Attachment 'patch-1.5b2.txt'
Download 1 diff -ur 1.5b2/Include.py modified/Include.py
2 --- 1.5b2/Include.py 2005-10-28 03:46:38.000000000 +0900
3 +++ modified/Include.py 2005-11-24 03:09:42.649867300 +0900
4 @@ -218,7 +218,7 @@
5 request.redirect(strfile)
6 try:
7 cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name))
8 - inc_page.send_page(request, content_only=1, content_id=cid)
9 + inc_page.send_page(request, content_only=1, content_id=cid, do_cache=False)
10 result.append(strfile.getvalue())
11 finally:
12 request.redirect()
13 diff -ur 1.5b2/multiconfig.py modified/multiconfig.py
14 --- 1.5b2/multiconfig.py 2005-10-30 20:22:58.000000000 +0900
15 +++ modified/multiconfig.py 2005-11-23 02:56:50.156250000 +0900
16 @@ -290,6 +290,7 @@
17 show_hosts = 1
18 show_interwiki = 1
19 show_section_numbers = 0
20 + allow_section_edit = 1
21 show_timings = 0
22 show_version = 0
23 siteid = 'default'
24 diff -ur 1.5b2/PageEditor.py modified/PageEditor.py
25 --- 1.5b2/PageEditor.py 2005-11-06 06:28:50.000000000 +0900
26 +++ modified/PageEditor.py 2005-11-24 10:35:22.009242300 +0900
27 @@ -135,7 +135,28 @@
28 edit_lock_message = None
29 preview = kw.get('preview', None)
30 staytop = kw.get('staytop', 0)
31 +
32 + # for section editing
33 + issectionedit = kw.get('issectionedit', 1)
34 + pagetext = kw.get('pagetext', None)
35 + startline = int(form.get('startline', ['0'])[0])
36 + endline = int(form.get('endline', ['0'])[0])
37 + srev = int(form.get('srev', ['0'])[0])
38 +
39 + if startline or endline:
40 + if not startline:
41 + startline = 1
42 +
43 + if not endline:
44 + endline = -1
45 + else:
46 + issectionedit = 0
47
48 + if issectionedit:
49 + # need to add config
50 + self._allow_section_edit = self.cfg.allow_section_edit
51 + # self._allow_section_edit = 1
52 +
53 from MoinMoin.formatter.text_html import Formatter
54 self.request.formatter = Formatter(self.request, store_pagelinks=1)
55
56 @@ -174,7 +195,10 @@
57 title = _('Edit "%(pagename)s"')
58 else:
59 title = _('Preview of "%(pagename)s"')
60 - self.set_raw_body(preview, modified=1)
61 + if issectionedit and pagetext is not None:
62 + self.set_raw_body(pagetext, modified=1)
63 + else:
64 + self.set_raw_body(preview, modified=1)
65
66 # send header stuff
67 lock_timeout = self.lock.timeout / 60
68 @@ -214,9 +238,19 @@
69 # We don't show preview when in conflict
70 preview = None
71
72 + # no section-editing any more
73 + if issectionedit:
74 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
75 + issectionedit = 0
76 +
77 elif self.exists():
78 # revision of existing page
79 rev = self.current_rev()
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 else:
86 # page creation
87 rev = 0
88 @@ -273,6 +307,12 @@
89 # Generate default content for new pages
90 if not raw_body:
91 raw_body = _('Describe %s here.') % (self.page_name,)
92 + elif issectionedit:
93 + # for section editing
94 + if pagetext is not None:
95 + raw_body = preview
96 + else:
97 + raw_body = self.fetchsection(raw_body, startline, endline)
98
99 # send form
100 self.request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
101 @@ -290,6 +330,11 @@
102 # Send revision of the page our edit is based on
103 self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
104
105 + # Send section startline and endline for section-editing
106 + if issectionedit:
107 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
108 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
109 +
110 # Save backto in a hidden input
111 backto = form.get('backto', [None])[0]
112 if backto:
113 @@ -391,6 +436,9 @@
114
115 badwords_re = None
116 if preview is not None:
117 + if issectionedit:
118 + self.set_raw_body(preview)
119 +
120 if SpellCheck and (
121 form.has_key('button_spellcheck') or
122 form.has_key('button_newwords')):
123 @@ -414,7 +462,12 @@
124 content_id = 'previewbelow'
125 else:
126 content_id = 'preview'
127 - self.send_page(self.request, content_id=content_id, content_only=1,
128 +
129 + if issectionedit:
130 + self.send_page(self.request, content_id=content_id, content_only=1,
131 + hilite_re=badwords_re, do_cache=False)
132 + else:
133 + self.send_page(self.request, content_id=content_id, content_only=1,
134 hilite_re=badwords_re)
135
136 self.request.write(self.request.formatter.endContent())
137 @@ -860,7 +913,7 @@
138 if newtext==saved_page.get_raw_body():
139 msg = _("You already saved this page!")
140 return msg
141 -
142 +
143 msg = _("""Sorry, someone else saved the page while you edited it.
144
145 Please do the following: Use the back button of your browser, and cut&paste
146 @@ -926,7 +979,17 @@
147 self.lock.release(force=not msg) # XXX does "not msg" make any sense?
148
149 return msg
150 -
151 +
152 + def fetchsection(self, pagetext, startline, endline):
153 +
154 + pagetext = pagetext.split('\n')
155 + if endline == -1:
156 + sectiontext = u'\n'.join(pagetext[startline-1:])
157 + else:
158 + sectiontext = u'\n'.join(pagetext[startline-1:endline])
159 +
160 + return sectiontext
161 +
162
163 class PageLock:
164 """
165 diff -ur 1.5b2/PageGraphicalEditor.py modified/PageGraphicalEditor.py
166 --- 1.5b2/PageGraphicalEditor.py 2005-11-06 06:35:56.000000000 +0900
167 +++ modified/PageGraphicalEditor.py 2005-11-24 09:50:32.149867300 +0900
168 @@ -63,6 +63,27 @@
169 edit_lock_message = None
170 preview = kw.get('preview', None)
171 staytop = kw.get('staytop', 0)
172 +
173 + # for section editing
174 + issectionedit = kw.get('issectionedit', 1)
175 + pagetext = kw.get('pagetext', None)
176 + startline = int(form.get('startline', ['0'])[0])
177 + endline = int(form.get('endline', ['0'])[0])
178 + srev = int(form.get('srev', ['0'])[0])
179 +
180 + if startline or endline:
181 + if not startline:
182 + startline = 1
183 +
184 + if not endline:
185 + endline = -1
186 + else:
187 + issectionedit = 0
188 +
189 + if issectionedit:
190 + # need to add config
191 + self._allow_section_edit = self.cfg.allow_section_edit
192 + # self._allow_section_edit = 1
193
194 # check edit permissions
195 if not self.request.user.may.write(self.page_name):
196 @@ -94,7 +115,10 @@
197 title = _('Edit "%(pagename)s"')
198 else:
199 title = _('Preview of "%(pagename)s"')
200 - self.set_raw_body(preview, modified=1)
201 + if issectionedit and pagetext is not None:
202 + self.set_raw_body(pagetext, modified=1)
203 + else:
204 + self.set_raw_body(preview, modified=1)
205
206 # send header stuff
207 lock_timeout = self.lock.timeout / 60
208 @@ -134,9 +158,19 @@
209 # We don't show preview when in conflict
210 preview = None
211
212 + # no section-editing any more
213 + if issectionedit:
214 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
215 + issectionedit = 0
216 +
217 elif self.exists():
218 # revision of existing page
219 rev = self.current_rev()
220 +
221 + if issectionedit and preview is None:
222 + if not (srev and srev == rev):
223 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
224 + issectionedit = 0
225 else:
226 # page creation
227 rev = 0
228 @@ -193,13 +227,19 @@
229 # Generate default content for new pages
230 if not raw_body:
231 raw_body = _('Describe %s here.') % (self.page_name,)
232 -
233 + elif issectionedit:
234 + # for section editing
235 + if pagetext is not None:
236 + raw_body = preview
237 + else:
238 + raw_body = self.fetchsection(raw_body, startline, endline)
239 +
240 # send form
241 self.request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
242 self.request.getScriptname(),
243 wikiutil.quoteWikinameURL(self.page_name),
244 ))
245 -
246 +
247 # yet another weird workaround for broken IE6 (it expands the text
248 # editor area to the right after you begin to type...). IE sucks...
249 # http://fplanque.net/2003/Articles/iecsstextarea/
250 @@ -210,6 +250,11 @@
251 # Send revision of the page our edit is based on
252 self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
253
254 + # Send section startline and endline for section-editing
255 + if issectionedit:
256 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
257 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
258 +
259 # Save backto in a hidden input
260 backto = form.get('backto', [None])[0]
261 if backto:
262 @@ -328,9 +373,12 @@
263 })
264
265 self.request.write("</p>")
266 -
267 +
268 badwords_re = None
269 if preview is not None:
270 + if issectionedit:
271 + self.set_raw_body(preview)
272 +
273 if SpellCheck and (
274 form.has_key('button_spellcheck') or
275 form.has_key('button_newwords')):
276 @@ -345,10 +393,16 @@
277 content_id = 'previewbelow'
278 else:
279 content_id = 'preview'
280 - self.send_page(self.request, content_id=content_id, content_only=1,
281 +
282 + if issectionedit:
283 + self.send_page(self.request, content_id=content_id, content_only=1,
284 + hilite_re=badwords_re, do_cache=False)
285 + else:
286 + self.send_page(self.request, content_id=content_id, content_only=1,
287 hilite_re=badwords_re)
288
289 self.request.write(self.request.formatter.endContent()) # end content div
290 self.request.theme.emit_custom_html(self.cfg.page_footer1)
291 self.request.theme.emit_custom_html(self.cfg.page_footer2)
292
293 +
294 diff -ur 1.5b2/text_html.py modified/text_html.py
295 --- 1.5b2/text_html.py 2005-10-31 08:39:10.000000000 +0900
296 +++ modified/text_html.py 2005-11-24 11:11:23.384242300 +0900
297 @@ -39,6 +39,16 @@
298 self._is_included = kw.get('is_included',False)
299 self.request = request
300 self.cfg = request.cfg
301 +
302 + # for section editing
303 + self._allow_section_edit = None
304 + if not hasattr(request, 'sectionindex'):
305 + request.sectionindex = 0
306 +
307 + self.sectionstack = []
308 + self.sectionpool = {}
309 + self.sectionlastdepth = 0
310 + self.lineno = 0
311
312 if not hasattr(request, '_fmt_hd_counters'):
313 request._fmt_hd_counters = []
314 @@ -285,6 +295,7 @@
315 return '<a id="%s"></a>' % (id, ) # do not add a \n here, it breaks pre sections with line_anchordef
316
317 def line_anchordef(self, lineno):
318 + self.lineno = lineno
319 return self.anchordef("line-%d" % lineno)
320
321 def anchorlink(self, on, name='', id=None):
322 @@ -689,6 +700,21 @@
323 if not self._base_depth:
324 self._base_depth = depth
325
326 + # section editing configuration
327 + if self._allow_section_edit is None:
328 + # need to add config
329 + self._allow_section_edit = self.cfg.allow_section_edit
330 + # self._allow_section_edit = 1
331 + sectionediting = self.request.getPragma('section-edit', '').lower()
332 + if sectionediting in ['off']:
333 + self._allow_section_edit = 0
334 + elif sectionediting in ['on']:
335 + self._allow_section_edit = 1
336 +
337 + if self._allow_section_edit:
338 + if not self.request.user.may.write(self.page.page_name):
339 + self._allow_section_edit = 0
340 +
341 count_depth = max(depth - (self._base_depth - 1), 1)
342
343 # check numbering, possibly changing the default
344 @@ -707,7 +733,32 @@
345
346 # closing tag, with empty line after, to make source more readable
347 if not on:
348 - return self.close('h%d' % heading_depth) + '\n'
349 + result = self.close('h%d' % heading_depth)
350 +
351 + sectionscript = ''
352 + if self._allow_section_edit:
353 +
354 + self.request.sectionindex += 1
355 + sectionindex = self.request.sectionindex
356 + sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
357 +
358 + attr = 'id="sectionedit%d"' % sectionindex
359 +
360 + backto = u''
361 + if self._is_included and hasattr(self.request, "_Include_backto"):
362 + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
363 +
364 + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
365 + srev = self.page.current_rev()
366 + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
367 +
368 + result = ('%s%s%s%s' %
369 + (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr),
370 + self.icon('edit'),
371 + self.url(0),
372 + result))
373 +
374 + return ' %s%s' % (result, sectionscript)
375
376 # create section number
377 number = ''
378 @@ -840,6 +891,53 @@
379 return self.open(tag, newline=1, attr=attrs)
380 return self.close(tag)
381
382 + def savesectioninfor(self, index, depth, lineno, save=1):
383 + # store section information
384 + section = {}
385 + sectionscriptlist = []
386 + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
387 + scriptresult = ''
388 +
389 + lastdepth = self.sectionlastdepth
390 + sectionindex = index
391 +
392 + if lastdepth >= depth:
393 + while 1:
394 + if len(self.sectionstack):
395 + lastsection = self.sectionstack.pop()
396 + lastdepth = lastsection['depth']
397 + if lastdepth >= depth:
398 + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
399 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
400 + else:
401 + self.sectionstack.append(lastsection)
402 + break
403 + else:
404 + break
405 +
406 + if save:
407 + section['index'] = sectionindex
408 + section['startlineno'] = lineno
409 + section['depth'] = depth
410 + section['endlineno'] = -1
411 + self.sectionlastdepth = depth
412 + self.sectionpool[sectionindex] = section
413 + self.sectionstack.append(section)
414 +
415 + if len(sectionscriptlist) > 0:
416 +
417 + scriptresult = u"""
418 +<script type="text/javascript">
419 +<!--
420 +%s
421 +//-->
422 +</script>
423 +""" % u'\n'.join(sectionscriptlist)
424 +
425 + return scriptresult
426 +
427 +
428 +
429 def escapedText(self, text):
430 return wikiutil.escape(text)
431
432 diff -ur 1.5b2/wikiaction.py modified/wikiaction.py
433 --- 1.5b2/wikiaction.py 2005-10-23 21:50:50.000000000 +0900
434 +++ modified/wikiaction.py 2005-11-24 09:47:28.196742300 +0900
435 @@ -563,10 +563,6 @@
436 from MoinMoin.PageEditor import PageEditor
437 pg = PageEditor(request, pagename)
438
439 - # Edit was canceled
440 - if request.form.has_key('button_cancel'):
441 - pg.sendCancel(savetext, rev)
442 - return
443
444 # is invoked without savetext start editing
445 if savetext is None:
446 @@ -577,11 +573,39 @@
447 if lasteditor == 'gui':
448 from MoinMoin.converter.text_html_text_x_moin import convert
449 savetext = convert(request, pagename, savetext) # XXX error handling
450 +
451 + # section editing
452 + startline = int(request.form.get('startline', ['0'])[0])
453 + endline = int(request.form.get('endline', ['0'])[0])
454 +
455 + if startline or endline:
456 + issectionedit = 1
457 +
458 + if not startline:
459 + startline = 1
460 +
461 + if not endline:
462 + endline = -1
463 +
464 + else:
465 + issectionedit = 0
466 +
467 + if issectionedit:
468 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
469 + sectiontext = savetext
470 + savetext = mergesection(pg.get_raw_body(), savetext, startline, endline)
471 +
472 +
473 + # Edit was canceled
474 + if request.form.has_key('button_cancel'):
475 + pg.sendCancel(savetext, rev)
476 + return
477
478 # IMPORTANT: normalize text from the form. This should be done in
479 # one place before we manipulate the text.
480 - savetext = pg.normalizeText(savetext, stripspaces=rstrip)
481 -
482 + if not issectionedit:
483 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
484 +
485 # Add category
486
487 # TODO: this code does not work with extended links, and is doing
488 @@ -630,11 +654,17 @@
489 if (request.form.has_key('button_preview') or
490 request.form.has_key('button_spellcheck') or
491 request.form.has_key('button_newwords')):
492 - pg.sendEditor(preview=savetext, comment=comment)
493 + if issectionedit:
494 + pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext)
495 + else:
496 + pg.sendEditor(preview=savetext, comment=comment)
497
498 # Preview with mode switch
499 elif request.form.has_key('button_switch'):
500 - pg.sendEditor(preview=savetext, comment=comment, staytop=1)
501 + if issectionedit:
502 + pg.sendEditor(preview=sectiontext, comment=comment, staytop=1, pagetext=savetext)
503 + else:
504 + pg.sendEditor(preview=savetext, comment=comment, staytop=1)
505
506 # Save new text
507 else:
508 @@ -655,7 +685,10 @@
509 querystr='action=diff&rev=%d' % rev)
510 }
511 # We don't send preview when we do merge conflict
512 - pg.sendEditor(msg=conflict_msg, comment=comment)
513 + if issectionedit:
514 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
515 +
516 + pg.sendEditor(msg=conflict_msg, comment=comment, issectionedit=0)
517 return
518 else:
519 savemsg = conflict_msg
520 @@ -949,6 +982,15 @@
521
522 return handler
523
524 -
525 -
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)
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.