Attachment 'SectionEditing-1.7.1.patch'
Download 1 diff -r -u -x=pyc MoinMoin_orig/action/edit.py MoinMoin/action/edit.py
2 --- MoinMoin_orig/action/edit.py 2008-03-18 15:51:23.000000000 -0400
3 +++ MoinMoin/action/edit.py 2008-09-01 11:27:29.000000000 -0400
4 @@ -103,6 +103,28 @@
5 # we don't want to throw an exception if user cancelled anyway
6 if not cancelled:
7 raise
8 + # section editing
9 + startline = int(request.form.get('startline', ['0'])[0])
10 + endline = int(request.form.get('endline', ['0'])[0])
11 +
12 + if startline or endline:
13 + issectionedit = 1
14 +
15 + if not startline:
16 + startline = 1
17 +
18 + if not endline:
19 + endline = -1
20 +
21 + else:
22 + issectionedit = 0
23 +
24 + if issectionedit:
25 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
26 + sectiontext = savetext
27 + savetext = mergesection(pg.get_raw_body(), savetext, startline, endline)
28 +
29 +
30
31 if cancelled:
32 pg.sendCancel(savetext or "", rev)
33 @@ -149,12 +171,23 @@
34 if ('button_preview' in request.form or
35 'button_spellcheck' in request.form or
36 'button_newwords' in request.form):
37 - pg.sendEditor(preview=savetext, comment=comment)
38 + #pg.sendEditor(preview=savetext, comment=comment)
39 +
40 + if issectionedit:
41 + pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext)
42 + else:
43 + pg.sendEditor(preview=savetext, comment=comment)
44 +
45
46 # Preview with mode switch
47 elif 'button_switch' in request.form:
48 - pg.sendEditor(preview=savetext, comment=comment, staytop=1)
49 -
50 + #pg.sendEditor(preview=savetext, comment=comment, staytop=1)
51 +
52 + if issectionedit:
53 + pg.sendEditor(preview=sectiontext, comment=comment, staytop=1, pagetext=savetext)
54 + else:
55 + pg.sendEditor(preview=savetext, comment=comment, staytop=1)
56 +
57 # Save new text
58 else:
59 try:
60 @@ -170,7 +203,13 @@
61
62 pg.mergeEditConflict(rev)
63 # We don't send preview when we do merge conflict
64 - pg.sendEditor(msg=msg, comment=comment)
65 +# pg.sendEditor(msg=msg, comment=comment)
66 +
67 + if issectionedit:
68 + msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
69 +
70 + pg.sendEditor(msg=msg, comment=comment, issectionedit=0)
71 +
72 return
73
74 except pg.SaveError, msg:
75 @@ -185,3 +224,17 @@
76 request.rev = 0
77 request.theme.add_msg(savemsg, "info")
78 pg.send_page()
79 +
80 +def mergesection(pagetext, newsectiontext, startline, endline):
81 +
82 + pagetext = pagetext.split('\n')
83 +
84 + prevtext = u'%s\n' % u'\n'.join(pagetext[:startline-1])
85 + if endline == -1:
86 + nexttext = ''
87 + else:
88 + nexttext = u'\n%s' % u'\n'.join(pagetext[endline:])
89 +
90 + return u'%s%s%s' % (prevtext, newsectiontext, nexttext)
91 +
92 +
93 diff -r -u -x=pyc MoinMoin_orig/config/multiconfig.py MoinMoin/config/multiconfig.py
94 --- MoinMoin_orig/config/multiconfig.py 2008-07-20 08:38:06.000000000 -0400
95 +++ MoinMoin/config/multiconfig.py 2008-09-02 02:45:45.000000000 -0400
96 @@ -541,6 +541,7 @@
97 show_interwiki = False # show our interwiki name (usually in front of the page name)
98 show_names = True # show editor names on RecentChanges / info/history action
99 show_section_numbers = 0 # enumerate sections (headlines) by default?
100 + allow_section_edit = 1
101 show_timings = False # show some timing stats (usually in the footer)
102 show_version = False # show moin version info / (C) (depends on theme)
103
104 diff -r -u -x=pyc MoinMoin_orig/formatter/text_html.py MoinMoin/formatter/text_html.py
105 --- MoinMoin_orig/formatter/text_html.py 2008-08-04 08:20:15.000000000 -0400
106 +++ MoinMoin/formatter/text_html.py 2008-09-18 09:00:50.000000000 -0400
107 @@ -195,6 +195,16 @@
108 self.request = request
109 self.cfg = request.cfg
110 self.no_magic = kw.get('no_magic', False) # disabled tag auto closing
111 + # for section editing
112 + self._allow_section_edit = None
113 + if not hasattr(request, 'sectionindex'):
114 + self.request.sectionindex = 0
115 +
116 + self.sectionstack = []
117 + self.sectionpool = {}
118 + self.sectionlastdepth = 0
119 + self.lineno = 0
120 +
121
122 if not hasattr(request, '_fmt_hd_counters'):
123 request._fmt_hd_counters = []
124 @@ -562,6 +572,7 @@
125 return '<span class="anchor" id="%s"></span>' % id
126
127 def line_anchordef(self, lineno):
128 + self.lineno = lineno
129 if line_anchors:
130 return self.anchordef("line-%d" % lineno)
131 else:
132 @@ -1168,6 +1179,20 @@
133 # remember depth of first heading, and adapt counting depth accordingly
134 if not self._base_depth:
135 self._base_depth = depth
136 + # section editing configuration
137 + if self._allow_section_edit is None:
138 + # need to add config
139 + self._allow_section_edit = self.cfg.allow_section_edit
140 + # self._allow_section_edit = 1
141 + sectionediting = self.request.getPragma('section-edit', '').lower()
142 + if sectionediting in ['off']:
143 + self._allow_section_edit = 0
144 + elif sectionediting in ['on']:
145 + self._allow_section_edit = 1
146 +
147 + if self._allow_section_edit:
148 + if not self.request.user.may.write(self.page.page_name):
149 + self._allow_section_edit = 0
150
151 count_depth = max(depth - (self._base_depth - 1), 1)
152
153 @@ -1187,8 +1212,36 @@
154
155 # closing tag, with empty line after, to make source more readable
156 if not on:
157 - return self._close('h%d' % heading_depth) + '\n'
158 -
159 + # section-editing
160 + #return self._close('h%d' % heading_depth) + '\n'
161 + result = self._close('h%d' % heading_depth) + '\n'
162 +
163 + sectionscript = ''
164 + if self._allow_section_edit:
165 +
166 + self.request.sectionindex += 1
167 + sectionindex = self.request.sectionindex
168 + sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
169 +
170 + section_attr = 'sectionedit%d' % sectionindex
171 +
172 + backto = u''
173 + if self._is_included and hasattr(self.request, "_Include_backto"):
174 + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
175 +
176 + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
177 + srev = self.page.current_rev()
178 + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
179 +
180 + result = ('%s%s%s%s' %
181 + (self.url(1, querystring, unescaped=1, title='Edit this section', id=section_attr,css='sectionedit'),
182 + 'Edit',
183 + self.url(0),
184 + result))
185 +
186 + return ' %s%s' % (result, sectionscript)
187 + # end of section-editing
188 +
189 # create section number
190 number = ''
191 if self._show_section_numbers:
192 @@ -1312,7 +1365,56 @@
193 allowed_attrs=self._allowed_table_attrs['row'],
194 **kw)
195 return self._close(tag) + '\n'
196 +
197 + # section-editing
198 +
199 + def savesectioninfor(self, index, depth, lineno, save=1):
200 + # store section information
201 + section = {}
202 + sectionscriptlist = []
203 + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
204 + scriptresult = ''
205 +
206 + lastdepth = self.sectionlastdepth
207 + sectionindex = index
208 +
209 + if lastdepth >= depth:
210 + while 1:
211 + if len(self.sectionstack):
212 + lastsection = self.sectionstack.pop()
213 + lastdepth = lastsection['depth']
214 + if lastdepth >= depth:
215 + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
216 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
217 + else:
218 + self.sectionstack.append(lastsection)
219 + break
220 + else:
221 + break
222 +
223 + if save:
224 + section['index'] = sectionindex
225 + section['startlineno'] = lineno
226 + section['depth'] = depth
227 + section['endlineno'] = -1
228 + self.sectionlastdepth = depth
229 + self.sectionpool[sectionindex] = section
230 + self.sectionstack.append(section)
231 +
232 + if len(sectionscriptlist) > 0:
233 +
234 + scriptresult = u"""
235 +<script type="text/javascript">
236 +<!--
237 +%s
238 +//-->
239 +</script>
240 +""" % u'\n'.join(sectionscriptlist)
241 +
242 + return scriptresult
243
244 + # end of section-editing
245 +
246 def table_cell(self, on, attrs=None, **kw):
247 tag = 'td'
248 if on:
249 diff -r -u -x=pyc MoinMoin_orig/macro/Include.py MoinMoin/macro/Include.py
250 --- MoinMoin_orig/macro/Include.py 2008-03-09 18:40:59.000000000 -0400
251 +++ MoinMoin/macro/Include.py 2008-09-01 10:51:57.000000000 -0400
252 @@ -206,7 +206,7 @@
253 try:
254 inc_page.send_page(content_only=True,
255 omit_footnotes=True,
256 - count_hit=False)
257 + count_hit=False,do_cache=False)
258 result.append(strfile.getvalue())
259 finally:
260 request.redirect()
261 diff -r -u -x=pyc MoinMoin_orig/PageEditor.py MoinMoin/PageEditor.py
262 --- MoinMoin_orig/PageEditor.py 2008-06-20 16:10:19.000000000 -0400
263 +++ MoinMoin/PageEditor.py 2008-09-01 11:04:13.000000000 -0400
264 @@ -158,6 +158,30 @@
265 edit_lock_message = None
266 preview = kw.get('preview', None)
267 staytop = kw.get('staytop', 0)
268 +
269 + # for section editing
270 + issectionedit = kw.get('issectionedit', 1)
271 + pagetext = kw.get('pagetext', None)
272 + startline = int(form.get('startline', ['0'])[0])
273 + endline = int(form.get('endline', ['0'])[0])
274 + srev = int(form.get('srev', ['0'])[0])
275 +
276 + if startline or endline:
277 + if not startline:
278 + startline = 1
279 +
280 + if not endline:
281 + endline = -1
282 + else:
283 + issectionedit = 0
284 +
285 + if issectionedit:
286 + # need to add config
287 + self._allow_section_edit = self.cfg.allow_section_edit
288 + # self._allow_section_edit = 1
289 +
290 + # end of section editing
291 +
292
293 from MoinMoin.formatter.text_html import Formatter
294 request.formatter = Formatter(request, store_pagelinks=1)
295 @@ -222,7 +246,16 @@
296 title = _('Preview of "%(pagename)s"')
297 # Propagate original revision
298 rev = request.rev
299 - self.set_raw_body(preview, modified=1)
300 +
301 + # section-editing
302 +
303 + #self.set_raw_body(preview, modified=1)
304 + if issectionedit and pagetext is not None:
305 + self.set_raw_body(pagetext, modified=1)
306 + else:
307 + self.set_raw_body(preview, modified=1)
308 +
309 + # end of section-editing
310
311 # send header stuff
312 lock_timeout = self.lock.timeout / 60
313 @@ -254,10 +287,28 @@
314 if conflict_msg:
315 # We don't show preview when in conflict
316 preview = None
317 + # section-editing
318 +
319 + # no section-editing any more
320 + if issectionedit:
321 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
322 + issectionedit = 0
323 +
324 + # end of section-editing
325 +
326
327 elif self.exists():
328 # revision of existing page
329 rev = self.current_rev()
330 +
331 + # section-editing
332 +
333 + if issectionedit and preview is None:
334 + if not (srev and srev == rev):
335 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
336 + issectionedit = 0
337 +
338 + # end of section-editing
339 else:
340 # page creation
341 rev = 0
342 @@ -329,6 +380,17 @@
343 # Generate default content for new pages
344 if not raw_body:
345 raw_body = _('Describe %s here.') % (self.page_name, )
346 + # section-editing
347 +
348 + elif issectionedit:
349 + # for section editing
350 + if pagetext is not None:
351 + raw_body = preview
352 + else:
353 + raw_body = self.fetchsection(raw_body, startline, endline)
354 +
355 + # end of section-editing
356 +
357
358 # send form
359 request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
360 @@ -345,6 +407,15 @@
361
362 # Send revision of the page our edit is based on
363 request.write('<input type="hidden" name="rev" value="%d">' % (rev, ))
364 + # section-editing
365 +
366 + # Send section startline and endline for section-editing
367 + if issectionedit:
368 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
369 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
370 +
371 + # end of section-editing
372 +
373
374 # Create and send a ticket, so we can check the POST
375 request.write('<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(request))
376 @@ -475,7 +546,14 @@
377
378 badwords_re = None
379 if preview is not None:
380 - if 'button_spellcheck' in form or 'button_newwords' in form:
381 + # section-editing
382 +
383 + if issectionedit:
384 + self.set_raw_body(preview)
385 +
386 + # end of section-editing
387 +
388 + if 'button_spellcheck' in form or 'button_newwords' in form:
389 badwords, badwords_re, msg = SpellCheck.checkSpelling(self, request, own_form=0)
390 request.write("<p>%s</p>" % msg)
391 request.write('</fieldset>')
392 @@ -494,7 +572,17 @@
393 content_id = 'previewbelow'
394 else:
395 content_id = 'preview'
396 - self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
397 +
398 + # section-editing
399 +
400 + #self.send_page(content_id=content_id, content_only=1,hilite_re=badwords_re)
401 +
402 + if issectionedit:
403 + self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re, do_cache=False)
404 + else:
405 + self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
406 +
407 + # end of section-editing
408
409 request.write(request.formatter.endContent())
410 request.theme.send_footer(self.page_name)
411 @@ -1150,6 +1238,20 @@
412 self.lock.release(force=not msg) # XXX does "not msg" make any sense?
413
414 return msg
415 + # section-editing
416 +
417 + def fetchsection(self, pagetext, startline, endline):
418 +
419 + pagetext = pagetext.split('\n')
420 + if endline == -1:
421 + sectiontext = u'\n'.join(pagetext[startline-1:])
422 + else:
423 + sectiontext = u'\n'.join(pagetext[startline-1:endline])
424 +
425 + return sectiontext
426 +
427 + # end of section-editing
428 +
429
430
431 class PageLock:
432 diff -r -u -x=pyc MoinMoin_orig/PageGraphicalEditor.py MoinMoin/PageGraphicalEditor.py
433 --- MoinMoin_orig/PageGraphicalEditor.py 2008-05-20 14:21:16.000000000 -0400
434 +++ MoinMoin/PageGraphicalEditor.py 2008-09-01 11:10:29.000000000 -0400
435 @@ -60,6 +60,28 @@
436 edit_lock_message = None
437 preview = kw.get('preview', None)
438 staytop = kw.get('staytop', 0)
439 + # for section editing
440 + issectionedit = kw.get('issectionedit', 1)
441 + pagetext = kw.get('pagetext', None)
442 + startline = int(form.get('startline', ['0'])[0])
443 + endline = int(form.get('endline', ['0'])[0])
444 + srev = int(form.get('srev', ['0'])[0])
445 +
446 + if startline or endline:
447 + if not startline:
448 + startline = 1
449 +
450 + if not endline:
451 + endline = -1
452 + else:
453 + issectionedit = 0
454 +
455 + if issectionedit:
456 + # need to add config
457 + self._allow_section_edit = self.cfg.allow_section_edit
458 + # self._allow_section_edit = 1
459 +
460 + # end of section editing
461
462 # check edit permissions
463 if not request.user.may.write(self.page_name):
464 @@ -111,8 +133,13 @@
465 title = _('Preview of "%(pagename)s"')
466 # Propagate original revision
467 rev = request.rev
468 - self.set_raw_body(preview, modified=1)
469 -
470 + #self.set_raw_body(preview, modified=1)
471 +
472 + if issectionedit and pagetext is not None:
473 + self.set_raw_body(pagetext, modified=1)
474 + else:
475 + self.set_raw_body(preview, modified=1)
476 +
477 # send header stuff
478 lock_timeout = self.lock.timeout / 60
479 lock_page = wikiutil.escape(self.page_name, quote=1)
480 @@ -143,10 +170,19 @@
481 if conflict_msg:
482 # We don't show preview when in conflict
483 preview = None
484 + # no section-editing any more
485 + if issectionedit:
486 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
487 + issectionedit = 0
488
489 elif self.exists():
490 # revision of existing page
491 rev = self.current_rev()
492 +
493 + if issectionedit and preview is None:
494 + if not (srev and srev == rev):
495 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
496 + issectionedit = 0
497 else:
498 # page creation
499 rev = 0
500 @@ -220,7 +256,14 @@
501 # Generate default content for new pages
502 if not raw_body:
503 raw_body = _('Describe %s here.') % (self.page_name, )
504 -
505 + elif issectionedit:
506 + # for section editing
507 + if pagetext is not None:
508 + raw_body = preview
509 + else:
510 + raw_body = self.fetchsection(raw_body, startline, endline)
511 +
512 +
513 # send form
514 request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
515 request.getScriptname(),
516 @@ -243,6 +286,11 @@
517
518 # Create and send a ticket, so we can check the POST
519 request.write('<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(request))
520 + # Send section startline and endline for section-editing
521 + if issectionedit:
522 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
523 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
524 +
525
526 # Save backto in a hidden input
527 backto = form.get('backto', [None])[0]
528 @@ -392,6 +440,10 @@
529
530 badwords_re = None
531 if preview is not None:
532 +
533 + if issectionedit:
534 + self.set_raw_body(preview)
535 +
536 if 'button_spellcheck' in form or 'button_newwords' in form:
537 badwords, badwords_re, msg = SpellCheck.checkSpelling(self, request, own_form=0)
538 request.write("<p>%s</p>" % msg)
539 @@ -403,8 +455,12 @@
540 content_id = 'previewbelow'
541 else:
542 content_id = 'preview'
543 - self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
544 -
545 +# self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
546 + if issectionedit:
547 + self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re, do_cache=False)
548 + else:
549 + self.send_page(content_id=content_id, content_only=1, hilite_re=badwords_re)
550 +
551 request.write(request.formatter.endContent()) # end content div
552 request.theme.send_footer(self.page_name)
553 request.theme.send_closing_html()
554 diff -r -u -x=pyc MoinMoin_orig/Page.py MoinMoin/Page.py
555 --- MoinMoin_orig/Page.py 2008-05-19 03:40:47.000000000 -0400
556 +++ MoinMoin/Page.py 2008-09-03 09:00:55.000000000 -0400
557 @@ -1263,7 +1263,7 @@
558 return getattr(parser, 'caching', False)
559 return False
560
561 - def send_page_content(self, request, body, format='wiki', format_args='', do_cache=1, **kw):
562 + def send_page_content(self, request, body, format='wiki', format_args='', do_cache=False, **kw):
563 """ Output the formatted wiki page, using caching if possible
564
565 @param request: the request object
566 @@ -1277,7 +1277,11 @@
567 Parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", format)
568 parser = Parser(body, request, format_args=format_args, **kw)
569
570 - if not (do_cache and self.canUseCache(Parser)):
571 + # 3.08.08 by Taras
572 + # For section editing workaround
573 + #
574 + #if not (do_cache and self.canUseCache(Parser)):
575 + if True:
576 self.format(parser)
577 else:
578 try:
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.