changeset 2710:d7cad3d048b9

Merge.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Wed, 22 Aug 2007 11:19:50 +0200
parents d64926adfb86 (current diff) 5092edd82058 (diff)
children 92fdea43e06e 53be04ae3ac1
files
diffstat 13 files changed, 96 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/PageEditor.py	Wed Aug 22 11:19:50 2007 +0200
@@ -155,8 +155,6 @@
         request = self.request
         form = request.form
         _ = self._
-        request.disableHttpCaching(level=2)
-        request.emit_http_headers()
 
         raw_body = ''
         msg = None
@@ -199,6 +197,10 @@
             self.send_page(msg=msg)
             return
 
+        # Emmit http_headers after checks (send_page)
+        request.disableHttpCaching(level=2)
+        request.emit_http_headers()
+
         # check if we want to load a draft
         use_draft = None
         if 'button_load_draft' in form:
@@ -403,7 +405,7 @@
 
         request.write(
             u'''\
-<textarea id="editor-textarea" name="savetext" lang="%(lang)s" dir="%(dir)s" rows="%(rows)d"
+<textarea id="editor-textarea" name="savetext" lang="%(lang)s" dir="%(dir)s" rows="%(rows)d" cols="80"
           onChange="flgChange = true;" onKeyPress="flgChange = true;">\
 %(text)s\
 </textarea>''' % {
@@ -415,7 +417,7 @@
 
         request.write("<p>")
         request.write(_("Comment:"),
-            ' <input id="editor-comment" type="text" name="comment" value="%s" maxlength="200"'
+            ' <input id="editor-comment" type="text" name="comment" value="%s" size="80" maxlength="200"'
             ' onChange="flgChange = true;" onKeyPress="flgChange = true;">' % (
                 wikiutil.escape(kw.get('comment', ''), 1), ))
         request.write("</p>")
--- a/MoinMoin/PageGraphicalEditor.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/PageGraphicalEditor.py	Wed Aug 22 11:19:50 2007 +0200
@@ -339,7 +339,7 @@
 """)
         request.write("<p>")
         request.write(_("Comment:"),
-            ' <input id="editor-comment" type="text" name="comment" value="%s" maxlength="200">' % (
+            ' <input id="editor-comment" type="text" name="comment" value="%s" size="80" maxlength="200">' % (
                 wikiutil.escape(kw.get('comment', ''), 1), ))
         request.write("</p>")
 
--- a/MoinMoin/_tests/test_wikiutil.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Wed Aug 22 11:19:50 2007 +0200
@@ -733,4 +733,33 @@
         encoded = wikiutil.anchor_name_from_text(text)
         assert expected == encoded
 
+class TestRelativeTools:
+    tests = [
+        # test                      expected output
+        # CHILD_PREFIX
+        (('MainPage', '/SubPage1'), 'MainPage/SubPage1'),
+        (('MainPage', '/SubPage1/SubPage2'), 'MainPage/SubPage1/SubPage2'),
+        (('MainPage/SubPage1', '/SubPage2/SubPage3'), 'MainPage/SubPage1/SubPage2/SubPage3'),
+        (('', '/OtherMainPage'), 'OtherMainPage'), # strange
+        # PARENT_PREFIX
+        (('MainPage/SubPage', '../SisterPage'), 'MainPage/SisterPage'),
+        (('MainPage/SubPage1/SubPage2', '../SisterPage'), 'MainPage/SubPage1/SisterPage'),
+        (('MainPage/SubPage1/SubPage2', '../../SisterPage'), 'MainPage/SisterPage'),
+        (('MainPage', '../SisterPage'), 'SisterPage'), # strange
+    ]
+    def test_abs_pagename(self):
+        for (current_page, relative_page), absolute_page in self.tests:
+            yield self._check_abs_pagename, current_page, relative_page, absolute_page
+
+    def _check_abs_pagename(self, current_page, relative_page, absolute_page):
+        assert absolute_page == wikiutil.AbsPageName(current_page, relative_page)
+
+    def test_rel_pagename(self):
+        for (current_page, relative_page), absolute_page in self.tests:
+            yield self._check_rel_pagename, current_page, absolute_page, relative_page
+
+    def _check_rel_pagename(self, current_page, absolute_page, relative_page):
+        assert relative_page == wikiutil.RelPageName(current_page, absolute_page)
+
+
 coverage_modules = ['MoinMoin.wikiutil']
--- a/MoinMoin/action/AttachFile.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/action/AttachFile.py	Wed Aug 22 11:19:50 2007 +0200
@@ -824,13 +824,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="newpagename" value="%(pagename)s">
+            <input type="text" name="newpagename" value="%(pagename)s" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(attachment_label)s</label></td>
         <td class="content">
-            <input type="text" name="newattachmentname" value="%(attachment_name)s">
+            <input type="text" name="newattachmentname" value="%(attachment_name)s" size="80">
         </td>
     </tr>
     <tr>
--- a/MoinMoin/action/CopyPage.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/action/CopyPage.py	Wed Aug 22 11:19:50 2007 +0200
@@ -116,13 +116,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="newpagename" value="%(pagename)s">
+            <input type="text" name="newpagename" value="%(pagename)s" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
@@ -146,13 +146,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="newpagename" value="%(pagename)s">
+            <input type="text" name="newpagename" value="%(pagename)s" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
--- a/MoinMoin/action/DeletePage.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/action/DeletePage.py	Wed Aug 22 11:19:50 2007 +0200
@@ -101,7 +101,7 @@
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
@@ -127,7 +127,7 @@
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
--- a/MoinMoin/action/PackagePages.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/action/PackagePages.py	Wed Aug 22 11:19:50 2007 +0200
@@ -153,13 +153,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="packagename" value="package.zip">
+            <input type="text" name="packagename" value="package.zip" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(list_label)s</label></td>
         <td class="content">
-            <input type="text" name="pagelist" maxlength="200" value=%(pagename)s>
+            <input type="text" name="pagelist" size="80" maxlength="200" value=%(pagename)s>
         </td>
     </tr>
     <tr>
--- a/MoinMoin/action/RenamePage.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/action/RenamePage.py	Wed Aug 22 11:19:50 2007 +0200
@@ -115,13 +115,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="newpagename" value="%(pagename)s">
+            <input type="text" name="newpagename" value="%(pagename)s" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
@@ -145,13 +145,13 @@
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>
         <td class="content">
-            <input type="text" name="newpagename" value="%(pagename)s">
+            <input type="text" name="newpagename" value="%(pagename)s" size="80">
         </td>
     </tr>
     <tr>
         <td class="label"><label>%(comment_label)s</label></td>
         <td class="content">
-            <input type="text" name="comment" maxlength="200">
+            <input type="text" name="comment" size="80" maxlength="200">
         </td>
     </tr>
     <tr>
--- a/MoinMoin/formatter/text_html.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Wed Aug 22 11:19:50 2007 +0200
@@ -489,7 +489,7 @@
                 wikitail, kw['anchor'] = wikitail.split('#', 1)
             wikitail = wikiutil.url_unquote(wikitail)
             try: # XXX this is the only place where we access self.page - do we need it? Crashes silently on actions!
-                pagename = wikiutil.AbsPageName(self.request, self.page.page_name, wikitail)
+                pagename = wikiutil.AbsPageName(self.page.page_name, wikitail)
             except:
                 pagename = wikitail
             return self.pagelink(on, pagename, **kw)
--- a/MoinMoin/macro/Include.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/macro/Include.py	Wed Aug 22 11:19:50 2007 +0200
@@ -73,7 +73,7 @@
         this_page._macroInclude_pagelist = {}
 
     # get list of pages to include
-    inc_name = wikiutil.AbsPageName(request, this_page.page_name, args.group('name'))
+    inc_name = wikiutil.AbsPageName(this_page.page_name, args.group('name'))
     pagelist = [inc_name]
     if inc_name.startswith("^"):
         try:
--- a/MoinMoin/parser/text_rst.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/parser/text_rst.py	Wed Aug 22 11:19:50 2007 +0200
@@ -379,7 +379,7 @@
                 anchor = ''
                 if '#' in refuri:
                     pagename, anchor = refuri.split('#', 1)
-                page = Page(self.request, wikiutil.AbsPageName(self.request, self.formatter.page.page_name, pagename))
+                page = Page(self.request, wikiutil.AbsPageName(self.formatter.page.page_name, pagename))
                 node['refuri'] = page.url(self.request, anchor=anchor)
                 if not page.exists():
                     node['classes'].append('nonexistent')
--- a/MoinMoin/script/migration/_conv160_wiki.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Wed Aug 22 11:19:50 2007 +0200
@@ -47,7 +47,7 @@
         """
         current_page = self.pagename
         item_type, page_name, file_name = (key + (None, ))[:3]
-        abs_page_name = wikiutil.AbsPageName(self.request, current_page, page_name)
+        abs_page_name = wikiutil.AbsPageName(current_page, page_name)
         if item_type == 'PAGE':
             item_name = page_name
             key = (item_type, abs_page_name)
--- a/MoinMoin/wikiutil.py	Wed Aug 22 11:18:49 2007 +0200
+++ b/MoinMoin/wikiutil.py	Wed Aug 22 11:19:50 2007 +0200
@@ -830,7 +830,7 @@
     return homewiki, username
 
 
-def AbsPageName(request, context, pagename):
+def AbsPageName(context, pagename):
     """
     Return the absolute pagename for a (possibly) relative pagename.
 
@@ -840,11 +840,50 @@
     @return: the absolute page name
     """
     if pagename.startswith(PARENT_PREFIX):
-        pagename = '/'.join([x for x in context.split('/')[:-1] + [pagename[PARENT_PREFIX_LEN:]] if x])
+        while context and pagename.startswith(PARENT_PREFIX):
+            context = '/'.join(context.split('/')[:-1])
+            pagename = pagename[PARENT_PREFIX_LEN:]
+        pagename = '/'.join(filter(None, [ context, pagename, ]))
     elif pagename.startswith(CHILD_PREFIX):
-        pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
+        if context:
+            pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
+        else:
+            pagename = pagename[CHILD_PREFIX_LEN:]
     return pagename
 
+def RelPageName(context, pagename):
+    """
+    Return the relative pagename for some context.
+
+    @param context: name of the page where "pagename" appears on
+    @param pagename: the absolute page name
+    @rtype: string
+    @return: the relative page name
+    """
+    if context == '':
+        # special case, context is some "virtual root" page with name == ''
+        # every page is a subpage of this virtual root
+        return CHILD_PREFIX + pagename
+    elif pagename.startswith(context + CHILD_PREFIX):
+        # simple child
+        return pagename[len(context):]
+    else:
+        # some kind of sister/aunt
+        context_frags = context.split('/')   # A, B, C, D, E
+        pagename_frags = pagename.split('/') # A, B, C, F
+        # first throw away common parents:
+        common = 0
+        for cf, pf in zip(context_frags, pagename_frags):
+            if cf == pf:
+                common += 1
+            else:
+                break
+        context_frags = context_frags[common:] # D, E
+        pagename_frags = pagename_frags[common:] # F
+        go_up = len(context_frags)
+        return PARENT_PREFIX * go_up + '/'.join(pagename_frags)
+
+
 def pagelinkmarkup(pagename):
     """ return markup that can be used as link to page <pagename> """
     from MoinMoin.parser.text_moin_wiki import Parser