changeset 1341:f4558797325a

new page.link_to_raw function, use more page.link_to(_raw) instead of lowlevel wikiutil.link_tag, use more query dicts instead of strs
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Aug 2006 15:51:08 +0200
parents 6786dc227674
children baafe28d8037 b65614f8a393
files MoinMoin/Page.py MoinMoin/action/Despam.py MoinMoin/action/LocalSiteMap.py MoinMoin/action/diff.py MoinMoin/macro/Action.py MoinMoin/macro/EditTemplates.py MoinMoin/macro/Navigation.py MoinMoin/macro/RecentChanges.py MoinMoin/theme/__init__.py
diffstat 9 files changed, 78 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/Page.py	Sun Aug 20 15:51:08 2006 +0200
@@ -890,6 +890,14 @@
             url = '%s/%s' % (request.getScriptname(), url)
         return url
 
+    def link_to_raw(self, request, text, querystr=None, anchor=None, **kw):
+        """ core functionality of link_to, without the magic """
+        url = self.url(request, querystr, escape=0, anchor=anchor)
+        # escaping is done by link_tag -> formatter.url -> ._open()
+        link = wikiutil.link_tag(request, url, text,
+                                 formatter=getattr(self, 'formatter', None), **kw)
+        return link
+
     def link_to(self, request, text=None, querystr=None, anchor=None, **kw):
         """ Return HTML markup that links to this page.
 
@@ -907,16 +915,14 @@
         """
         if not text:
             text = self.split_title(request)
-
-        url = self.url(request, querystr, escape=0, anchor=anchor)
-        # escaping is done by link_tag -> formatter.url -> ._open()
+        text = wikiutil.escape(text)
 
         # Add css class for non existing page
         if not self.exists():
             kw['css_class'] = 'nonexistent'
 
-        link = wikiutil.link_tag(request, url, wikiutil.escape(text),
-                                 formatter=getattr(self, 'formatter', None), **kw)
+        link = self.link_to_raw(request, text, querystr, anchor, **kw)
+
         # Create a link to attachments if any exist
         if kw.get('attachment_indicator', 0):
             from MoinMoin.action import AttachFile
--- a/MoinMoin/action/Despam.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/action/Despam.py	Sun Aug 20 15:51:08 2006 +0200
@@ -45,7 +45,12 @@
                        Column('pages', label=_("Pages"), align='right'),
                        Column('link', label='', align='left')]
     for nr, editor in editors:
-        dataset.addRow((editor, unicode(nr), pg.link_to(request, text=_("Select Author"), querystr="action=Despam&editor=%s" % wikiutil.url_quote_plus(editor))))
+        dataset.addRow((editor, unicode(nr),
+            pg.link_to(request, text=_("Select Author"),
+                querystr={
+                    'action': 'Despam',
+                    'editor': editor, # was: url_quote_plus()
+                })))
 
     table = DataBrowserWidget(request)
     table.setData(dataset)
--- a/MoinMoin/action/LocalSiteMap.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/action/LocalSiteMap.py	Sun Aug 20 15:51:08 2006 +0200
@@ -64,12 +64,14 @@
     def visit(self, request, name, depth):
         """ Visit a page, i.e. create a link.
         """
-        if not name: return
-        self.append('&nbsp;' * (5*depth))
-        self.append('&nbsp;' + wikiutil.link_tag(request, '%s?action=%s' %
-            (wikiutil.quoteWikinameURL(name), __name__.split('.')[-1]), name))
+        if not name:
+            return
+        pg = Page(request, name)
+        action = __name__.split('.')[-1]
+        self.append('&nbsp;' * (5*depth+1))
+        self.append(pg.link_to(request, name, querystr={'action': action}))
         self.append("&nbsp;<small>[")
-        self.append(Page(request, name).link_to(request, 'view'))
+        self.append(pg.link_to(request, 'view'))
         self.append("</small>]<br>")
 
     def append(self, text):
--- a/MoinMoin/action/diff.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/action/diff.py	Sun Aug 20 15:51:08 2006 +0200
@@ -143,9 +143,11 @@
             if ignorews:
                 request.write(_('(ignoring whitespace)') + '<br>')
             else:
-                qstr = 'action=diff&ignorews=1'
-                if rev1: qstr = '%s&rev1=%s' % (qstr, rev1)
-                if rev2: qstr = '%s&rev2=%s' % (qstr, rev2)
+                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,
                     text=_('Ignore changes in the amount of whitespace'),
                     querystr=qstr, rel='nofollow') + '<p>')
--- a/MoinMoin/macro/Action.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/macro/Action.py	Sun Aug 20 15:51:08 2006 +0200
@@ -66,11 +66,8 @@
         text = wikiutil.escape(text, 1)
 
         # Create link
-        formatter = self.macro.formatter
-        page = wikiutil.quoteWikinameURL(formatter.page.page_name)
-        url = '%s?action=%s' % (page, action)
-        link = wikiutil.link_tag(self.request, url, text=text,
-                                 formatter=formatter)
+        page = self.macro.formatter.page
+        link = page.link_to(self.request, text, querystr='action=%s' % action)
         return link
 
 
--- a/MoinMoin/macro/EditTemplates.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/macro/EditTemplates.py	Sun Aug 20 15:51:08 2006 +0200
@@ -15,23 +15,16 @@
     # Get list of template pages readable by current user
     filter = re.compile(self.request.cfg.page_template_regex, re.UNICODE).search
     templates = self.request.rootpage.getPageList(filter=filter)
-
+    result = []
     if templates:
         templates.sort()
-
+        page = self.formatter.page
         # send list of template pages
-        result = self.formatter.bullet_list(1)
-        for page in templates:
-            result = result +\
-                     self.formatter.listitem(1) +\
-                     wikiutil.link_tag(self.request, "%s?action=edit&amp;template=%s" % (
-                        wikiutil.quoteWikinameURL(self.formatter.page.page_name),
-                        wikiutil.quoteWikinameURL(page)), page
-                     ) + \
-                     self.formatter.listitem(0)
+        result.append(self.formatter.bullet_list(1))
+        for template in templates:
+            result.append(self.formatter.listitem(1))
+            result.append(page.link_to(self.request, template, querystr={'action': 'edit', 'template': template}))
+            result.append(self.formatter.listitem(0))
+        result.append(self.formatter.bullet_list(0))
+    return ''.join(result)
 
-        result = result + self.formatter.bullet_list(0)
-        return result
-
-    return ''
-
--- a/MoinMoin/macro/Navigation.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/macro/Navigation.py	Sun Aug 20 15:51:08 2006 +0200
@@ -64,7 +64,7 @@
     """
 
     # querystring for slideshow links
-    PROJECTION = 'action=print&media=projection'
+    PROJECTION = {'action': 'print', 'media': 'projection', }
 
     def __init__(self, macro, args):
         """ Prepare common values used during processing.
@@ -76,7 +76,7 @@
         self.pagename = self.macro.formatter.page.page_name
         self.print_mode = self.macro.request.action == 'print'
         self.media = self.macro.request.form.get('media', [None])[0]
-        self.querystr = self.print_mode and self.PROJECTION or ''
+        self.querystr = self.print_mode and self.PROJECTION or {}
 
 
     def dispatch(self):
@@ -113,6 +113,7 @@
         """ Navigate from a subpage to its siblings.
         """
         _ = self._
+        request = self.macro.request
         # get parent page name
         parent = root or _getParent(self.pagename)
         if not parent:
@@ -127,7 +128,7 @@
 
         # iterate over children, adding links to all of them
         result = []
-        children = _getPages(self.macro.request, '^%s/' % parent)
+        children = _getPages(request, '^%s/' % parent)
         for child in children:
             # display short page name, leaving out the parent path
             # (and make sure the name doesn't get wrapped)
@@ -142,7 +143,7 @@
                 result.append(self.macro.formatter.text(shortname))
             else:
                 # link to sibling / child
-                result.append(Page(self.macro.request, child).link_to(self.macro.request, text=shortname, querystr=self.querystr))
+                result.append(Page(request, child).link_to(request, text=shortname, querystr=self.querystr))
             result.append(' &nbsp; ')
 
         return ''.join(result)
@@ -157,12 +158,13 @@
         _ = self._
         curpage = focus or self.pagename
         result = []
-
+        request = self.macro.request
+        pg = Page(request, curpage)
         if self.print_mode:
             # projection mode
             label = _('Wiki')
-            toggle = ''
-            result.append(Page(self.macro.request, curpage).link_to(self.macro.request, text=_('Edit'), querystr='action=edit'))
+            toggle = {}
+            result.append(pg.link_to(request, text=_('Edit'), querystr={'action': 'edit'}))
             result.append(' &nbsp; ')
         else:
             # wiki mode
@@ -170,15 +172,15 @@
             toggle = self.PROJECTION
 
         # add mode toggle link
-        result.append(Page(self.macro.request, curpage).link_to(self.macro.request, text=label, querystr=toggle))
+        result.append(pg.link_to(request, text=label, querystr=toggle))
 
         # leave out the following on slide pages
         if focus is None:
-            children = _getPages(self.macro.request, '^%s/' % self.pagename)
+            children = _getPages(request, '^%s/' % self.pagename)
             if children:
                 # add link to first child if one exists
                 result.append(' &nbsp; ')
-                result.append(Page(self.macro.request, children[0]).link_to(self.macro.request, text=_('Start'), querystr=self.querystr))
+                result.append(Page(request, children[0]).link_to(request, text=_('Start'), querystr=self.querystr))
 
         return ''.join(result)
 
@@ -187,6 +189,7 @@
         """ Navigate within a slide show.
         """
         _ = self._
+        request = self.macro.request
         parent = root or _getParent(self.pagename)
         if not parent:
             return (self.macro.formatter.sysmsg(1) +
@@ -197,7 +200,7 @@
         result = []
         labels = ['^', '|<', '<<', '>>', '>|']
         filter_regex = '^%s/' % re.escape(parent)
-        pos, size, links = _getLinks(self.macro.request, self.pagename, filter_regex)
+        pos, size, links = _getLinks(request, self.pagename, filter_regex)
         pos += 1
         links = zip(labels, (parent,) + links)
 
@@ -206,7 +209,7 @@
             result.append(' ')
             if name:
                 # active link
-                result.append(Page(self.macro.request, name).link_to(self.macro.request, text=label, querystr=self.querystr))
+                result.append(Page(request, name).link_to(request, text=label, querystr=self.querystr))
             else:
                 # ghosted link
                 result.append(self.macro.formatter.text(label))
--- a/MoinMoin/macro/RecentChanges.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/macro/RecentChanges.py	Sun Aug 20 15:51:08 2006 +0200
@@ -54,36 +54,29 @@
     is_new = lines[-1].action == 'SAVENEW'
     # check whether this page is newer than the user's bookmark
     hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
-    page = Page(request, line.pagename)
+    page = Page(request, pagename)
 
     html_link = ''
     if not page.exists():
         # indicate page was deleted
-        html_link = request.theme.make_icon('deleted')
+        html_link = request.theme.make_icon('deleted') # TODO: we could link to the last existing rev here
     elif page.isConflict():
         img = macro.formatter.smiley("/!\\")
         #img = request.theme.make_icon('help')
-        html_link = wikiutil.link_tag(request,
-                                      wikiutil.quoteWikinameURL(pagename) + "?action=edit",
-                                      img, formatter=macro.formatter, rel="nofollow")
+        html_link = page.link_to_raw(request, img, querystr={'action': 'edit'}, rel='nofollow')
     elif is_new:
         # show "NEW" icon if page was created after the user's bookmark
         if hilite:
             img = request.theme.make_icon('new')
-            html_link = wikiutil.link_tag(request, wikiutil.quoteWikinameURL(pagename),
-                                          img, formatter=macro.formatter, rel="nofollow")
+            html_link = page.link_to_raw(request, img, rel='nofollow')
     elif hilite:
         # show "UPDATED" icon if page was edited after the user's bookmark
         img = request.theme.make_icon('updated')
-        html_link = wikiutil.link_tag(request,
-                                      wikiutil.quoteWikinameURL(pagename) + "?action=diff&date=%d" % bookmark_usecs,
-                                      img, formatter=macro.formatter, rel="nofollow")
+        html_link = page.link_to_raw(request, img, querystr={'action': 'diff', 'date': '%d' % bookmark_usecs}, rel='nofollow')
     else:
         # show "DIFF" icon else
         img = request.theme.make_icon('diffrc')
-        html_link = wikiutil.link_tag(request,
-                                      wikiutil.quoteWikinameURL(line.pagename) + "?action=diff",
-                                      img, formatter=macro.formatter, rel="nofollow")
+        html_link = page.link_to_raw(request, img, querystr={'action': 'diff'}, rel='nofollow')
 
     # print name of page, with a link to it
     force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
@@ -131,10 +124,7 @@
     d['comments'] = comments
 
     img = request.theme.make_icon('info')
-    info_html = wikiutil.link_tag(request,
-                                  wikiutil.quoteWikinameURL(line.pagename) + "?action=info",
-                                  img, formatter=macro.formatter, rel="nofollow")
-    d['info_html'] = info_html
+    d['info_html'] = page.link_to_raw(request, img, querystr={'action': 'info'}, rel='nofollow')
 
     return request.theme.recentchanges_entry(d)
 
@@ -256,17 +246,11 @@
             currentBookmark = wikiutil.version2timestamp(bookmark_usecs)
             currentBookmark = user.getFormattedDateTime(currentBookmark)
             currentBookmark = _('(currently set to %s)') % currentBookmark
-
-            url = wikiutil.quoteWikinameURL(pagename) + "?action=bookmark&time=del"
-            deleteBookmark = wikiutil.link_tag(request, url, _("Delete Bookmark"),
-                                               formatter=macro.formatter, rel="nofollow")
+            deleteBookmark = page.link_to(request, _("Delete bookmark"), querystr={'action': 'bookmark', 'time': 'del'}, rel='nofollow')
             d['rc_curr_bookmark'] = currentBookmark + ' ' + deleteBookmark
 
         version = wikiutil.timestamp2version(tnow)
-        url = wikiutil.quoteWikinameURL(pagename) + \
-            "?action=bookmark&time=%d" % version
-        d['rc_update_bookmark'] = wikiutil.link_tag(request, url, _("Set bookmark"),
-                                                    formatter=macro.formatter, rel="nofollow")
+        d['rc_update_bookmark'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % version}, rel='nofollow')
 
     # set max size in days
     max_days = min(int(request.form.get('max_days', [0])[0]), _DAYS_SELECTION[-1])
@@ -302,26 +286,22 @@
         if ((this_day != day or (not hilite and not max_days))) and len(pages) > 0:
             # new day or bookmark reached: print out stuff 
             this_day = day
-            for page in pages:
-                ignore_pages[page] = None
+            for p in pages:
+                ignore_pages[p] = None
             pages = pages.values()
             pages.sort(cmp_lines)
             pages.reverse()
 
             if request.user.valid:
-                d['bookmark_link_html'] = wikiutil.link_tag(
-                    request,
-                    wikiutil.quoteWikinameURL(
-                        macro.formatter.page.page_name) + "?action=bookmark&time=%d" % (pages[0][0].ed_time_usecs,),
-                        _("set bookmark"),
-                        formatter=macro.formatter, rel="nofollow")
+                bmtime = pages[0][0].ed_time_usecs
+                d['bookmark_link_html'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % bmtime}, rel='nofollow')
             else:
                 d['bookmark_link_html'] = None
             d['date'] = request.user.getFormattedDate(wikiutil.version2timestamp(pages[0][0].ed_time_usecs))
             request.write(request.theme.recentchanges_daybreak(d))
 
-            for page in pages:
-                request.write(format_page_edits(macro, page, bookmark_usecs))
+            for p in pages:
+                request.write(format_page_edits(macro, p, bookmark_usecs))
             pages = {}
             day_count += 1
             if max_days and (day_count >= max_days):
@@ -348,26 +328,22 @@
             # end of loop reached: print out stuff 
             # XXX duplicated code from above
             # but above does not trigger if we have the first day in wiki history
-            for page in pages:
-                ignore_pages[page] = None
+            for p in pages:
+                ignore_pages[p] = None
             pages = pages.values()
             pages.sort(cmp_lines)
             pages.reverse()
 
             if request.user.valid:
-                d['bookmark_link_html'] = wikiutil.link_tag(
-                    request,
-                    wikiutil.quoteWikinameURL(
-                        macro.formatter.page.page_name) + "?action=bookmark&time=%d" % (pages[0][0].ed_time_usecs,),
-                        _("Set bookmark"),
-                        formatter=macro.formatter, rel="nofollow")
+                bmtime = pages[0][0].ed_time_usecs
+                d['bookmark_link_html'] = page.link_to(request, _("Set bookmark"), querystr={'action': 'bookmark', 'time': '%d' % bmtime}, rel='nofollow')
             else:
                 d['bookmark_link_html'] = None
             d['date'] = request.user.getFormattedDate(wikiutil.version2timestamp(pages[0][0].ed_time_usecs))
             request.write(request.theme.recentchanges_daybreak(d))
 
-            for page in pages:
-                request.write(format_page_edits(macro, page, bookmark_usecs))
+            for p in pages:
+                request.write(format_page_edits(macro, p, bookmark_usecs))
 
 
     d['rc_msg'] = msg
--- a/MoinMoin/theme/__init__.py	Sun Aug 20 13:51:01 2006 +0200
+++ b/MoinMoin/theme/__init__.py	Sun Aug 20 15:51:08 2006 +0200
@@ -1158,10 +1158,10 @@
         _ = self.request.getText
         return """\
 <script type="text/javascript">
-var gui_editor_link_href = "%(url)s?action=edit&editor=gui";
+var gui_editor_link_href = "%(url)s";
 var gui_editor_link_text = "%(text)s";
 </script>        
-""" % {'url': page.url(self.request),
+""" % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, escape=0),
        'text': _('Edit (GUI)', formatted=False),
       }