changeset 1816:4a31739bc6e1

Page.url(): removed escaping support
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 25 Feb 2007 03:08:18 +0100
parents 4dbc0547b7e0
children fd22bf359a65 df984fe11783
files MoinMoin/Page.py MoinMoin/PageEditor.py MoinMoin/action/AttachFile.py MoinMoin/action/Load.py MoinMoin/action/RenamePage.py MoinMoin/action/RenderAsDocbook.py MoinMoin/action/SubscribeUser.py MoinMoin/action/__init__.py MoinMoin/action/fullsearch.py MoinMoin/action/newpage.py MoinMoin/action/rss_rc.py MoinMoin/action/supplementation.py MoinMoin/formatter/text_gedit.py MoinMoin/formatter/text_html.py MoinMoin/macro/MonthCalendar.py MoinMoin/parser/text_rst.py MoinMoin/request/__init__.py MoinMoin/stats/hitcounts.py MoinMoin/stats/pagesize.py MoinMoin/stats/useragents.py MoinMoin/theme/__init__.py docs/CHANGES
diffstat 22 files changed, 47 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/Page.py	Sun Feb 25 03:08:18 2007 +0100
@@ -693,18 +693,19 @@
         self._raw_body = body
         self._raw_body_modified = modified
 
-    def url(self, request, querystr=None, escape=1, anchor=None, relative=True):
-        """ Return complete URL for this page, including scriptname
+    def url(self, request, querystr=None, anchor=None, relative=True, **kw):
+        """ Return complete URL for this page, including scriptname.
+            The URL is NOT escaped, if you write it to HTML, use wikiutil.escape
+            (at least if you have a querystr, to escape the & chars).
 
         @param request: the request object
         @param querystr: the query string to add after a "?" after the url
             (str or dict, see wikiutil.makeQueryString)
-        @param escape: escape url for html, to be backward compatible
-            with old code (bool)
         @param anchor: if specified, make a link to this anchor
         @rtype: str
         @return: complete url of this page, including scriptname
         """
+        assert(isinstance(anchor, (type(None), str, unicode)))
         # Create url, excluding scriptname
         url = wikiutil.quoteWikinameURL(self.page_name)
         if querystr:
@@ -715,16 +716,6 @@
 
             querystr = wikiutil.makeQueryString(querystr)
 
-            # TODO: remove in 2.0
-            # Escape query string to be compatible with old 3rd party code
-            # New code should call with escape=0 to prevent the warning.
-            if escape:
-                import warnings
-                warnings.warn("In moin 2.0 query string in url will not be escaped. "
-                              "See http://moinmoin.wikiwikiweb.de/ApiChanges. "
-                              "%s" % querystr)
-                querystr = wikiutil.escape(querystr)
-
             # make action URLs denyable by robots.txt:
             if action is not None and request.cfg.url_prefix_action is not None:
                 url = "%s/%s/%s" % (request.cfg.url_prefix_action, action, url)
@@ -740,7 +731,7 @@
 
     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)
+        url = self.url(request, querystr, anchor=anchor)
         # escaping is done by link_tag -> formatter.url -> ._open()
         link = wikiutil.link_tag(request, url, text,
                                  formatter=getattr(self, 'formatter', None), **kw)
--- a/MoinMoin/PageEditor.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/PageEditor.py	Sun Feb 25 03:08:18 2007 +0100
@@ -603,11 +603,14 @@
         request = self.request
         _ = lambda s, formatted=True, r=request, l=email_lang: r.getText(s, formatted=formatted, lang=l)
 
-        pagelink = request.getQualifiedURL(self.url(request, relative=False))
         if len(revisions) >= 2:
-            pagelink += "?action=diff&rev2=%i&rev1=%i" % tuple(revisions[:2])
-
-
+            querystr = {'action': 'diff',
+                        'rev2': str(revisions[0]),
+                        'rev1': str(revisions[1])}
+        else:
+            querystr = {}
+        pagelink = request.getQualifiedURL(self.url(request, querystr, relative=False))
+ 
         mailBody = _("Dear Wiki user,\n\n"
             'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
             "The following page has been changed by %(editor)s:\n"
--- a/MoinMoin/action/AttachFile.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/AttachFile.py	Sun Feb 25 03:08:18 2007 +0100
@@ -159,8 +159,7 @@
     if os.path.isdir(attach_dir):
         files = os.listdir(attach_dir)
     page = Page(request, pagename)
-    # TODO: remove escape=0 in 2.0
-    link = page.url(request, {'action': 'AttachFile'}, escape=0)
+    link = page.url(request, {'action': 'AttachFile'})
     attach_info = _('There are <a href="%(link)s">%(count)s attachment(s)</a> stored for this page.', formatted=False) % {
         'count': len(files),
         'link': wikiutil.escape(link)
--- a/MoinMoin/action/Load.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/Load.py	Sun Feb 25 03:08:18 2007 +0100
@@ -101,7 +101,7 @@
 
     def do_action_finish(self, success):
         if success:
-            url = Page(self.request, self.pagename).url(self.request, escape=0, relative=False)
+            url = Page(self.request, self.pagename).url(self.request, relative=False)
             self.request.http_redirect(url)
             self.request.finish()
         else:
--- a/MoinMoin/action/RenamePage.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/RenamePage.py	Sun Feb 25 03:08:18 2007 +0100
@@ -53,7 +53,7 @@
 
     def do_action_finish(self, success):
         if success:
-            url = Page(self.request, self.newpagename).url(self.request, escape=0, relative=False)
+            url = Page(self.request, self.newpagename).url(self.request, relative=False)
             self.request.http_redirect(url)
             self.request.finish()
         else:
--- a/MoinMoin/action/RenderAsDocbook.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/RenderAsDocbook.py	Sun Feb 25 03:08:18 2007 +0100
@@ -8,6 +8,6 @@
 from MoinMoin.Page import Page
 
 def execute(pagename, request):
-    url = Page(request, pagename).url(request, {'action': 'show', 'mimetype': 'text/docbook'}, escape=0, relative=False)
+    url = Page(request, pagename).url(request, {'action': 'show', 'mimetype': 'text/docbook'}, relative=False)
     request.http_redirect(url)
 
--- a/MoinMoin/action/SubscribeUser.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/SubscribeUser.py	Sun Feb 25 03:08:18 2007 +0100
@@ -73,7 +73,7 @@
             else:
                 result.append(formatter.smiley('{X}'))
                 result.append(formatter.text(" "))
-            result.append(formatter.url(1, Page(request, userobj.name).url(request, escape=0)))
+            result.append(formatter.url(1, Page(request, userobj.name).url(request)))
             result.append(formatter.text(userobj.name))
             result.append(formatter.url(0))
             result.append(formatter.linebreak(preformatted=0))
--- a/MoinMoin/action/__init__.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/__init__.py	Sun Feb 25 03:08:18 2007 +0100
@@ -276,7 +276,7 @@
 def do_goto(pagename, request):
     """ redirect to another page """
     target = request.form.get('target', [''])[0]
-    request.http_redirect(Page(request, target).url(request, escape=0, relative=False))
+    request.http_redirect(Page(request, target).url(request, relative=False))
 
 def do_userform(pagename, request):
     """ save data posted from UserPreferences """
--- a/MoinMoin/action/fullsearch.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/fullsearch.py	Sun Feb 25 03:08:18 2007 +0100
@@ -194,7 +194,7 @@
         page = results.hits[0]
         if not page.attachment: # we did not find an attachment
             page = Page(request, page.page_name)
-            url = page.url(request, querystr={'highlight': query.highlight_re()}, escape=0, relative=False)
+            url = page.url(request, querystr={'highlight': query.highlight_re()}, relative=False)
             request.http_redirect(url)
             return
     elif not results.hits: # no hits?
--- a/MoinMoin/action/newpage.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/newpage.py	Sun Feb 25 03:08:18 2007 +0100
@@ -89,7 +89,7 @@
             if parent:
                 pagename = "%s/%s" % (parent, pagename)
 
-            url = Page(self.request, pagename).url(self.request, query, escape=0, relative=False)
+            url = Page(self.request, pagename).url(self.request, query, relative=False)
             self.request.http_redirect(url)
 
         return ''
--- a/MoinMoin/action/rss_rc.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/rss_rc.py	Sun Feb 25 03:08:18 2007 +0100
@@ -15,7 +15,9 @@
 from MoinMoin.wikixml.util import RssGenerator
 
 def full_url(request, page, querystr=None, anchor=None):
-    return request.getQualifiedURL(page.url(request, relative=False, anchor=anchor, querystr=querystr))
+    url = page.url(request, relative=False, anchor=anchor, querystr=querystr)
+    url = wikiutil.escape(url)
+    return request.getQualifiedURL(url)
 
 def execute(pagename, request):
     """ Send recent changes as an RSS document
--- a/MoinMoin/action/supplementation.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/action/supplementation.py	Sun Feb 25 03:08:18 2007 +0100
@@ -19,15 +19,15 @@
 
     if pagename.endswith(sub_page_name): # sub_sub_page redirects to sub_page
         query = {}
-        url = Page(request, pagename).url(request, query, escape=0, relative=False)
+        url = Page(request, pagename).url(request, query, relative=False)
         request.http_redirect(url)
     elif request.user.may.read(newpagename) and request.user.may.write(newpagename):
         query = {}
-        url = Page(request, newpagename).url(request, query, escape=0, relative=False)
+        url = Page(request, newpagename).url(request, query, relative=False)
         test = Page(request, newpagename)
         if test.exists(): # page is defined -> redirect
             request.http_redirect(url)
         else:  # page will be created from template
             query = {'action': 'edit', 'backto': newpagename, 'template': quoteWikinameURL(sub_page_template)}
-            url = Page(request, newpagename).url(request, query, escape=0, relative=False)
+            url = Page(request, newpagename).url(request, query, relative=False)
             request.http_redirect(url)
--- a/MoinMoin/formatter/text_gedit.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/formatter/text_gedit.py	Sun Feb 25 03:08:18 2007 +0100
@@ -54,7 +54,7 @@
         html_class = 'badinterwiki' # we use badinterwiki in any case to simplify reverse conversion
         href = wikiutil.quoteWikinameURL(pagename) or "/" # FCKeditor behaves strange on empty href
         title = kw.get('title', interwiki)
-        return self.url(1, href, title=title, do_escape=1, css=html_class) # interwiki links with pages with umlauts
+        return self.url(1, href, title=title, css=html_class) # interwiki links with pages with umlauts
 
     def attachment_inlined(self, url, text, **kw):
         if url == text:
--- a/MoinMoin/formatter/text_html.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/formatter/text_html.py	Sun Feb 25 03:08:18 2007 +0100
@@ -529,7 +529,7 @@
                 else:
                     html_class = 'interwiki'
                 title = kw.get('title', wikitag)
-                return self.url(1, href, title=title, do_escape=1, css=html_class) # interwiki links with umlauts
+                return self.url(1, href, title=title, css=html_class) # interwiki links with umlauts
             else:
                 return self.url(0)
 
@@ -540,7 +540,7 @@
         Call once with on=1 to start the link, and again with on=0
         to end it (no other arguments are needed when on==0).
 
-        do_escape: XXX doesn't work yet
+        do_escape: filters url through wikiutil.escape
 
         Keyword params:
             url - the URL to link to; will go through Wiki URL mapping.
@@ -564,9 +564,8 @@
                 del kw['href']
             if url is not None:
                 url = wikiutil.mapURL(self.request, url)
-                # TODO just calling url_quote does not work, as it will also quote "http:" to "http%xx" X)
-                if 0: # do_escape: # protocol and server part must not get quoted, path should get quoted
-                    url = wikiutil.url_quote(url)
+                if do_escape:
+                    url = wikiutil.escape(url)
                 attrs['href'] = url
 
             if css:
--- a/MoinMoin/macro/MonthCalendar.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/macro/MonthCalendar.py	Sun Feb 25 03:08:18 2007 +0100
@@ -312,10 +312,10 @@
     qpagenames = '*'.join(map(wikiutil.quoteWikinameURL, parmpagename))
     qtemplate = wikiutil.quoteWikinameURL(parmtemplate)
     querystr = "calparms=%%s,%d,%d,%d,%%d,%%s" % (parmyear, parmmonth, parmoffset)
-    prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate), escape=0)
-    nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate), escape=0)
-    prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate), escape=0)
-    nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate), escape=0)
+    prevlink = p.url(request, querystr % (qpagenames, parmoffset2 - 1, qtemplate))
+    nextlink = p.url(request, querystr % (qpagenames, parmoffset2 + 1, qtemplate))
+    prevylink = p.url(request, querystr % (qpagenames, parmoffset2 - 12, qtemplate))
+    nextylink = p.url(request, querystr % (qpagenames, parmoffset2 + 12, qtemplate))
     prevmonth = formatter.url(1, prevlink, 'cal-link') + '&lt;' + formatter.url(0)
     nextmonth = formatter.url(1, nextlink, 'cal-link') + '&gt;' + formatter.url(0)
     prevyear = formatter.url(1, prevylink, 'cal-link') + '&lt;&lt;' + formatter.url(0)
@@ -428,7 +428,7 @@
                             r, g, b = (r, g+colorstep, b)
                 r, g, b = cliprgb(r, g, b)
                 style = 'background-color:#%02x%02x%02x' % (r, g, b)
-                fmtlink = formatter.url(1, daypage.url(request, query, escape=0), csslink, **onmouse) + str(day) + formatter.url(0)
+                fmtlink = formatter.url(1, daypage.url(request, query), csslink, **onmouse) + str(day) + formatter.url(0)
                 if day == currentday and month == currentmonth and year == currentyear:
                     cssday = "cal-today"
                     fmtlink = "<b>%s</b>" % fmtlink # for browser with CSS probs
--- a/MoinMoin/parser/text_rst.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/parser/text_rst.py	Sun Feb 25 03:08:18 2007 +0100
@@ -384,9 +384,8 @@
                 anchor = ''
                 if '#' in refuri:
                     pagename, anchor = refuri.split('#', 1)
-                    anchor = '#' + anchor
                 page = Page(self.request, wikiutil.AbsPageName(self.request, self.formatter.page.page_name, pagename))
-                node['refuri'] = page.url(self.request) + anchor
+                node['refuri'] = page.url(self.request, anchor=anchor)
                 if not page.exists():
                     node['classes'].append('nonexistent')
         html4css1.HTMLTranslator.visit_reference(self, node)
--- a/MoinMoin/request/__init__.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/request/__init__.py	Sun Feb 25 03:08:18 2007 +0100
@@ -1106,10 +1106,10 @@
                         wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(self, pagetrail[-1])
                         url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
                     else:
-                        url = Page(self, pagetrail[-1]).url(self, escape=0, relative=False)
+                        url = Page(self, pagetrail[-1]).url(self, relative=False)
                 else:
                     # Or to localized FrontPage
-                    url = wikiutil.getFrontPage(self).url(self, escape=0, relative=False)
+                    url = wikiutil.getFrontPage(self).url(self, relative=False)
                 self.http_redirect(url)
                 return self.finish()
 
--- a/MoinMoin/stats/hitcounts.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/stats/hitcounts.py	Sun Feb 25 03:08:18 2007 +0100
@@ -37,8 +37,7 @@
     if params:
         querystr += '&amp;' + params
 
-    # TODO: remove escape=0 in 2.0
-    data = {'url': page.url(request, querystr, escape=0)}
+    data = {'url': page.url(request, querystr)}
     data.update(request.cfg.chart_options)
     result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
               ' alt="hitcounts chart">') % data
--- a/MoinMoin/stats/pagesize.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/stats/pagesize.py	Sun Feb 25 03:08:18 2007 +0100
@@ -34,8 +34,7 @@
     if params:
         querystr += '&amp;' + params
 
-    # TODO: remove escape=0 in 2.0
-    data = {'url': page.url(request, querystr, escape=0)}
+    data = {'url': page.url(request, querystr)}
     data.update(request.cfg.chart_options)
     result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
               ' alt="pagesize chart">') % data
--- a/MoinMoin/stats/useragents.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/stats/useragents.py	Sun Feb 25 03:08:18 2007 +0100
@@ -35,8 +35,7 @@
     if params:
         querystr += '&amp;' + params
 
-    # TODO: remove escape=0 in 2.0
-    data = {'url': page.url(request, querystr, escape=0)}
+    data = {'url': page.url(request, querystr)}
     data.update(request.cfg.chart_options)
     result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
               ' alt="useragents chart">') % data
--- a/MoinMoin/theme/__init__.py	Sat Feb 24 20:42:21 2007 +0100
+++ b/MoinMoin/theme/__init__.py	Sun Feb 25 03:08:18 2007 +0100
@@ -1166,7 +1166,7 @@
 var gui_editor_link_text = "%(text)s";
 //-->
 </script>        
-""" % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, escape=0, relative=False),
+""" % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, relative=False),
        'text': _('Edit (GUI)', formatted=False),
       }
 
@@ -1584,8 +1584,7 @@
             request.user.edit_on_doubleclick):
             if request.user.may.write(pagename): # separating this gains speed
                 querystr = wikiutil.escape(wikiutil.makeQueryString({'action': 'edit'}))
-                # TODO: remove escape=0 in 2.0
-                url = page.url(request, querystr, escape=0, relative=False)
+                url = page.url(request, querystr, relative=False)
                 bodyattr.append(''' ondblclick="location.href='%s'" ''' % url)
 
         # Set body to the user interface language and direction
--- a/docs/CHANGES	Sat Feb 24 20:42:21 2007 +0100
+++ b/docs/CHANGES	Sun Feb 25 03:08:18 2007 +0100
@@ -65,6 +65,8 @@
     get reverted.
 
   Developer notes (these should be moved to the end in the release):
+    * Page.url() does not escape any more. You have to use wikiutil.escape()
+      yourself if you want to write the URL to HTML and it contains e.g. &.
     * the testing wikiconfig moved to tests/wikiconfig.py, the testing wiki
       is now created in tests/wiki/...
     * killed "processors" (finally), formatter method changed to: