diff -r -u MoinMoin.orig/PageEditor.py MoinMoin/PageEditor.py --- MoinMoin.orig/PageEditor.py 2006-03-05 10:41:11.533854400 -0800 +++ MoinMoin/PageEditor.py 2006-03-05 18:37:02.346659200 -0800 @@ -136,7 +136,28 @@ edit_lock_message = None preview = kw.get('preview', None) staytop = kw.get('staytop', 0) + + # for section editing + issectionedit = kw.get('issectionedit', 1) + pagetext = kw.get('pagetext', None) + startline = int(form.get('startline', ['0'])[0]) + endline = int(form.get('endline', ['0'])[0]) + srev = int(form.get('srev', ['0'])[0]) + + if startline or endline: + if not startline: + startline = 1 + + if not endline: + endline = -1 + else: + issectionedit = 0 + if issectionedit: + # need to add config + self._allow_section_edit = self.cfg.allow_section_edit + # self._allow_section_edit = 1 + from MoinMoin.formatter.text_html import Formatter self.request.formatter = Formatter(self.request, store_pagelinks=1) @@ -175,7 +196,10 @@ title = _('Edit "%(pagename)s"') else: title = _('Preview of "%(pagename)s"') - self.set_raw_body(preview, modified=1) + if issectionedit and pagetext is not None: + self.set_raw_body(pagetext, modified=1) + else: + self.set_raw_body(preview, modified=1) # send header stuff lock_timeout = self.lock.timeout / 60 @@ -215,9 +239,19 @@ # We don't show preview when in conflict preview = None + # no section-editing any more + if issectionedit: + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.')) + issectionedit = 0 + elif self.exists(): # revision of existing page rev = self.current_rev() + + if issectionedit and preview is None: + if not (srev and srev == rev): + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.')) + issectionedit = 0 else: # page creation rev = 0 @@ -275,6 +309,12 @@ # Generate default content for new pages if not raw_body: raw_body = _('Describe %s here.') % (self.page_name,) + elif issectionedit: + # for section editing + if pagetext is not None: + raw_body = preview + else: + raw_body = self.fetchsection(raw_body, startline, endline) # send form self.request.write('
' % ( @@ -292,6 +332,11 @@ # Send revision of the page our edit is based on self.request.write('' % (rev,)) + # Send section startline and endline for section-editing + if issectionedit: + self.request.write('' % startline) + self.request.write('' % endline) + # Save backto in a hidden input backto = form.get('backto', [None])[0] if backto: @@ -393,6 +438,9 @@ badwords_re = None if preview is not None: + if issectionedit: + self.set_raw_body(preview) + if SpellCheck and ( form.has_key('button_spellcheck') or form.has_key('button_newwords')): @@ -418,7 +466,12 @@ content_id = 'previewbelow' else: content_id = 'preview' - self.send_page(self.request, content_id=content_id, content_only=1, + + if issectionedit: + self.send_page(self.request, content_id=content_id, content_only=1, + hilite_re=badwords_re, do_cache=False) + else: + self.send_page(self.request, content_id=content_id, content_only=1, hilite_re=badwords_re) self.request.write(self.request.formatter.endContent()) @@ -864,7 +917,7 @@ if newtext==saved_page.get_raw_body(): msg = _("You already saved this page!") return msg - + msg = _("""Sorry, someone else saved the page while you edited it. Please do the following: Use the back button of your browser, and cut&paste @@ -930,7 +983,17 @@ self.lock.release(force=not msg) # XXX does "not msg" make any sense? return msg - + + def fetchsection(self, pagetext, startline, endline): + + pagetext = pagetext.split('\n') + if endline == -1: + sectiontext = u'\n'.join(pagetext[startline-1:]) + else: + sectiontext = u'\n'.join(pagetext[startline-1:endline]) + + return sectiontext + class PageLock: """ Files MoinMoin.orig/PageEditor.pyc and MoinMoin/PageEditor.pyc differ diff -r -u MoinMoin.orig/PageGraphicalEditor.py MoinMoin/PageGraphicalEditor.py --- MoinMoin.orig/PageGraphicalEditor.py 2006-03-05 10:41:11.573912000 -0800 +++ MoinMoin/PageGraphicalEditor.py 2006-03-05 18:37:21.013500800 -0800 @@ -64,6 +64,27 @@ edit_lock_message = None preview = kw.get('preview', None) staytop = kw.get('staytop', 0) + + # for section editing + issectionedit = kw.get('issectionedit', 1) + pagetext = kw.get('pagetext', None) + startline = int(form.get('startline', ['0'])[0]) + endline = int(form.get('endline', ['0'])[0]) + srev = int(form.get('srev', ['0'])[0]) + + if startline or endline: + if not startline: + startline = 1 + + if not endline: + endline = -1 + else: + issectionedit = 0 + + if issectionedit: + # need to add config + self._allow_section_edit = self.cfg.allow_section_edit + # self._allow_section_edit = 1 # check edit permissions if not self.request.user.may.write(self.page_name): @@ -95,7 +116,10 @@ title = _('Edit "%(pagename)s"') else: title = _('Preview of "%(pagename)s"') - self.set_raw_body(preview, modified=1) + if issectionedit and pagetext is not None: + self.set_raw_body(pagetext, modified=1) + else: + self.set_raw_body(preview, modified=1) # send header stuff lock_timeout = self.lock.timeout / 60 @@ -135,9 +159,19 @@ # We don't show preview when in conflict preview = None + # no section-editing any more + if issectionedit: + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.')) + issectionedit = 0 + elif self.exists(): # revision of existing page rev = self.current_rev() + + if issectionedit and preview is None: + if not (srev and srev == rev): + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.')) + issectionedit = 0 else: # page creation rev = 0 @@ -195,13 +229,19 @@ # Generate default content for new pages if not raw_body: raw_body = _('Describe %s here.') % (self.page_name,) - + elif issectionedit: + # for section editing + if pagetext is not None: + raw_body = preview + else: + raw_body = self.fetchsection(raw_body, startline, endline) + # send form self.request.write('' % ( self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page_name), )) - + # yet another weird workaround for broken IE6 (it expands the text # editor area to the right after you begin to type...). IE sucks... # http://fplanque.net/2003/Articles/iecsstextarea/ @@ -212,6 +252,11 @@ # Send revision of the page our edit is based on self.request.write('' % (rev,)) + # Send section startline and endline for section-editing + if issectionedit: + self.request.write('' % startline) + self.request.write('' % endline) + # Save backto in a hidden input backto = form.get('backto', [None])[0] if backto: @@ -330,9 +375,12 @@ }) self.request.write("

") - + badwords_re = None if preview is not None: + if issectionedit: + self.set_raw_body(preview) + if SpellCheck and ( form.has_key('button_spellcheck') or form.has_key('button_newwords')): @@ -347,8 +395,13 @@ content_id = 'previewbelow' else: content_id = 'preview' - self.send_page(self.request, content_id=content_id, content_only=1, - hilite_re=badwords_re) + + if issectionedit: + self.send_page(self.request, content_id=content_id, content_only=1, + hilite_re=badwords_re, do_cache=False) + else: + self.send_page(self.request, content_id=content_id, content_only=1, + hilite_re=badwords_re) self.request.write(self.request.formatter.endContent()) # end content div wikiutil.send_footer(self.request, self.page_name) Files MoinMoin.orig/formatter/.text_html.py.swp and MoinMoin/formatter/.text_html.py.swp differ diff -r -u MoinMoin.orig/formatter/text_html.py MoinMoin/formatter/text_html.py --- MoinMoin.orig/formatter/text_html.py 2006-03-05 10:41:07.758425600 -0800 +++ MoinMoin/formatter/text_html.py 2006-03-05 18:43:27.089892800 -0800 @@ -192,6 +192,16 @@ self._is_included = kw.get('is_included', False) self.request = request self.cfg = request.cfg + + # for section editing + self._allow_section_edit = None + if not hasattr(request, 'sectionindex'): + request.sectionindex = 0 + + self.sectionstack = [] + self.sectionpool = {} + self.sectionlastdepth = 0 + self.lineno = 0 if not hasattr(request, '_fmt_hd_counters'): request._fmt_hd_counters = [] @@ -593,6 +603,7 @@ return '' % wikiutil.escape(id, 1) def line_anchordef(self, lineno): + self.lineno = lineno if line_anchors: return self.anchordef("line-%d" % lineno) else: @@ -1181,6 +1192,21 @@ if not self._base_depth: self._base_depth = depth + # section editing configuration + if self._allow_section_edit is None: + # need to add config + self._allow_section_edit = self.cfg.allow_section_edit + # self._allow_section_edit = 1 + sectionediting = self.request.getPragma('section-edit', '').lower() + if sectionediting in ['off']: + self._allow_section_edit = 0 + elif sectionediting in ['on']: + self._allow_section_edit = 1 + + if self._allow_section_edit: + if not self.request.user.may.write(self.page.page_name): + self._allow_section_edit = 0 + count_depth = max(depth - (self._base_depth - 1), 1) # check numbering, possibly changing the default @@ -1199,7 +1225,32 @@ # closing tag, with empty line after, to make source more readable if not on: - return self._close('h%d' % heading_depth) + '\n' + result = self._close('h%d' % heading_depth) + '\n' + + sectionscript = '' + if self._allow_section_edit: + + self.request.sectionindex += 1 + sectionindex = self.request.sectionindex + sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno) + + attr = 'id="sectionedit%d"' % sectionindex + + backto = u'' + if self._is_included and hasattr(self.request, "_Include_backto"): + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto) + + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name)) + srev = self.page.current_rev() + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno) + + result = ('%s%s%s%s' % + (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr), + self.icon('edit'), + self.url(0), + result)) + + return ' %s%s' % (result, sectionscript) # create section number number = '' @@ -1324,6 +1375,54 @@ allowed_attrs=self._allowed_table_attrs['row'], **kw) return self._close(tag) + '\n' + + def savesectioninfor(self, index, depth, lineno, save=1): + # store section information + section = {} + sectionscriptlist = [] + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";' + scriptresult = '' + + lastdepth = self.sectionlastdepth + sectionindex = index + + if lastdepth >= depth: + while 1: + if len(self.sectionstack): + lastsection = self.sectionstack.pop() + lastdepth = lastsection['depth'] + if lastdepth >= depth: + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1)) + else: + self.sectionstack.append(lastsection) + break + else: + break + + if save: + section['index'] = sectionindex + section['startlineno'] = lineno + section['depth'] = depth + section['endlineno'] = -1 + self.sectionlastdepth = depth + self.sectionpool[sectionindex] = section + self.sectionstack.append(section) + + if len(sectionscriptlist) > 0: + + scriptresult = u""" + +""" % u'\n'.join(sectionscriptlist) + + return scriptresult + + + def table_cell(self, on, attrs=None, **kw): tag = 'td' Files MoinMoin.orig/formatter/text_html.pyc and MoinMoin/formatter/text_html.pyc differ Only in MoinMoin.orig/macro: .Include.py.swp diff -r -u MoinMoin.orig/macro/Include.py MoinMoin/macro/Include.py --- MoinMoin.orig/macro/Include.py 2006-03-05 10:41:10.542428800 -0800 +++ MoinMoin/macro/Include.py 2006-03-05 18:36:37.681192000 -0800 @@ -219,7 +219,7 @@ try: cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name)) inc_page.send_page(request, content_only=1, content_id=cid, - omit_footnotes=True) + omit_footnotes=True, do_cache=False) result.append(strfile.getvalue()) finally: request.redirect() diff -r -u MoinMoin.orig/multiconfig.py MoinMoin/multiconfig.py --- MoinMoin.orig/multiconfig.py 2006-03-05 10:41:11.263465600 -0800 +++ MoinMoin/multiconfig.py 2006-03-05 18:37:37.577318400 -0800 @@ -291,6 +291,7 @@ show_login = 1 show_names = True show_section_numbers = 0 + allow_section_edit = 1 show_timings = 0 show_version = 0 siteid = 'default' Files MoinMoin.orig/multiconfig.pyc and MoinMoin/multiconfig.pyc differ diff -r -u MoinMoin.orig/wikiaction.py MoinMoin/wikiaction.py --- MoinMoin.orig/wikiaction.py 2006-03-05 10:41:19.254956800 -0800 +++ MoinMoin/wikiaction.py 2006-03-05 18:38:28.710844800 -0800 @@ -579,11 +579,36 @@ comment = wikiutil.clean_comment(comment) + # section editing + startline = int(request.form.get('startline', ['0'])[0]) + endline = int(request.form.get('endline', ['0'])[0]) + + if startline or endline: + issectionedit = 1 + + if not startline: + startline = 1 + + if not endline: + endline = -1 + + else: + issectionedit = 0 + + if issectionedit: + savetext = pg.normalizeText(savetext, stripspaces=rstrip) + sectiontext = savetext + savetext = mergesection(pg.get_raw_body(), savetext, startline, endline) + + # Edit was canceled if request.form.has_key('button_cancel'): pg.sendCancel(savetext or "", rev) return + if not issectionedit: + savetext = pg.normalizeText(savetext, stripspaces=rstrip) + # Add category # TODO: this code does not work with extended links, and is doing @@ -619,11 +644,17 @@ if (request.form.has_key('button_preview') or request.form.has_key('button_spellcheck') or request.form.has_key('button_newwords')): - pg.sendEditor(preview=savetext, comment=comment) + if issectionedit: + pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext) + else: + pg.sendEditor(preview=savetext, comment=comment) # Preview with mode switch elif request.form.has_key('button_switch'): - pg.sendEditor(preview=savetext, comment=comment, staytop=1) + if issectionedit: + pg.sendEditor(preview=sectiontext, comment=comment, staytop=1, pagetext=savetext) + else: + pg.sendEditor(preview=savetext, comment=comment, staytop=1) # Save new text else: @@ -644,7 +675,10 @@ querystr='action=diff&rev=%d' % rev) } # We don't send preview when we do merge conflict - pg.sendEditor(msg=conflict_msg, comment=comment) + if issectionedit: + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.')) + + pg.sendEditor(msg=conflict_msg, comment=comment, issectionedit=0) return else: savemsg = conflict_msg @@ -893,3 +927,14 @@ return handler +def mergesection(pagetext, newsectiontext, startline, endline): + + pagetext = pagetext.split('\n') + + prevtext = u'%s\n' % u'\n'.join(pagetext[:startline-1]) + if endline == -1: + nexttext = '' + else: + nexttext = u'\n%s' % u'\n'.join(pagetext[endline:]) + + return u'%s%s%s' % (prevtext, newsectiontext, nexttext) Files MoinMoin.orig/wikiaction.pyc and MoinMoin/wikiaction.pyc differ