# HG changeset patch
# User Paul Boddie <paul@boddie.org.uk>
# Date 1301168961 -3600
# Node ID eab32df358f6a10b5e1aa36d4e89927f56d857ca
# Parent  3931b6a8b535c151d17b8969fe8da64c6e88ecdd
Added support for returning to a particular section of a page, where the section
is provided by an included page, when cancelling or saving an edit on that
included page initiated from the "parent" or "including" page.

diff -r 3931b6a8b535 -r eab32df358f6 MoinMoin/PageEditor.py
--- a/MoinMoin/PageEditor.py	Sat Mar 12 23:48:11 2011 +0100
+++ b/MoinMoin/PageEditor.py	Sat Mar 26 20:49:21 2011 +0100
@@ -354,6 +354,9 @@
         backto = request.values.get('backto')
         if backto:
             request.write(unicode(html.INPUT(type="hidden", name="backto", value=backto)))
+        section = request.values.get('section')
+        if section:
+            request.write(unicode(html.INPUT(type="hidden", name="section", value=section)))
 
         # button bar
         button_spellcheck = '<input class="button" type="submit" name="button_spellcheck" value="%s" onClick="flgChange = false;">' % _('Check Spelling')
@@ -529,7 +532,12 @@
         backto = request.values.get('backto')
         if backto:
             pg = Page(request, backto)
-            request.http_redirect(pg.url(request))
+            section = request.values.get('section')
+            if section:
+                url = pg.url(request, anchor=section)
+            else:
+                url = pg.url(request)
+            request.http_redirect(url)
         else:
             request.theme.add_msg(_('Edit was cancelled.'), "error")
             self.send_page()
diff -r 3931b6a8b535 -r eab32df358f6 MoinMoin/action/edit.py
--- a/MoinMoin/action/edit.py	Sat Mar 12 23:48:11 2011 +0100
+++ b/MoinMoin/action/edit.py	Sat Mar 26 20:49:21 2011 +0100
@@ -177,6 +177,17 @@
             # msg contains a unicode string
             savemsg = unicode(msg)
 
+        backto = request.values.get('backto')
+        if backto:
+            pg = Page(request, backto)
+            section = request.values.get('section')
+            if section:
+                url = pg.url(request, anchor=section)
+            else:
+                url = pg.url(request)
+            request.http_redirect(url)
+            return
+
         # Send new page after save or after unsuccessful conflict merge.
         request.reset()
         pg = Page(request, pagename)
diff -r 3931b6a8b535 -r eab32df358f6 MoinMoin/macro/Include.py
--- a/MoinMoin/macro/Include.py	Sat Mar 12 23:48:11 2011 +0100
+++ b/MoinMoin/macro/Include.py	Sat Mar 26 20:49:21 2011 +0100
@@ -202,7 +202,7 @@
             this_page._macroInclude_pagelist.get(inc_name, 0) + 1
 
         # output a container for the included page
-        result.append(macro.formatter.div(1, css_class="included-page"))
+        result.append(macro.formatter.div(1, id=inc_name, css_class="included-page"))
 
         # output the included page
         strfile = StringIO.StringIO()
@@ -227,7 +227,7 @@
             result.extend([
                 macro.formatter.div(1, css_class="include-link"),
                 inc_page.link_to(request, '[%s]' % (inc_name, ), css_class="include-page-link"),
-                inc_page.link_to(request, '[%s]' % (_('edit'), ), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto}),
+                inc_page.link_to(request, '[%s]' % (_('edit'), ), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto, "section": wikiutil.anchor_name_from_text(inc_name)}),
                 macro.formatter.div(0),
             ])
         # XXX page.link_to is wrong now, it escapes the edit_icon html as it escapes normal text
