changeset 622:8fba6d15a2f5

make request.(html_)formatter available early and use it
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 06 May 2006 00:09:06 +0200
parents d1e84cbab594
children 088282ae5cf3
files MoinMoin/Page.py MoinMoin/action/Despam.py MoinMoin/action/MyPages.py MoinMoin/request.py MoinMoin/stats/hitcounts.py MoinMoin/theme/__init__.py MoinMoin/wikiaction.py MoinMoin/wikirpc.py
diffstat 8 files changed, 20 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/Page.py	Sat May 06 00:09:06 2006 +0200
@@ -46,10 +46,10 @@
         #print >>sys.stderr, "page %s" % repr(page_name)
         #traceback.print_stack(limit=4, file=sys.stderr)
 
-
         formatter = kw.get('formatter', None)
         if isinstance(formatter, (str, unicode)): # mimetype given
             mimetype = str(formatter)
+            self.formatter = None
             self.output_mimetype = mimetype
             self.default_formatter = mimetype == "text/html"
         elif formatter is not None: # formatter instance given
@@ -57,6 +57,7 @@
             self.default_formatter = 0
             self.output_mimetype = "text/todo" # TODO where do we get this value from?
         else:
+            self.formatter = None
             self.default_formatter = 1
             self.output_mimetype = "text/html"
 
@@ -1006,7 +1007,7 @@
             from MoinMoin.formatter.text_html import Formatter
             self.formatter = Formatter(request, store_pagelinks=1)
         elif not self.formatter:
-            formatterName = self.output_mimetype.translate({ord('/'): '_', ord('.'): '_'}) # XXX use existing fn for that
+            formatterName = self.output_mimetype.replace('/', '_').replace('.', '_') # XXX use existing fn for that
             try:
                 Formatter = wikiutil.importPlugin(request.cfg, "formatter", formatterName, "Formatter")
                 self.formatter = Formatter(request)
@@ -1014,13 +1015,12 @@
                 from MoinMoin.formatter.text_html import Formatter
                 self.formatter = Formatter(request, store_pagelinks=1)
                 self.output_mimetype = "text/html"
-            
-        request.http_headers(["Content-Type: %s; charset=%s" % (self.output_mimetype, self.output_charset)])
-
+        request.formatter = self.formatter
         self.formatter.setPage(self)
         if self.hilite_re:
             self.formatter.set_highlight_re(self.hilite_re)
-        request.formatter = self.formatter
+        
+        request.http_headers(["Content-Type: %s; charset=%s" % (self.output_mimetype, self.output_charset)])
 
         # default is wiki markup
         pi_format = self.cfg.default_markup or "wiki"
@@ -1289,7 +1289,7 @@
         @rtype: string
         @return: formatter name as used in caching
         """
-        if not hasattr(self, 'formatter'):
+        if not hasattr(self, 'formatter') or self.formatter is None:
             return ''
         module = self.formatter.__module__
         return module[module.rfind('.') + 1:]
--- a/MoinMoin/action/Despam.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/action/Despam.py	Sat May 06 00:09:06 2006 +0200
@@ -15,7 +15,6 @@
 from MoinMoin.widget.browser import DataBrowserWidget
 from MoinMoin import wikiutil, Page, PageEditor
 from MoinMoin.macro import RecentChanges
-from MoinMoin.formatter.text_html import Formatter
 
 def show_editors(request, pagename, timestamp):
     _ =  request.getText
@@ -65,7 +64,7 @@
     #  mimic macro object for use of RecentChanges subfunctions
     macro = tmp()
     macro.request = request
-    macro.formatter = Formatter(request)
+    macro.formatter = request.html_formatter
 
     request.write("<table>")
     for line in log.reverse():
--- a/MoinMoin/action/MyPages.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/action/MyPages.py	Sat May 06 00:09:06 2006 +0200
@@ -19,8 +19,7 @@
         username = ''
 
     if not username:
-        return thispage.send_page(request,
-            msg = _('Please log in first.'))
+        return thispage.send_page(request, msg=_('Please log in first.'))
 
     userhomewiki = request.cfg.user_homewiki
     if userhomewiki != 'Self' and userhomewiki != request.cfg.interwikiname:
@@ -59,33 +58,21 @@
 
     from MoinMoin.Page import Page
     from MoinMoin.parser.wiki import Parser
-    from MoinMoin.formatter.text_html import Formatter
-    pagename = username
     request.http_headers()
     
     # This action generate data using the user language
     request.setContentLanguage(request.lang)
-    request.theme.send_title(_('MyPages management'), pagename=pagename)
+    request.theme.send_title(_('MyPages management'), page=homepage)
         
-    # Start content - IMPORTANT - without content div, there is no
-    # direction support!
+    # Start content - IMPORTANT - without content div, there is no direction support!
     request.write(request.formatter.startContent("content"))
 
     parser = Parser(pagecontent, request)
-    formatter = Formatter(request)
-    reqformatter = None
-    if hasattr(request, 'formatter'):
-        reqformatter = request.formatter
-    request.formatter = formatter
     p = Page(request, "$$$")
-    formatter.setPage(p)
-    parser.format(formatter)
-    if reqformatter == None:
-        del request.formatter
-    else:
-        request.formatter = reqformatter
-
+    request.formatter.setPage(p)
+    parser.format(request.formatter)
+    
     request.write(request.formatter.endContent())
-    request.theme.send_footer(pagename)
+    request.theme.send_footer(homepage.page_name)
     request.theme.send_closing_html()
 
--- a/MoinMoin/request.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/request.py	Sat May 06 00:09:06 2006 +0200
@@ -1021,6 +1021,9 @@
         self.clock.start('run')
 
         from MoinMoin.Page import Page
+        from MoinMoin.formatter.text_html import Formatter
+        self.html_formatter = Formatter(self)
+        self.formatter = self.html_formatter
 
         if self.query_string == 'action=xmlrpc':
             from MoinMoin.wikirpc import xmlrpc
--- a/MoinMoin/stats/hitcounts.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/stats/hitcounts.py	Sat May 06 00:09:06 2006 +0200
@@ -16,7 +16,6 @@
 
 from MoinMoin import caching, config, wikiutil
 from MoinMoin.Page import Page
-from MoinMoin.formatter.text_html import Formatter
 from MoinMoin.logfile import eventlog, logfile
 
 
@@ -24,7 +23,6 @@
     _ = request.getText
 
     if not request.cfg.chart_options:
-        request.formatter = Formatter(request)
         return text(pagename, request, params)
 
     if _debug:
--- a/MoinMoin/theme/__init__.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/theme/__init__.py	Sat May 06 00:09:06 2006 +0200
@@ -1010,7 +1010,7 @@
         @rtype: unicode
         @return: iconbar html
         """
-        page = d['page']       
+        page = d['page']
         if not self.shouldShowEditbar(page):
             return ''
 
--- a/MoinMoin/wikiaction.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/wikiaction.py	Sat May 06 00:09:06 2006 +0200
@@ -809,9 +809,6 @@
     if action in request.cfg.actions_excluded:
         return None
 
-    from MoinMoin.formatter.text_html import Formatter
-    request.formatter = Formatter(request)
-
     try:
         handler = wikiutil.importPlugin(request.cfg, "action", action, identifier)
     except wikiutil.PluginMissingError:
--- a/MoinMoin/wikirpc.py	Fri May 05 20:56:30 2006 +0200
+++ b/MoinMoin/wikirpc.py	Sat May 06 00:09:06 2006 +0200
@@ -30,7 +30,6 @@
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.logfile import editlog
-from MoinMoin.formatter import text_html
 
 _debug = 0
 
@@ -389,7 +388,7 @@
         from MoinMoin import search
         query = search.QueryParser().parse_query(query_string)
         results = search.searchPages(self.request, query)
-        results.formatter = text_html.Formatter(self.request)
+        results.formatter = self.request.html_formatter
         results.request = self.request
         return [(self._outstr(hit.page_name),
                  self._outstr(results.formatContext(hit, 180, 1)))