1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - ApproveChanges 4 5 Permit the approval of an edited page queued by the page editor when an 6 unprivileged user attempted to save a page. Since queued changes are placed 7 in a subpage, this action just moves the queued page content into the 8 existing page when approving the changes. 9 10 @copyright: 2011 Paul Boddie <paul@boddie.org.uk> 11 @license: GNU GPL (v2 or later), see COPYING.txt for details. 12 """ 13 14 Dependencies = ['pages'] 15 16 from MoinMoin.action import ActionBase 17 from MoinMoin.PageEditor import PageEditor 18 from MoinMoin.wikiutil import escape 19 from ApproveChangesSupport import * 20 21 # Action class and supporting functions. 22 23 class ApproveChanges(ActionBase): 24 25 "An action which approves a queued page version." 26 27 def __init__(self, pagename, request): 28 ActionBase.__init__(self, pagename, request) 29 _ = self._ 30 self.form_trigger = "approve" 31 self.form_trigger_label = _("Approve changes") 32 33 def get_form_html(self, buttons_html): 34 _ = self._ 35 request = self.request 36 fmt = request.formatter 37 38 d = { 39 "buttons_html" : buttons_html, 40 "prompt" : escape(_("Approve the displayed page version?")), 41 } 42 43 # Prepare the output HTML. 44 45 html = ''' 46 <table> 47 <tr> 48 <td>%(prompt)s</td> 49 </tr> 50 <tr> 51 <td class="buttons"> 52 %(buttons_html)s 53 </td> 54 </tr> 55 </table>''' % d 56 57 return html 58 59 def do_action(self): 60 61 "Approve the page and move it into place." 62 63 _ = self._ 64 request = self.request 65 66 # Make sure that only suitably privileged users can perform this action. 67 68 queued_changes_page = get_queued_changes_page(request) 69 70 if not is_reviewer(request): 71 return 0, _("Only page reviewers can perform this action.") 72 73 # Edit the target page, using this page's content. 74 # The current page must be a queued page version. 75 76 if not is_queued_changes_page(request, self.pagename): 77 return 0, _("This page is not queued for approval.") 78 79 target_page_name = get_target_page_name(self.pagename) 80 target_page = PageEditor(request, target_page_name) 81 82 # Save the target page, first removing the signature and then removing 83 # any protective ACL. 84 85 body = self.page.get_raw_body() 86 87 body = check_page(request, body) 88 if not body: 89 return 0, _("The queued changes have been modified somehow. Not saving!") 90 91 body = remove_access_control(request, body) 92 93 try: 94 target_page.saveText(body, 0, comment=_("Changes to page approved.")) 95 except PageEditor.Unchanged: 96 pass 97 98 # Delete the current page. 99 # NOTE: The page could be deleted completely or certain revisions 100 # NOTE: purged. 101 # NOTE: (to-do/proper-queued-page-deletion.txt) 102 103 current_page = PageEditor(request, self.pagename) 104 current_page.deletePage(_("Changes to page approved.")) 105 106 # Redirect to the target page. 107 108 request.http_redirect(target_page.url(request)) 109 return 1, None 110 111 def render_success(self, msg, msgtype): 112 113 """ 114 Render neither 'msg' nor 'msgtype' since redirection should occur 115 instead. 116 NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. 117 """ 118 119 pass 120 121 # Action function. 122 123 def execute(pagename, request): 124 ApproveChanges(pagename, request).render() 125 126 # vim: tabstop=4 expandtab shiftwidth=4