Attachment 'SectionEditing-1.5.4.patch'
Download 1 --- MoinMoin/macro/Include.py.orig Mon Oct 16 13:21:40 2006
2 +++ MoinMoin/macro/Include.py Tue Feb 13 16:48:00 2007
3 @@ -219,7 +219,7 @@
4 try:
5 cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name))
6 inc_page.send_page(request, content_only=1, content_id=cid,
7 - omit_footnotes=True)
8 + omit_footnotes=True, do_cache=False)
9 result.append(strfile.getvalue())
10 finally:
11 request.redirect()
12 --- MoinMoin/PageEditor.py.orig Mon Oct 2 21:09:04 2006
13 +++ MoinMoin/PageEditor.py Tue Feb 13 16:50:27 2007
14 @@ -149,6 +149,29 @@
15 preview = kw.get('preview', None)
16 staytop = kw.get('staytop', 0)
17
18 + # for section editing
19 + issectionedit = kw.get('issectionedit', 1)
20 + pagetext = kw.get('pagetext', None)
21 + startline = int(form.get('startline', ['0'])[0])
22 + endline = int(form.get('endline', ['0'])[0])
23 + srev = int(form.get('srev', ['0'])[0])
24 +
25 + if startline or endline:
26 + if not startline:
27 + startline = 1
28 +
29 + if not endline:
30 + endline = -1
31 + else:
32 + issectionedit = 0
33 +
34 + if issectionedit:
35 + # need to add config
36 + self._allow_section_edit = self.cfg.allow_section_edit
37 + # self._allow_section_edit = 1
38 +
39 + # end of section editing
40 +
41 from MoinMoin.formatter.text_html import Formatter
42 self.request.formatter = Formatter(self.request, store_pagelinks=1)
43
44 @@ -187,7 +210,16 @@
45 title = _('Edit "%(pagename)s"')
46 else:
47 title = _('Preview of "%(pagename)s"')
48 - self.set_raw_body(preview, modified=1)
49 +
50 + # section-editing
51 +
52 + #self.set_raw_body(preview, modified=1)
53 + if issectionedit and pagetext is not None:
54 + self.set_raw_body(pagetext, modified=1)
55 + else:
56 + self.set_raw_body(preview, modified=1)
57 +
58 + # end of section-editing
59
60 # send header stuff
61 lock_timeout = self.lock.timeout / 60
62 @@ -227,9 +259,27 @@
63 # We don't show preview when in conflict
64 preview = None
65
66 + # section-editing
67 +
68 + # no section-editing any more
69 + if issectionedit:
70 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
71 + issectionedit = 0
72 +
73 + # end of section-editing
74 +
75 elif self.exists():
76 # revision of existing page
77 rev = self.current_rev()
78 +
79 + # section-editing
80 +
81 + if issectionedit and preview is None:
82 + if not (srev and srev == rev):
83 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
84 + issectionedit = 0
85 +
86 + # end of section-editing
87 else:
88 # page creation
89 rev = 0
90 @@ -288,6 +338,17 @@
91 if not raw_body:
92 raw_body = _('Describe %s here.') % (self.page_name,)
93
94 + # section-editing
95 +
96 + elif issectionedit:
97 + # for section editing
98 + if pagetext is not None:
99 + raw_body = preview
100 + else:
101 + raw_body = self.fetchsection(raw_body, startline, endline)
102 +
103 + # end of section-editing
104 +
105 # send form
106 self.request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
107 self.request.getScriptname(),
108 @@ -304,6 +365,15 @@
109 # Send revision of the page our edit is based on
110 self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
111
112 + # section-editing
113 +
114 + # Send section startline and endline for section-editing
115 + if issectionedit:
116 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
117 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
118 +
119 + # end of section-editing
120 +
121 # Create and send a ticket, so we can check the POST
122 self.request.write('<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(self.request))
123
124 @@ -406,6 +476,14 @@
125
126 badwords_re = None
127 if preview is not None:
128 +
129 + # section-editing
130 +
131 + if issectionedit:
132 + self.set_raw_body(preview)
133 +
134 + # end of section-editing
135 +
136 if SpellCheck and (
137 form.has_key('button_spellcheck') or
138 form.has_key('button_newwords')):
139 @@ -427,9 +505,22 @@
140 content_id = 'previewbelow'
141 else:
142 content_id = 'preview'
143 - self.send_page(self.request, content_id=content_id, content_only=1,
144 +
145 +
146 + # section-editing
147 +
148 + #self.send_page(self.request, content_id=content_id, content_only=1,
149 + # hilite_re=badwords_re)
150 +
151 + if issectionedit:
152 + self.send_page(self.request, content_id=content_id, content_only=1,
153 + hilite_re=badwords_re, do_cache=False)
154 + else:
155 + self.send_page(self.request, content_id=content_id, content_only=1,
156 hilite_re=badwords_re)
157
158 + # end of section-editing
159 +
160 self.request.write(self.request.formatter.endContent())
161 wikiutil.send_footer(self.request, self.page_name)
162
163 @@ -1009,6 +1100,20 @@
164 return msg
165
166
167 + # section-editing
168 +
169 + def fetchsection(self, pagetext, startline, endline):
170 +
171 + pagetext = pagetext.split('\n')
172 + if endline == -1:
173 + sectiontext = u'\n'.join(pagetext[startline-1:])
174 + else:
175 + sectiontext = u'\n'.join(pagetext[startline-1:endline])
176 +
177 + return sectiontext
178 +
179 + # end of section-editing
180 +
181 class PageLock:
182 """
183 PageLock - Lock pages
184 --- MoinMoin/PageGraphicalEditor.py.orig Sun Sep 17 11:17:07 2006
185 +++ MoinMoin/PageGraphicalEditor.py Tue Feb 13 16:48:00 2007
186 @@ -64,6 +64,29 @@
187 preview = kw.get('preview', None)
188 staytop = kw.get('staytop', 0)
189
190 + # for section editing
191 + issectionedit = kw.get('issectionedit', 1)
192 + pagetext = kw.get('pagetext', None)
193 + startline = int(form.get('startline', ['0'])[0])
194 + endline = int(form.get('endline', ['0'])[0])
195 + srev = int(form.get('srev', ['0'])[0])
196 +
197 + if startline or endline:
198 + if not startline:
199 + startline = 1
200 +
201 + if not endline:
202 + endline = -1
203 + else:
204 + issectionedit = 0
205 +
206 + if issectionedit:
207 + # need to add config
208 + self._allow_section_edit = self.cfg.allow_section_edit
209 + # self._allow_section_edit = 1
210 +
211 + # end of section editing
212 +
213 # check edit permissions
214 if not self.request.user.may.write(self.page_name):
215 msg = _('You are not allowed to edit this page.')
216 @@ -94,6 +117,11 @@
217 title = _('Edit "%(pagename)s"')
218 else:
219 title = _('Preview of "%(pagename)s"')
220 + #self.set_raw_body(preview, modified=1)
221 +
222 + if issectionedit and pagetext is not None:
223 + self.set_raw_body(pagetext, modified=1)
224 + else:
225 self.set_raw_body(preview, modified=1)
226
227 # send header stuff
228 @@ -134,9 +162,20 @@
229 # We don't show preview when in conflict
230 preview = None
231
232 + # no section-editing any more
233 + if issectionedit:
234 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
235 + issectionedit = 0
236 +
237 elif self.exists():
238 # revision of existing page
239 rev = self.current_rev()
240 +
241 + if issectionedit and preview is None:
242 + if not (srev and srev == rev):
243 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
244 + issectionedit = 0
245 +
246 else:
247 # page creation
248 rev = 0
249 @@ -195,6 +234,13 @@
250 if not raw_body:
251 raw_body = _('Describe %s here.') % (self.page_name,)
252
253 + elif issectionedit:
254 + # for section editing
255 + if pagetext is not None:
256 + raw_body = preview
257 + else:
258 + raw_body = self.fetchsection(raw_body, startline, endline)
259 +
260 # send form
261 self.request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
262 self.request.getScriptname(),
263 @@ -214,6 +260,11 @@
264 # Create and send a ticket, so we can check the POST
265 self.request.write('<input type="hidden" name="ticket" value="%s">' % wikiutil.createTicket(self.request))
266
267 + # Send section startline and endline for section-editing
268 + if issectionedit:
269 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
270 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
271 +
272 # Save backto in a hidden input
273 backto = form.get('backto', [None])[0]
274 if backto:
275 @@ -337,6 +388,10 @@
276
277 badwords_re = None
278 if preview is not None:
279 +
280 + if issectionedit:
281 + self.set_raw_body(preview)
282 +
283 if SpellCheck and (
284 form.has_key('button_spellcheck') or
285 form.has_key('button_newwords')):
286 @@ -351,6 +406,13 @@
287 content_id = 'previewbelow'
288 else:
289 content_id = 'preview'
290 + #self.send_page(self.request, content_id=content_id, content_only=1,
291 + # hilite_re=badwords_re)
292 +
293 + if issectionedit:
294 + self.send_page(self.request, content_id=content_id, content_only=1,
295 + hilite_re=badwords_re, do_cache=False)
296 + else:
297 self.send_page(self.request, content_id=content_id, content_only=1,
298 hilite_re=badwords_re)
299
300 --- MoinMoin/multiconfig.py.orig Sun Sep 17 15:37:04 2006
301 +++ MoinMoin/multiconfig.py Tue Feb 13 16:48:00 2007
302 @@ -342,6 +342,7 @@
303 show_login = 1
304 show_names = True
305 show_section_numbers = 0
306 + allow_section_edit = 1
307 show_timings = 0
308 show_version = 0
309 siteid = 'default'
310 --- MoinMoin/formatter/text_html.py.orig Thu May 11 12:24:00 2006
311 +++ MoinMoin/formatter/text_html.py Tue Feb 13 16:48:00 2007
312 @@ -197,6 +197,16 @@
313 self.request = request
314 self.cfg = request.cfg
315
316 + # for section editing
317 + self._allow_section_edit = None
318 + if not hasattr(request, 'sectionindex'):
319 + self.request.sectionindex = 0
320 +
321 + self.sectionstack = []
322 + self.sectionpool = {}
323 + self.sectionlastdepth = 0
324 + self.lineno = 0
325 +
326 if not hasattr(request, '_fmt_hd_counters'):
327 request._fmt_hd_counters = []
328
329 @@ -584,6 +594,7 @@
330 return '<span class="anchor" id="%s"></span>' % wikiutil.escape(id, 1)
331
332 def line_anchordef(self, lineno):
333 + self.lineno = lineno
334 if line_anchors:
335 return self.anchordef("line-%d" % lineno)
336 else:
337 @@ -1175,6 +1186,21 @@
338 if not self._base_depth:
339 self._base_depth = depth
340
341 + # section editing configuration
342 + if self._allow_section_edit is None:
343 + # need to add config
344 + self._allow_section_edit = self.cfg.allow_section_edit
345 + # self._allow_section_edit = 1
346 + sectionediting = self.request.getPragma('section-edit', '').lower()
347 + if sectionediting in ['off']:
348 + self._allow_section_edit = 0
349 + elif sectionediting in ['on']:
350 + self._allow_section_edit = 1
351 +
352 + if self._allow_section_edit:
353 + if not self.request.user.may.write(self.page.page_name):
354 + self._allow_section_edit = 0
355 +
356 count_depth = max(depth - (self._base_depth - 1), 1)
357
358 # check numbering, possibly changing the default
359 @@ -1193,7 +1219,35 @@
360
361 # closing tag, with empty line after, to make source more readable
362 if not on:
363 - return self._close('h%d' % heading_depth) + '\n'
364 + # section-editing
365 + #return self._close('h%d' % heading_depth) + '\n'
366 + result = self._close('h%d' % heading_depth) + '\n'
367 +
368 + sectionscript = ''
369 + if self._allow_section_edit:
370 +
371 + self.request.sectionindex += 1
372 + sectionindex = self.request.sectionindex
373 + sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
374 +
375 + section_attr = 'sectionedit%d' % sectionindex
376 +
377 + backto = u''
378 + if self._is_included and hasattr(self.request, "_Include_backto"):
379 + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
380 +
381 + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
382 + srev = self.page.current_rev()
383 + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
384 +
385 + result = ('%s%s%s%s' %
386 + (self.url(1, querystring, unescaped=1, title='Edit this section', id=section_attr),
387 + self.icon('edit'),
388 + self.url(0),
389 + result))
390 +
391 + return ' %s%s' % (result, sectionscript)
392 + # end of section-editing
393
394 # create section number
395 number = ''
396 @@ -1325,6 +1379,55 @@
397 allowed_attrs=self._allowed_table_attrs['row'],
398 **kw)
399 return self._close(tag) + '\n'
400 +
401 + # section-editing
402 +
403 + def savesectioninfor(self, index, depth, lineno, save=1):
404 + # store section information
405 + section = {}
406 + sectionscriptlist = []
407 + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
408 + scriptresult = ''
409 +
410 + lastdepth = self.sectionlastdepth
411 + sectionindex = index
412 +
413 + if lastdepth >= depth:
414 + while 1:
415 + if len(self.sectionstack):
416 + lastsection = self.sectionstack.pop()
417 + lastdepth = lastsection['depth']
418 + if lastdepth >= depth:
419 + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
420 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
421 + else:
422 + self.sectionstack.append(lastsection)
423 + break
424 + else:
425 + break
426 +
427 + if save:
428 + section['index'] = sectionindex
429 + section['startlineno'] = lineno
430 + section['depth'] = depth
431 + section['endlineno'] = -1
432 + self.sectionlastdepth = depth
433 + self.sectionpool[sectionindex] = section
434 + self.sectionstack.append(section)
435 +
436 + if len(sectionscriptlist) > 0:
437 +
438 + scriptresult = u"""
439 +<script type="text/javascript">
440 +<!--
441 +%s
442 +//-->
443 +</script>
444 +""" % u'\n'.join(sectionscriptlist)
445 +
446 + return scriptresult
447 +
448 + # end of section-editing
449
450 def table_cell(self, on, attrs=None, **kw):
451 tag = 'td'
452 --- MoinMoin/wikiaction.py.orig Sun Sep 17 15:37:26 2006
453 +++ MoinMoin/wikiaction.py Tue Feb 13 16:49:49 2007
454 @@ -606,6 +606,28 @@
455 if not cancelled:
456 raise
457
458 + # section editing
459 + startline = int(request.form.get('startline', ['0'])[0])
460 + endline = int(request.form.get('endline', ['0'])[0])
461 +
462 + if startline or endline:
463 + issectionedit = 1
464 +
465 + if not startline:
466 + startline = 1
467 +
468 + if not endline:
469 + endline = -1
470 +
471 + else:
472 + issectionedit = 0
473 +
474 + if issectionedit:
475 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
476 + sectiontext = savetext
477 + savetext = mergesection(pg.get_raw_body(), savetext, startline, endline)
478 +
479 +
480 if cancelled:
481 pg.sendCancel(savetext or "", rev)
482 return
483 @@ -647,11 +669,21 @@
484 if (request.form.has_key('button_preview') or
485 request.form.has_key('button_spellcheck') or
486 request.form.has_key('button_newwords')):
487 - pg.sendEditor(preview=savetext, comment=comment)
488 + #pg.sendEditor(preview=savetext, comment=comment)
489 +
490 + if issectionedit:
491 + pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext)
492 + else:
493 + pg.sendEditor(preview=savetext, comment=comment)
494
495 # Preview with mode switch
496 elif request.form.has_key('button_switch'):
497 - pg.sendEditor(preview=savetext, comment=comment, staytop=1)
498 + #pg.sendEditor(preview=savetext, comment=comment, staytop=1)
499 +
500 + if issectionedit:
501 + pg.sendEditor(preview=sectiontext, comment=comment, staytop=1, pagetext=savetext)
502 + else:
503 + pg.sendEditor(preview=savetext, comment=comment, staytop=1)
504
505 # Save new text
506 else:
507 @@ -672,7 +704,13 @@
508 querystr='action=diff&rev=%d' % rev)
509 }
510 # We don't send preview when we do merge conflict
511 - pg.sendEditor(msg=conflict_msg, comment=comment)
512 + #pg.sendEditor(msg=conflict_msg, comment=comment)
513 +
514 + if issectionedit:
515 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
516 +
517 + pg.sendEditor(msg=conflict_msg, comment=comment, issectionedit=0)
518 +
519 return
520 else:
521 savemsg = conflict_msg
522 @@ -915,4 +953,17 @@
523 handler = globals().get('do_' + action)
524
525 return handler
526 +
527 +def mergesection(pagetext, newsectiontext, startline, endline):
528 +
529 + pagetext = pagetext.split('\n')
530 +
531 + prevtext = u'%s\n' % u'\n'.join(pagetext[:startline-1])
532 + if endline == -1:
533 + nexttext = ''
534 + else:
535 + nexttext = u'\n%s' % u'\n'.join(pagetext[endline:])
536 +
537 + return u'%s%s%s' % (prevtext, newsectiontext, nexttext)
538 +
539
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.