changeset 1384:d1ceb31f3d02

make more use of formatter
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 21 Aug 2006 09:59:57 +0200
parents fdb726f0f34f
children 09aa290e4a88 95f907618c53
files MoinMoin/action/__init__.py MoinMoin/action/diff.py MoinMoin/macro/OrphanedPages.py MoinMoin/macro/SystemAdmin.py
diffstat 4 files changed, 53 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/__init__.py	Mon Aug 21 02:07:13 2006 +0200
+++ b/MoinMoin/action/__init__.py	Mon Aug 21 09:59:57 2006 +0200
@@ -91,8 +91,9 @@
             for convenience we give him some pre-assembled html for the buttons.
         """
         _ = self._
+        f = self.request.formatter
         prompt = _("Execute action %(actionname)s?") % {'actionname': self.actionname}
-        return "<p>%s</p>%s" % (prompt, buttons_html)
+        return f.paragraph(1) + f.text(prompt) + f.paragraph(0) + f.rawHTML(buttons_html)
 
     def make_buttons(self):
         """ return a list of form buttons for the action form """
--- a/MoinMoin/action/diff.py	Mon Aug 21 02:07:13 2006 +0200
+++ b/MoinMoin/action/diff.py	Mon Aug 21 09:59:57 2006 +0200
@@ -117,49 +117,48 @@
             oldrev2 = 0 # XXX
 
     edit_count = abs(oldcount1 - oldcount2)
-
-    # this should use the formatter, but there is none?
-    request.write('<div id="content">\n') # start content div
-    request.write('<p class="diff-header">')
-    request.write(_('Differences between revisions %d and %d') % (oldpage.get_real_rev(), newpage.get_real_rev()))
+    f = request.formatter
+    request.write(f.div(1, id="content"))
+    request.write(f.paragraph(1, css_class="diff-header"))
+    request.write(f.text(_('Differences between revisions %d and %d') % (oldpage.get_real_rev(), newpage.get_real_rev())))
     if edit_count > 1:
-        request.write(' ' + _('(spanning %d versions)') % (edit_count,))
-    request.write('</p>')
+        request.write(f.text(' ' + _('(spanning %d versions)') % (edit_count,)))
+    request.write(f.paragraph(0))
 
     if request.user.show_fancy_diff:
         from MoinMoin.util import diff_html
-        request.write(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body()))
+        request.write(f.rawHTML(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body())))
         newpage.send_page(request, count_hit=0, content_only=1, content_id="content-below-diff")
     else:
         from MoinMoin.util import diff_text
         lines = diff_text.diff(oldpage.getlines(), newpage.getlines())
         if not lines:
-            msg = _("No differences found!")
+            msg = f.text(_("No differences found!"))
             if edit_count > 1:
-                msg = msg + '<p>' + _('The page was saved %(count)d times, though!') % {
-                    'count': edit_count}
+                msg = msg + f.paragraph(1) + f.text(_('The page was saved %(count)d times, though!') % {
+                    'count': edit_count}) + f.paragraph(0)
             request.write(msg)
         else:
             if ignorews:
-                request.write(_('(ignoring whitespace)') + '<br>')
+                request.write(f.text(_('(ignoring whitespace)')), f.linebreak())
             else:
                 qstr = {'action': 'diff', 'ignorews': '1', }
                 if rev1:
                     qstr['rev1'] = str(rev1)
                 if rev2:
                     qstr['rev2'] = str(rev2)
-                request.write(Page(request, pagename).link_to(request,
+                request.write(f.paragraph(1), Page(request, pagename).link_to(request,
                     text=_('Ignore changes in the amount of whitespace'),
-                    querystr=qstr, rel='nofollow') + '<p>')
+                    querystr=qstr, rel='nofollow'), f.paragraph(0))
 
-            request.write('<pre>')
+            request.write(f.preformatted(1))
             for line in lines:
                 if line[0] == "@":
-                    request.write('<hr>')
-                request.write(wikiutil.escape(line)+'\n')
-            request.write('</pre>')
+                    request.write(f.rule(1))
+                request.write(f.text(wikiutil.escape(line)+'\n'))
+            request.write(f.preformatted(0))
 
-    request.write('</div>\n') # end content div
+    request.write(f.div(0)) # end content div
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
 
--- a/MoinMoin/macro/OrphanedPages.py	Mon Aug 21 02:07:13 2006 +0200
+++ b/MoinMoin/macro/OrphanedPages.py	Mon Aug 21 09:59:57 2006 +0200
@@ -24,23 +24,26 @@
             if link in orphaned:
                 del orphaned[link]
 
-    # check for the extreme case
-    if not orphaned:
-        return "<p>%s</p>" % _("No orphaned pages in this wiki.")
-
-    # return a list of page links
-    orphanednames = orphaned.keys()
-    orphanednames.sort()
     result = []
-    result.append(macro.formatter.number_list(1))
-    for name in orphanednames:
-        if not name: continue
-        result.append(macro.formatter.listitem(1))
-        result.append(macro.formatter.pagelink(1, name, generated=1))
-        result.append(macro.formatter.text(name))
-        result.append(macro.formatter.pagelink(0, name))
-        result.append(macro.formatter.listitem(0))
-    result.append(macro.formatter.number_list(0))
+    f = macro.formatter
+    if not orphaned:
+        result.append(f.paragraph(1))
+        result.append(f.text(_("No orphaned pages in this wiki.")))
+        result.append(f.paragraph(0))
+    else:
+        # return a list of page links
+        orphanednames = orphaned.keys()
+        orphanednames.sort()
+        result.append(f.number_list(1))
+        for name in orphanednames:
+            if not name:
+                continue
+            result.append(f.listitem(1))
+            result.append(f.pagelink(1, name, generated=1))
+            result.append(f.text(name))
+            result.append(f.pagelink(0, name))
+            result.append(f.listitem(0))
+        result.append(f.number_list(0))
 
     return ''.join(result)
 
--- a/MoinMoin/macro/SystemAdmin.py	Mon Aug 21 02:07:13 2006 +0200
+++ b/MoinMoin/macro/SystemAdmin.py	Mon Aug 21 09:59:57 2006 +0200
@@ -23,7 +23,6 @@
     if not request.user.isSuperUser():
         return ''
 
-    result = []
     _MENU = {
         'attachments': (("File attachment browser"), do_admin_browser),
         'users': (("User account browser"), do_user_browser),
@@ -31,21 +30,24 @@
     choice = request.form.get('sysadm', [None])[0]
 
     # create menu
-    menuitems = [(label, id) for id, (label, handler) in _MENU.items()]
+    menuitems = [(label, fnid) for fnid, (label, handler) in _MENU.items()]
     menuitems.sort()
-    for label, id in menuitems:
-        if id == choice:
-            result.append(macro.formatter.strong(1))
-            result.append(macro.formatter.text(label))
-            result.append(macro.formatter.strong(0))
+    result = []
+    f = macro.formatter
+    for label, fnid in menuitems:
+        if fnid == choice:
+            result.append(f.strong(1))
+            result.append(f.text(label))
+            result.append(f.strong(0))
         else:
-            result.append(wikiutil.link_tag(request, "%s?sysadm=%s" % (macro.formatter.page.page_name, id), label))
-        result.append('<br>')
-    result.append('<br>')
+            #result.append(wikiutil.link_tag(request, "%s?sysadm=%s" % (macro.formatter.page.page_name, id), label))
+            result.append(f.page.link_to(request, label, querystr={'sysadm': fnid}))
+        result.append(f.linebreak())
+    result.append(f.linebreak())
 
     # add chosen content
     if _MENU.has_key(choice):
-        result.append(_MENU[choice][1](request))
+        result.append(f.rawHTML(_MENU[choice][1](request)))
 
-    return macro.formatter.rawHTML(''.join(result))
+    return ''.join(result)