1.1 --- a/actions/ApproveChanges.py Thu Oct 13 22:48:25 2011 +0200
1.2 +++ b/actions/ApproveChanges.py Thu Oct 13 23:31:45 2011 +0200
1.3 @@ -15,7 +15,8 @@
1.4
1.5 from MoinMoin.action import ActionBase
1.6 from MoinMoin.Page import Page
1.7 -from MoinMoin.PageEditor import PageEditor
1.8 +from MoinMoin.PageEditor import PageEditor, conflict_markers
1.9 +from MoinMoin.util import diff3
1.10 from ApproveChangesSupport import *
1.11
1.12 # Action class and supporting functions.
1.13 @@ -82,10 +83,8 @@
1.14 if not is_queued_changes_page(request, self.pagename):
1.15 return 0, _("This page is not queued for approval.")
1.16
1.17 - target_page_name = get_target_page_name(self.pagename)
1.18 - target_page = PageEditor(request, target_page_name)
1.19 -
1.20 - # First, the displayed revision must be retrieved.
1.21 + # First, the displayed revision of the queued changes page must be
1.22 + # retrieved.
1.23
1.24 form = get_form(request)
1.25
1.26 @@ -100,16 +99,51 @@
1.27 page = Page(request, self.page.page_name, rev=rev)
1.28 body = page.get_raw_body()
1.29
1.30 - # Save the target page, removing any introduced directives.
1.31 + # Remove any introduced directives.
1.32 +
1.33 + body, directives = remove_directives(body, ["acl", "parent-revision"])
1.34 +
1.35 + # Get the target page's parent revision for the queued changes.
1.36 +
1.37 + target_page_name = get_target_page_name(self.pagename)
1.38 + target_page = PageEditor(request, target_page_name)
1.39 +
1.40 + current_rev = target_page.current_rev()
1.41 + parent_rev = int(directives.get("parent-revision", current_rev))
1.42 +
1.43 + # Where the parent revision differs from the current revision of the
1.44 + # page, attempt to merge the changes.
1.45 +
1.46 + query = {}
1.47 +
1.48 + if parent_rev != current_rev:
1.49
1.50 - body = remove_directives(body, ["acl", "parent-revision"])
1.51 + # The body of the parent revision of the target page, along with the
1.52 + # body of the current revision must be acquired.
1.53 +
1.54 + parent_body = Page(request, target_page_name, rev=parent_rev).get_raw_body()
1.55 + current_body = target_page.get_raw_body()
1.56 +
1.57 + # The parent, current and queued texts must then be merged.
1.58 +
1.59 + body = diff3.text_merge(parent_body, current_body, body, True, *conflict_markers)
1.60 +
1.61 + # Look for conflict markers and redirect to edit mode on the
1.62 + # resulting page if they are present.
1.63 +
1.64 + for marker in conflict_markers:
1.65 + if body.find(marker) != -1:
1.66 + query = {'action' : 'edit'}
1.67 + break
1.68 +
1.69 + # Save the target page.
1.70
1.71 try:
1.72 target_page.saveText(body, 0, comment=_("Changes to page approved from queue revision %d.") % rev)
1.73 except PageEditor.Unchanged:
1.74 pass
1.75
1.76 - # Delete the current page.
1.77 + # Delete the queued changes page.
1.78 # NOTE: The page could be deleted completely or certain revisions
1.79 # NOTE: purged.
1.80 # NOTE: (to-do/proper-queued-page-deletion.txt)
1.81 @@ -117,9 +151,9 @@
1.82 current_page = PageEditor(request, self.pagename)
1.83 current_page.deletePage(_("Changes to page approved."))
1.84
1.85 - # Redirect to the target page.
1.86 + # Redirect to the target page, potentially in editing mode.
1.87
1.88 - request.http_redirect(target_page.url(request))
1.89 + request.http_redirect(target_page.url(request, query))
1.90 return 1, None
1.91
1.92 def render_success(self, msg, msgtype):