# HG changeset patch
# User Paul Boddie <paul@boddie.org.uk>
# Date 1301169228 -3600
# Node ID 584575c1cfae0844166c15ec9e89b1e517e15a50
# Parent  fb521bcd610f8a096d1e72905f19f922e5d8eca2
Introduced a container around included pages in order to permit improved
positioning of the page-related links.
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.
(Combined two separate patches.)

diff -r fb521bcd610f -r 584575c1cfae MoinMoin/PageEditor.py
--- a/MoinMoin/PageEditor.py	Sat Feb 05 01:14:02 2011 +0100
+++ b/MoinMoin/PageEditor.py	Sat Mar 26 20:53:48 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 fb521bcd610f -r 584575c1cfae MoinMoin/action/edit.py
--- a/MoinMoin/action/edit.py	Sat Feb 05 01:14:02 2011 +0100
+++ b/MoinMoin/action/edit.py	Sat Mar 26 20:53:48 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 fb521bcd610f -r 584575c1cfae MoinMoin/macro/Include.py
--- a/MoinMoin/macro/Include.py	Sat Feb 05 01:14:02 2011 +0100
+++ b/MoinMoin/macro/Include.py	Sat Mar 26 20:53:48 2011 +0100
@@ -200,6 +200,9 @@
         this_page._macroInclude_pagelist[inc_name] = \
             this_page._macroInclude_pagelist.get(inc_name, 0) + 1
 
+        # output a container for the included page
+        result.append(macro.formatter.div(1, id=inc_name, css_class="included-page"))
+
         # output the included page
         strfile = StringIO.StringIO()
         request.redirect(strfile)
@@ -223,10 +226,13 @@
             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
+
+        # close the container for the included page
+        result.append(macro.formatter.div(0))
 
     # return include text
     return ''.join(result)
