changeset 1828:09e81597c7ce

PageEditor:cache cleaning for renamePage, DeletePage, minor optimisation, RenamePage feature added to rename all subpages
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 25 Feb 2007 21:59:25 +0100
parents 6a162bb60560
children f9baefe352d9
files MoinMoin/PageEditor.py MoinMoin/action/DeletePage.py MoinMoin/action/RenamePage.py
diffstat 3 files changed, 99 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Sun Feb 25 20:41:56 2007 +0100
+++ b/MoinMoin/PageEditor.py	Sun Feb 25 21:59:25 2007 +0100
@@ -4,6 +4,7 @@
 
     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
                 2005-2006 by MoinMoin:ThomasWaldmann
+                2007 by ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -530,6 +531,18 @@
             # Save page text with a comment about the old name
             savetext = u"## page was renamed from %s\n%s" % (self.page_name, savetext)
             newpage.saveText(savetext, 0, comment=comment, index=0, extra=self.page_name, action='SAVE/RENAME')
+            # delete pagelinks
+            arena = self
+            key = 'pagelinks'
+            cache = caching.CacheEntry(request, arena, key, scope='item')
+            cache.remove()
+
+            # clean the cache
+            for formatter_name in self.cfg.caching_formats:
+                arena = self
+                key = formatter_name
+                cache = caching.CacheEntry(request, arena, key, scope='item')
+                cache.remove()
 
             if request.cfg.xapian_search:
                 from MoinMoin.search.Xapian import Index
--- a/MoinMoin/action/DeletePage.py	Sun Feb 25 20:41:56 2007 +0100
+++ b/MoinMoin/action/DeletePage.py	Sun Feb 25 21:59:25 2007 +0100
@@ -5,9 +5,10 @@
     This action allows you to delete a page.
 
     @copyright: 2006 MoinMoin:ThomasWaldmann
+                2007 ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-
+import re
 from MoinMoin import wikiutil
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin.action import ActionBase
@@ -23,13 +24,13 @@
         _ = self._
         self.form_trigger = 'delete'
         self.form_trigger_label = _('Delete')
-        pages = request.rootpage.getPageList(user='', exists='')
+        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)
-                
 
     def is_allowed(self):
         # this is not strictly necessary because the underlying storage code checks
@@ -66,7 +67,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 " % msg
 
         return success, msgs
 
--- a/MoinMoin/action/RenamePage.py	Sun Feb 25 20:41:56 2007 +0100
+++ b/MoinMoin/action/RenamePage.py	Sun Feb 25 21:59:25 2007 +0100
@@ -6,9 +6,10 @@
 
     @copyright: 2002-2004 Michael Reinsch <mr@uue.org>,
                 2006 MoinMoin:ThomasWaldmann
+                2007 ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-
+import re
 from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
@@ -25,6 +26,13 @@
         _ = 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)
 
     def is_allowed(self):
         may = self.request.user.may
@@ -48,6 +56,20 @@
 
         self.page = PageEditor(self.request, self.pagename)
         success, msg = self.page.renamePage(newpagename, comment)
+
+        rename_subpages = 0
+        if form.has_key('rename_subpages'):
+            try:
+                rename_subpages = int(form['rename_subpages'][0])
+            except:
+                pass
+
+        if rename_subpages and self.subpages:
+            for name in self.subpages:
+                self.page = PageEditor(self.request, name)
+                new_subpagename = name.replace(self.pagename, newpagename, 1)
+                success_i, msg = self.page.renamePage(new_subpagename, comment)
+
         self.newpagename = newpagename # keep there for finish
         return success, msg
 
@@ -61,13 +83,64 @@
 
     def get_form_html(self, buttons_html):
         _ = self._
-        d = {
-            'pagename': wikiutil.escape(self.pagename),
-            'newname_label': _("New name"),
-            'comment_label': _("Optional reason for the renaming"),
-            'buttons_html': buttons_html,
-        }
-        return '''
+        if self.subpages:
+            subpages = ' '.join(self.subpages)
+
+            d = {
+                'subpage': subpages,
+                'subpages_checked':('', 'checked')[self.request.form.get('subpages_checked', ['0'])[0] == '1'],
+                'subpage_label': _('Rename all /subpages too?'),
+                'pagename': wikiutil.escape(self.pagename),
+                'newname_label': _("New name"),
+                'comment_label': _("Optional reason for the renaming"),
+                'buttons_html': buttons_html,
+                'querytext': _('Really rename this page?')
+                }
+
+            return '''
+<strong>%(querytext)s</strong>
+<br>
+<br>
+<table>
+    <tr>
+    <dd>
+        %(subpage_label)s<input type="checkbox" name="rename_subpages" value="1" %(subpages_checked)s> 
+    </dd>
+    <dd>
+        <class="label"><subpage> %(subpage)s</subpage>
+    </dd>   
+    </tr>
+</table>       
+<table>
+    <tr>
+        <td class="label"><label>%(newname_label)s</label></td>
+        <td class="content">
+            <input type="text" name="newpagename" value="%(pagename)s">
+        </td>
+    </tr>
+    <tr>
+        <td class="label"><label>%(comment_label)s</label></td>
+        <td class="content">
+            <input type="text" name="comment" maxlength="200">
+        </td>
+    </tr>
+    <tr>
+        <td></td>
+        <td class="buttons">
+            %(buttons_html)s
+        </td>
+    </tr>
+</table>
+''' % d
+        
+        else:
+            d = {
+                'pagename': wikiutil.escape(self.pagename),
+                'newname_label': _("New name"),
+                'comment_label': _("Optional reason for the renaming"),
+                'buttons_html': buttons_html,
+                }
+            return '''
 <table>
     <tr>
         <td class="label"><label>%(newname_label)s</label></td>