changeset 4235:a6c315ff8d66

Make more use of werkzeugs Href object for URL-generation in MoinMoin
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sun, 20 Jul 2008 18:08:13 +0200
parents 5ddcd9fe00b4
children 97bffc03c15f
files MoinMoin/Page.py MoinMoin/PageEditor.py MoinMoin/PageGraphicalEditor.py MoinMoin/action/AttachFile.py MoinMoin/action/Despam.py MoinMoin/action/PackagePages.py MoinMoin/action/SpellCheck.py MoinMoin/action/SubscribeUser.py MoinMoin/action/__init__.py MoinMoin/action/sendcached.py MoinMoin/macro/AdvancedSearch.py MoinMoin/macro/FullSearch.py MoinMoin/macro/NewPage.py MoinMoin/macro/__init__.py MoinMoin/theme/__init__.py MoinMoin/userform/login.py MoinMoin/userprefs/oid.py
diffstat 17 files changed, 42 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/Page.py	Sun Jul 20 18:08:13 2008 +0200
@@ -754,12 +754,13 @@
                 url = "%s/%s/%s" % (request.cfg.url_prefix_action, action, url)
             url = '%s?%s' % (url, querystr)
 
+        if not relative:
+            url = request.href(url)
+
         # Add anchor
         if anchor:
             url = "%s#%s" % (url, wikiutil.url_quote_plus(anchor))
 
-        if not relative:
-            url = '%s/%s' % (request.script_root, url)
         return url
 
     def link_to_raw(self, request, text, querystr=None, anchor=None, **kw):
@@ -1026,10 +1027,7 @@
             # redirect to another page
             # note that by including "action=show", we prevent endless looping
             # (see code in "request") or any cascaded redirection
-            request.http_redirect('%s/%s?action=show&redirect=%s' % (
-                request.script_root,
-                wikiutil.quoteWikinameURL(pi['redirect']),
-                wikiutil.url_quote_plus(self.page_name, ''), ))
+            request.http_redirect(request.href(pi['redirect'], action='show', redirect=self.page_name))
             return
 
         # if necessary, load the formatter
--- a/MoinMoin/PageEditor.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/PageEditor.py	Sun Jul 20 18:08:13 2008 +0200
@@ -330,10 +330,9 @@
             raw_body = _('Describe %s here.') % (self.page_name, )
 
         # send form
-        request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
-            request.script_root,
-            wikiutil.quoteWikinameURL(self.page_name),
-            ))
+        request.write('<form id="editor" method="post" action="%s#preview" onSubmit="flgChange = false;">' % (
+                request.href(self.page_name)
+        ))
 
         # yet another weird workaround for broken IE6 (it expands the text
         # editor area to the right after you begin to type...). IE sucks...
--- a/MoinMoin/PageGraphicalEditor.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/PageGraphicalEditor.py	Sun Jul 20 18:08:13 2008 +0200
@@ -221,9 +221,8 @@
             raw_body = _('Describe %s here.') % (self.page_name, )
 
         # send form
-        request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
-            request.script_root,
-            wikiutil.quoteWikinameURL(self.page_name),
+        request.write('<form id="editor" method="post" action="%s#preview">' % (
+                request.href(self.page_name)
             ))
 
         # yet another weird workaround for broken IE6 (it expands the text
--- a/MoinMoin/action/AttachFile.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/AttachFile.py	Sun Jul 20 18:08:13 2008 +0200
@@ -723,11 +723,10 @@
 
     # move file
     d = {'action': action_name,
-         'baseurl': request.script_root,
+         'url': request.href(pagename),
          'do': 'attachment_move',
          'ticket': wikiutil.createTicket(request),
          'pagename': pagename,
-         'pagename_quoted': wikiutil.quoteWikinameURL(pagename),
          'attachment_name': filename,
          'move': _('Move'),
          'cancel': _('Cancel'),
@@ -735,7 +734,7 @@
          'attachment_label': _("New attachment name"),
         }
     formhtml = '''
-<form action="%(baseurl)s/%(pagename_quoted)s" method="POST">
+<form action="%(url)s" method="POST">
 <input type="hidden" name="action" value="%(action)s">
 <input type="hidden" name="do" value="%(do)s">
 <input type="hidden" name="ticket" value="%(ticket)s">
--- a/MoinMoin/action/Despam.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/Despam.py	Sun Jul 20 18:08:13 2008 +0200
@@ -104,14 +104,13 @@
     request.write('''
 </table>
 <p>
-<form method="post" action="%s/%s">
+<form method="post" action="%s">
 <input type="hidden" name="action" value="Despam">
 <input type="hidden" name="editor" value="%s">
 <input type="submit" name="ok" value="%s">
 </form>
 </p>
-''' % (request.script_root, wikiutil.quoteWikinameURL(pagename),
-       wikiutil.url_quote(editor), _("Revert all!")))
+''' % (request.href(pagename), wikiutil.url_quote(editor), _("Revert all!")))
 
 def revert_page(request, pagename, editor):
     if not request.user.may.revert(pagename):
--- a/MoinMoin/action/PackagePages.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/PackagePages.py	Sun Jul 20 18:08:13 2008 +0200
@@ -114,11 +114,10 @@
             error = u'<p class="error">%s</p>\n' % error
 
         d = {
-            'baseurl': self.request.script_root,
+            'url': self.request.href(self.pagename),
             'error': error,
             'action': self.__class__.__name__,
             'pagename': wikiutil.escape(self.pagename, True),
-            'pagename_quoted': wikiutil.quoteWikinameURL(self.pagename),
             'package': _('Package pages'),
             'cancel': _('Cancel'),
             'newname_label': _("Package name"),
@@ -126,7 +125,7 @@
         }
         form = '''
 %(error)s
-<form method="post" action="%(baseurl)s/%(pagename_quoted)s">
+<form method="post" action="%(url)s">
 <input type="hidden" name="action" value="%(action)s">
 <table>
     <tr>
--- a/MoinMoin/action/SpellCheck.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/SpellCheck.py	Sun Jul 20 18:08:13 2008 +0200
@@ -187,8 +187,8 @@
 
         # add a form containing the bad words
         if own_form:
-            msg = msg + ('<form method="post" action="%s/%s">\n'
-                         '<input type="hidden" name="action" value="%s">\n') % (request.script_root, wikiutil.quoteWikinameURL(page.page_name), action_name)
+            msg = msg + ('<form method="post" action="%s">\n'
+                         '<input type="hidden" name="action" value="%s">\n') % (request.href(page.page_name), action_name)
 
         checkbox = '<input type="checkbox" name="newwords" value="%(word)s">%(word)s&nbsp;&nbsp;'
         msg = msg + (
--- a/MoinMoin/action/SubscribeUser.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/SubscribeUser.py	Sun Jul 20 18:08:13 2008 +0200
@@ -19,12 +19,12 @@
     request.theme.send_title(_("Subscribe users to the page %s") % pagename, pagename=pagename)
 
     request.write("""
-<form action="%s/%s" method="POST" enctype="multipart/form-data">
+<form action="%s" method="POST" enctype="multipart/form-data">
 <input type="hidden" name="action" value="SubscribeUser">
 %s <input type="text" name="users" size="50">
 <input type="submit" value="Subscribe">
 </form>
-""" % (request.script_root, wikiutil.quoteWikinameURL(pagename),
+""" % (request.href(pagename),
       _("Enter user names (comma separated):")))
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
--- a/MoinMoin/action/__init__.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/__init__.py	Sun Jul 20 18:08:13 2008 +0200
@@ -136,19 +136,17 @@
 
         d = {
             'method': self.method,
-            'baseurl': self.request.script_root,
+            'url': self.request.href(self.pagename),
             'enctype': self.enctype,
             'error_html': error_html,
             'actionname': self.actionname,
-            'pagename': self.pagename,
-            'pagename_quoted': wikiutil.quoteWikinameURL(self.pagename),
             'ticket_html': ticket_html,
             'user_html': self.get_form_html(buttons_html),
         }
 
         form_html = '''
 %(error_html)s
-<form action="%(baseurl)s/%(pagename_quoted)s" method="%(method)s" enctype="%(enctype)s">
+<form action="%(url)s/%(pagename_quoted)s" method="%(method)s" enctype="%(enctype)s">
 <div>
 <input type="hidden" name="action" value="%(actionname)s">
 %(ticket_html)s
--- a/MoinMoin/action/sendcached.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/action/sendcached.py	Sun Jul 20 18:08:13 2008 +0200
@@ -136,10 +136,7 @@
 
 def get_url(request, key):
     """ get URL for the object cached for key """
-    return "%s/?%s" % (
-        request.script_root,
-        wikiutil.makeQueryString(dict(action=action_name, key=key), want_unicode=False))
-
+    return request.href(action=action_name, key=key)
 
 def get_cache_headers(request, key):
     """ get last_modified and headers cached for key """
--- a/MoinMoin/macro/AdvancedSearch.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/macro/AdvancedSearch.py	Sun Jul 20 18:08:13 2008 +0200
@@ -161,7 +161,7 @@
 
     # the dialogue
     return f.rawHTML('\n'.join([
-        u'<form method="get" action="%s/%s">' % (macro.request.script_root, wikiutil.quoteWikinameURL(macro.request.formatter.page.page_name)),
+        u'<form method="get" action="%s">' % macro.request.href(macro.request.formatter.page.page_name),
         u'<div>',
         u'<input type="hidden" name="action" value="fullsearch">',
         u'<input type="hidden" name="advancedsearch" value="1">',
--- a/MoinMoin/macro/FullSearch.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/macro/FullSearch.py	Sun Jul 20 18:08:13 2008 +0200
@@ -67,7 +67,7 @@
     # Format
     type = (type == "titlesearch")
     html = [
-        u'<form method="get" action="%s/%s">' % (macro.request.script_root, wikiutil.quoteWikinameURL(macro.request.formatter.page.page_name)),
+        u'<form method="get" action="%s">' % macro.request.href(macro.request.formatter.page.page_name),
         u'<div>',
         u'<input type="hidden" name="action" value="fullsearch">',
         u'<input type="hidden" name="titlesearch" value="%i">' % type,
--- a/MoinMoin/macro/NewPage.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/macro/NewPage.py	Sun Jul 20 18:08:13 2008 +0200
@@ -76,7 +76,7 @@
 
         # TODO: better abstract this using the formatter
         html = [
-            u'<form class="macro" method="POST" action="%s/%s"><div>' % (self.request.script_root, wikiutil.quoteWikinameURL(self.formatter.page.page_name)),
+            u'<form class="macro" method="POST" action="%s"><div>' % self.request.href(self.formatter.page.page_name),
             u'<input type="hidden" name="action" value="newpage">',
             u'<input type="hidden" name="parent" value="%s">' % wikiutil.escape(self.parent, 1),
             u'<input type="hidden" name="template" value="%s">' % wikiutil.escape(self.template, 1),
--- a/MoinMoin/macro/__init__.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/macro/__init__.py	Sun Jul 20 18:08:13 2008 +0200
@@ -280,7 +280,7 @@
         """
         _ = self._
         html = [
-            u'<form method="get" action="%s/%s"><div>' % (self.request.script_root, wikiutil.quoteWikinameURL(self.formatter.page.page_name)),
+            u'<form method="get" action="%s"><div>' % self.request.href(self.formatter.page.page_name),
             u'<div>',
             u'<input type="hidden" name="action" value="goto">',
             u'<input type="text" name="target" size="30">',
--- a/MoinMoin/theme/__init__.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/theme/__init__.py	Sun Jul 20 18:08:13 2008 +0200
@@ -744,13 +744,12 @@
             'search_value': wikiutil.escape(form.get('value', [''])[0], 1),
             'search_full_label': _('Text'),
             'search_title_label': _('Titles'),
-            'baseurl': self.request.script_root,
-            'pagename_quoted': wikiutil.quoteWikinameURL(d['page'].page_name),
+            'url': self.request.href(d['page'].page_name)
             }
         d.update(updates)
 
         html = u'''
-<form id="searchform" method="get" action="%(baseurl)s/%(pagename_quoted)s">
+<form id="searchform" method="get" action="%(url)s">
 <div>
 <input type="hidden" name="action" value="fullsearch">
 <input type="hidden" name="context" value="180">
@@ -1052,11 +1051,10 @@
             'options': '\n'.join(options),
             'rev_field': rev and '<input type="hidden" name="rev" value="%d">' % rev or '',
             'do_button': _("Do"),
-            'baseurl': self.request.script_root,
-            'pagename_quoted': wikiutil.quoteWikinameURL(page.page_name),
+            'url': self.request.href(page.page_name)
             }
         html = '''
-<form class="actionsmenu" method="GET" action="%(baseurl)s/%(pagename_quoted)s">
+<form class="actionsmenu" method="GET" action="%(url)s">
 <div>
     <label>%(label)s</label>
     <select name="action"
@@ -1632,12 +1630,12 @@
         ))
 
         # Links
-        output.append('<link rel="Start" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_front_page)))
+        output.append('<link rel="Start" href="%s">\n' % request.href(page_front_page))
         if pagename:
-            output.append('<link rel="Alternate" title="%s" href="%s/%s?action=raw">\n' % (
-                _('Wiki Markup'), scriptname, pagename_quoted, ))
-            output.append('<link rel="Alternate" media="print" title="%s" href="%s/%s?action=print">\n' % (
-                _('Print View'), scriptname, pagename_quoted, ))
+            output.append('<link rel="Alternate" title="%s" href="%s">\n' % (
+                    _('Wiki Markup'), request.href(pagename, action='raw')))
+            output.append('<link rel="Alternate" media="print" title="%s" href="%s">\n' % (
+                    _('Print View'), request.href(pagename, action='print')))
 
             # !!! currently disabled due to Mozilla link prefetching, see
             # http://www.mozilla.org/projects/netlib/Link_Prefetching_FAQ.html
@@ -1657,7 +1655,7 @@
             #~         request.write('<link rel="Last" href="%s/%s">\n' % (request.script_root, quoteWikinameURL(all_pages[-1])))
 
             if page_parent_page:
-                output.append('<link rel="Up" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_parent_page)))
+                output.append('<link rel="Up" href="%s">\n' % request.href(page_parent_page))
 
         # write buffer because we call AttachFile
         request.write(''.join(output))
@@ -1670,10 +1668,10 @@
             AttachFile.send_link_rel(request, pagename)
 
         output.extend([
-            '<link rel="Search" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_find_page)),
-            '<link rel="Index" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_title_index)),
-            '<link rel="Glossary" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_word_index)),
-            '<link rel="Help" href="%s/%s">\n' % (scriptname, wikiutil.quoteWikinameURL(page_help_formatting)),
+            '<link rel="Search" href="%s">\n' % request.href(page_find_page),
+            '<link rel="Index" href="%s">\n' % request.href(page_title_index),
+            '<link rel="Glossary" href="%s">\n' % request.href(page_word_index),
+            '<link rel="Help" href="%s">\n' % request.href(page_help_formatting),
                       ])
 
         output.append("</head>\n")
--- a/MoinMoin/userform/login.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/userform/login.py	Sun Jul 20 18:08:13 2008 +0200
@@ -33,9 +33,7 @@
         """ Create the complete HTML form code. """
         _ = self._
         request = self.request
-        sn = request.script_root
-        pi = request.path
-        action = u"%s%s" % (sn, pi)
+        action = "%s%s" % (request.script_root, request.path)
         hints = []
         for authm in request.cfg.auth:
             hint = authm.login_hint(request)
--- a/MoinMoin/userprefs/oid.py	Sun Jul 20 16:43:12 2008 +0200
+++ b/MoinMoin/userprefs/oid.py	Sun Jul 20 18:08:13 2008 +0200
@@ -150,9 +150,7 @@
         return
 
     def _make_form(self):
-        sn = self.request.script_root
-        pi = self.request.path
-        action = u"%s%s" % (sn, pi)
+        action = "%s%s" % (self.request.script_root, self.request.path)
         _form = html.FORM(action=action)
         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
         _form.append(html.INPUT(type="hidden", name="handler", value="oid"))