changeset 3057:9c58f31af69e

CopyPage/RenamePage/DeletePage action: fix regex compile errors due to unescaped pagename usage, fix cosmetic bug, simplify/optimize code (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 21 Feb 2008 20:06:02 +0100
parents b7914fb12243
children f48d46b39364
files MoinMoin/action/CopyPage.py MoinMoin/action/DeletePage.py MoinMoin/action/RenamePage.py
diffstat 3 files changed, 22 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/CopyPage.py	Thu Feb 21 19:41:15 2008 +0100
+++ b/MoinMoin/action/CopyPage.py	Thu Feb 21 20:06:02 2008 +0100
@@ -4,7 +4,8 @@
 
     This action allows you to copy a page.
 
-    @copyright: 2007 MoinMoin:ReimarBauer
+    @copyright: 2007 MoinMoin:ReimarBauer,
+                2007 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 import re
@@ -24,16 +25,11 @@
         _ = self._
         self.form_trigger = 'copy'
         self.form_trigger_label = _('Copy Page')
-        filterfn = re.compile(pagename).match
+        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
         pages = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
-        self.subpages = []
-        self.users_subpages = []
-        subpage = pagename + '/'
-        for name in pages:
-            if name.startswith(subpage):
-                self.subpages.append(name)
-                if self.request.user.may.read(name):
-                    self.users_subpages.append(name)
+        subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
+        self.subpages = subpagenames
+        self.users_subpages = [pagename for pagename in subpagenames if self.request.user.may.read(pagename)]
 
     def is_allowed(self):
         may = self.request.user.may
@@ -56,7 +52,7 @@
         comment = wikiutil.clean_input(comment)
 
         self.page = PageEditor(self.request, self.pagename)
-        success, msg = self.page.copyPage(newpagename, comment)
+        success, msgs = self.page.copyPage(newpagename, comment)
 
         copy_subpages = 0
         if form.has_key('copy_subpages'):
@@ -70,9 +66,10 @@
                 self.page = PageEditor(self.request, name)
                 new_subpagename = name.replace(self.pagename, newpagename, 1)
                 success_i, msg = self.page.copyPage(new_subpagename, comment)
+                msgs = "%s %s" % (msgs, msg)
 
         self.newpagename = newpagename # keep there for finish
-        return success, msg
+        return success, msgs
 
     def do_action_finish(self, success):
         if success:
--- a/MoinMoin/action/DeletePage.py	Thu Feb 21 19:41:15 2008 +0100
+++ b/MoinMoin/action/DeletePage.py	Thu Feb 21 20:06:02 2008 +0100
@@ -4,7 +4,7 @@
 
     This action allows you to delete a page.
 
-    @copyright: 2006 MoinMoin:ThomasWaldmann,
+    @copyright: 2006-2007 MoinMoin:ThomasWaldmann,
                 2007 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
@@ -24,13 +24,8 @@
         _ = self._
         self.form_trigger = 'delete'
         self.form_trigger_label = _('Delete')
-        filterfn = re.compile(pagename).match
-        pages = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
-        self.subpages = []
-        subpage = pagename + '/'
-        for name in pages:
-            if name.startswith(subpage) and self.request.user.may.delete(name):
-                self.subpages.append(name)
+        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
+        self.subpages = [pagename for pagename in subpagenames if self.request.user.may.delete(pagename)]
 
     def is_allowed(self):
         # this is not strictly necessary because the underlying storage code checks
@@ -54,8 +49,8 @@
         # Create a page editor that does not do editor backups, because
         # delete generates a "deleted" version of the page.
         self.page = PageEditor(self.request, self.pagename, do_editor_backup=0)
-        success, msg = self.page.deletePage(comment)
-        msgs = msg
+        success, msgs = self.page.deletePage(comment)
+
         delete_subpages = 0
         if 'delete_subpages' in form:
             try:
@@ -67,7 +62,7 @@
             for name in self.subpages:
                 self.page = PageEditor(self.request, name, do_editor_backup=0)
                 success_i, msg = self.page.deletePage(comment)
-                msgs += "%s " % msg
+                msgs = "%s %s" % (msgs, msg)
 
         return success, msgs
 
--- a/MoinMoin/action/RenamePage.py	Thu Feb 21 19:41:15 2008 +0100
+++ b/MoinMoin/action/RenamePage.py	Thu Feb 21 20:06:02 2008 +0100
@@ -5,7 +5,7 @@
     This action allows you to rename a page.
 
     @copyright: 2002-2004 Michael Reinsch <mr@uue.org>,
-                2006 MoinMoin:ThomasWaldmann,
+                2006-2007 MoinMoin:ThomasWaldmann,
                 2007 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
@@ -26,13 +26,9 @@
         _ = self._
         self.form_trigger = 'rename'
         self.form_trigger_label = _('Rename Page')
-        filterfn = re.compile(pagename).match
-        pages = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
-        self.subpages = []
-        subpage = pagename + '/'
-        for name in pages:
-            if name.startswith(subpage) and self.request.user.may.delete(name):
-                self.subpages.append(name)
+        filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
+        subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
+        self.subpages = [pagename for pagename in subpagenames if self.request.user.may.delete(pagename)]
 
     def is_allowed(self):
         may = self.request.user.may
@@ -55,7 +51,7 @@
         comment = wikiutil.clean_input(comment)
 
         self.page = PageEditor(self.request, self.pagename)
-        success, msg = self.page.renamePage(newpagename, comment)
+        success, msgs = self.page.renamePage(newpagename, comment)
 
         rename_subpages = 0
         if 'rename_subpages' in form:
@@ -69,9 +65,10 @@
                 self.page = PageEditor(self.request, name)
                 new_subpagename = name.replace(self.pagename, newpagename, 1)
                 success_i, msg = self.page.renamePage(new_subpagename, comment)
+                msgs = "%s %s" % (msgs, msg)
 
         self.newpagename = newpagename # keep there for finish
-        return success, msg
+        return success, msgs
 
     def do_action_finish(self, success):
         if success: