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