Index: trac/wiki/web_ui.py
===================================================================
--- trac/wiki/web_ui.py	(revision 4010)
+++ trac/wiki/web_ui.py	(working copy)
@@ -396,18 +396,15 @@
         if page.name == 'WikiStart':
             data['title'] = ''
 
-        page_html = comment_html = attach_href = ''
-        latest_page = WikiPage(self.env, page.name)
-
+        comment_html = attach_href = ''
         if page.exists:
-            page_html = wiki_to_html(page.text, self.env, req, db)
+            latest_page = WikiPage(self.env, page.name)
             if version:
                 comment_html = wiki_to_oneliner(page.comment or '--',
                                                 self.env, db)
         else:
             if not req.perm.has_permission('WIKI_CREATE'):
                 raise HTTPNotFound('Page %s not found', page.name)
-            page_html = html.P('Describe "%s" here' % data['page_name'])
 
         # Show attachments
         attachments = attachments_data(self.env, req, db, 'wiki', page.name)
@@ -419,7 +416,6 @@
                      WikiSystem(self.env).get_pages(prefix)]
 
         data.update({'action': 'view',
-                     'page_html': page_html,
                      'comment_html': comment_html,
                      'latest_version': latest_page.version,
                      'attachments': attachments,
Index: trac/web/chrome.py
===================================================================
--- trac/web/chrome.py	(revision 4012)
+++ trac/web/chrome.py	(working copy)
@@ -36,7 +36,7 @@
                               format_time, http_date
 from trac.web.api import IRequestHandler, HTTPNotFound
 from trac.web.href import Href
-from trac.wiki import IWikiSyntaxProvider
+from trac.wiki import wiki_to_html, wiki_to_oneliner, IWikiSyntaxProvider
 
 def add_link(req, rel, href, title=None, mimetype=None, classname=None):
     """Add a link to the HDF data set that will be inserted as <link> element in
@@ -427,6 +427,10 @@
         data['format_time'] = partial(format_time, tzinfo=tzinfo)
         data['fromtimestamp'] = partial(datetime.fromtimestamp, tz=tzinfo)
 
+        # Wiki-formatting functions
+        data['wiki_to_html'] = partial(wiki_to_html, env=self.env, req=req)
+        data['wiki_to_oneliner'] = partial(wiki_to_html, env=self.env, req=req)
+
     def load_template(self, filename, method=None):
         """Retrieve a Template and optionally preset the template data.
 
@@ -468,4 +472,10 @@
             return stream.render('text')
         else:
             doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)
+            req.environ['trac.chrome.links'] = {}
+            req.environ['trac.chrome.scripts'] = []
+            data['chrome'].update({
+                'post_links': req.environ['trac.chrome.links'],
+                'post_scripts': req.environ['trac.chrome.scripts'],
+            })
             return stream.render(method, doctype=doctype)
Index: templates/layout.html
===================================================================
--- templates/layout.html	(revision 4010)
+++ templates/layout.html	(working copy)
@@ -50,6 +50,14 @@
     <div id="main">
       ${select('*|text()')}
 
+      <script type="text/javascript" py:if="chrome.post_links">
+        <py:for each="link in chrome.post_links.get('stylesheet')">
+          $.loadStyleSheet("${link.href}", "${link.title}");
+        </py:for>
+      </script>
+      <script py:for="script in chrome.post_scripts"
+              type="${script.type}" src="${script.href}"></script>
+
       <div id="altlinks" py:if="chrome.links.alternate">
         <h3>Download in other formats:</h3>
         <ul>
Index: templates/wiki_view.html
===================================================================
--- templates/wiki_view.html	(revision 4010)
+++ templates/wiki_view.html	(working copy)
@@ -40,8 +40,13 @@
         </table>
       </py:if>
 
-      <div class="wikipage searchable">
-        $page_html
+      <div class="wikipage searchable" py:choose="">
+        <py:when test="page.exists">
+          ${wiki_to_html(page.text)}
+        </py:when>
+        <py:otherwise>
+          Describe ${page.name} here.
+        </py:otherwise>
       </div>
 
       ${list_of_attachments(attachments, attach_href, compact=True)}
