Back to index

moin  1.9.0~rc2
DeletePage.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - DeletePage action
00004 
00005     This action allows you to delete a page.
00006 
00007     @copyright: 2006-2007 MoinMoin:ThomasWaldmann,
00008                 2007 MoinMoin:ReimarBauer
00009     @license: GNU GPL, see COPYING for details.
00010 """
00011 import re
00012 from MoinMoin import wikiutil
00013 from MoinMoin.PageEditor import PageEditor
00014 from MoinMoin.action import ActionBase
00015 
00016 class DeletePage(ActionBase):
00017     """ Delete page action
00018 
00019     Note: the action name is the class name
00020     """
00021     def __init__(self, pagename, request):
00022         ActionBase.__init__(self, pagename, request)
00023         self.use_ticket = True
00024         _ = self._
00025         self.form_trigger = 'delete'
00026         self.form_trigger_label = _('Delete')
00027         filterfn = re.compile(ur"^%s/.*$" % re.escape(pagename), re.U).match
00028         subpagenames = request.rootpage.getPageList(user='', exists=1, filter=filterfn)
00029         self.subpages = [pagename for pagename in subpagenames if self.request.user.may.delete(pagename)]
00030 
00031     def is_allowed(self):
00032         # this is not strictly necessary because the underlying storage code checks
00033         # as well
00034         may = self.request.user.may
00035         return may.write(self.pagename) and may.delete(self.pagename)
00036 
00037     def check_condition(self):
00038         _ = self._
00039         if not self.page.exists():
00040             return _('This page is already deleted or was never created!')
00041         else:
00042             return None
00043 
00044     def do_action(self):
00045         """ Delete pagename """
00046         form = self.form
00047         comment = form.get('comment', u'')
00048         comment = wikiutil.clean_input(comment)
00049 
00050         # Create a page editor that does not do editor backups, because
00051         # delete generates a "deleted" version of the page.
00052         self.page = PageEditor(self.request, self.pagename, do_editor_backup=0)
00053         success, msgs = self.page.deletePage(comment)
00054 
00055         delete_subpages = 0
00056         try:
00057             delete_subpages = int(form['delete_subpages'])
00058         except:
00059             pass
00060 
00061         if delete_subpages and self.subpages:
00062             for name in self.subpages:
00063                 self.page = PageEditor(self.request, name, do_editor_backup=0)
00064                 success_i, msg = self.page.deletePage(comment)
00065                 msgs = "%s %s" % (msgs, msg)
00066 
00067         return success, msgs
00068 
00069     def get_form_html(self, buttons_html):
00070         _ = self._
00071 
00072         if self.subpages:
00073             subpages = ' '.join(self.subpages)
00074 
00075             d = {
00076                 'subpage': subpages,
00077                 'subpages_checked': ('', 'checked')[self.request.args.get('subpages_checked', '0') == '1'],
00078                 'subpage_label': _('Delete all /subpages too?'),
00079                 'comment_label': _("Optional reason for the deletion"),
00080                 'buttons_html': buttons_html,
00081                 'querytext': _('Really delete this page?'),
00082                 }
00083 
00084             return '''
00085 <strong>%(querytext)s</strong>
00086 <br>
00087 <br>
00088 <table>
00089 <tr>
00090 <dd>
00091 %(subpage_label)s<input type="checkbox" name="delete_subpages" value="1" %(subpages_checked)s> </dd>
00092 <dd><class="label"><subpage> %(subpage)s</subpage></dd>
00093 </tr>
00094 </table>
00095 <table>
00096     <tr>
00097         <td class="label"><label>%(comment_label)s</label></td>
00098         <td class="content">
00099             <input type="text" name="comment" size="80" maxlength="200">
00100         </td>
00101     </tr>
00102     <tr>
00103         <td></td>
00104         <td class="buttons">
00105             %(buttons_html)s
00106         </td>
00107     </tr>
00108 </table>
00109 ''' % d
00110 
00111         else:
00112             d = {
00113                 'pagename': self.pagename,
00114                 'comment_label': _("Optional reason for the deletion"),
00115                 'buttons_html': buttons_html,
00116                 'querytext': _('Really delete this page?'),
00117                 }
00118 
00119             return '''
00120 <strong>%(querytext)s</strong>
00121 <table>
00122     <tr>
00123         <td class="label"><label>%(comment_label)s</label></td>
00124         <td class="content">
00125             <input type="text" name="comment" size="80" maxlength="200">
00126         </td>
00127     </tr>
00128     <tr>
00129         <td></td>
00130         <td class="buttons">
00131             %(buttons_html)s
00132         </td>
00133     </tr>
00134 </table>
00135 ''' % d
00136 
00137 
00138 
00139 def execute(pagename, request):
00140     """ Glue code for actions """
00141     DeletePage(pagename, request).render()
00142