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