Attachment 'patch-1.35.txt'
Download 1 diff -ur 1.35/Include.py modified/Include.py
2 --- 1.35/Include.py 2005-06-27 00:43:06.000000000 +0900
3 +++ modified/Include.py 2005-11-29 17:44:47.015625000 +0900
4 @@ -216,7 +216,7 @@
5 request.redirect(strfile)
6 try:
7 cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameFS(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.35/multiconfig.py modified/multiconfig.py
14 --- 1.35/multiconfig.py 2005-07-31 00:58:52.000000000 +0900
15 +++ modified/multiconfig.py 2005-11-29 17:40:11.609375000 +0900
16 @@ -247,6 +252,7 @@
17 shared_intermap = None # can be string or list of strings (filenames)
18 show_hosts = 1
19 show_section_numbers = 1
20 + allow_section_edit = 1
21 show_timings = 0
22 show_version = 0
23 siteid = 'default'
24 diff -ur 1.35/PageEditor.py modified/PageEditor.py
25 --- 1.35/PageEditor.py 2005-07-28 00:51:40.000000000 +0900
26 +++ modified/PageEditor.py 2005-11-29 17:43:39.000000000 +0900
27 @@ -176,6 +176,27 @@
28 preview = kw.get('preview', None)
29 emit_anchor = not kw.get('staytop', 0)
30
31 + # for section editing
32 + issectionedit = kw.get('issectionedit', 1)
33 + pagetext = kw.get('pagetext', None)
34 + startline = int(form.get('startline', ['0'])[0])
35 + endline = int(form.get('endline', ['0'])[0])
36 + srev = int(form.get('srev', ['0'])[0])
37 +
38 + if startline or endline:
39 + if not startline:
40 + startline = 1
41 +
42 + if not endline:
43 + endline = -1
44 + else:
45 + issectionedit = 0
46 +
47 + if issectionedit:
48 + # need to add config
49 + self._allow_section_edit = self.cfg.allow_section_edit
50 + # self._allow_section_edit = 1
51 +
52 from MoinMoin.formatter.text_html import Formatter
53 self.request.formatter = Formatter(self.request, store_pagelinks=1)
54
55 @@ -214,7 +235,11 @@
56 title = _('Edit "%(pagename)s"')
57 else:
58 title = _('Preview of "%(pagename)s"')
59 - self.set_raw_body(preview, modified=1)
60 +
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 @@ -254,9 +279,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 + if issectionedit and preview is None:
81 + if not (srev and srev == rev):
82 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
83 + issectionedit = 0
84 +
85 else:
86 # page creation
87 rev = 0
88 @@ -341,10 +392,21 @@
89 # Generate default content for new pages
90 if not raw_body:
91 raw_body = _('Describe %s here.') % (self.page_name,)
92 -
93 + elif issectionedit:
94 + # for section editing
95 + if pagetext is not None:
96 + raw_body = preview
97 + else:
98 + raw_body = self.fetchsection(raw_body, startline, endline)
99 +
100 # Send revision of the page our edit is based on
101 self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
102 -
103 +
104 + # Send section startline and endline for section-editing
105 + if issectionedit:
106 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
107 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
108 +
109 # Add textarea with page text
110
111 # TODO: currently self.language is None at this point. We have
112 @@ -425,6 +512,8 @@
113
114 badwords_re = None
115 if preview is not None:
116 + if issectionedit:
117 + self.set_raw_body(preview)
118 if SpellCheck and (
119 form.has_key('button_spellcheck') or
120 form.has_key('button_newwords')):
121 @@ -442,7 +531,11 @@
122 + '</dl>')
123
124 if preview is not None:
125 - self.send_page(self.request, content_id='preview', content_only=1,
126 + if issectionedit:
127 + self.send_page(self.request, content_id='preview', content_only=1,
128 + hilite_re=badwords_re, do_cache=False)
129 + else:
130 + self.send_page(self.request, content_id='preview', content_only=1,
131 hilite_re=badwords_re)
132
133 self.request.write(self.request.formatter.endContent())
134 @@ -936,6 +1029,16 @@
135 self.lock.release(force=not msg) # XXX does "not msg" make any sense?
136
137 return msg
138 +
139 + def fetchsection(self, pagetext, startline, endline):
140 +
141 + pagetext = pagetext.split('\n')
142 + if endline == -1:
143 + sectiontext = u'\n'.join(pagetext[startline-1:])
144 + else:
145 + sectiontext = u'\n'.join(pagetext[startline-1:endline])
146 +
147 + return sectiontext
148
149
150 class PageLock:
151 diff -ur 1.35/text_html.py modified/text_html.py
152 --- 1.35/text_html.py 2005-07-27 03:46:52.000000000 +0900
153 +++ modified/text_html.py 2005-11-29 17:47:00.718750000 +0900
154 @@ -38,7 +38,16 @@
155 self._is_included = kw.get('is_included',False)
156 self.request = request
157 self.cfg = request.cfg
158 -
159 +
160 + # for section editing
161 + self._allow_section_edit = None
162 + if not hasattr(request, 'sectionindex'):
163 + request.sectionindex = 0
164 +
165 + self.sectionstack = []
166 + self.sectionpool = {}
167 + self.sectionlastdepth = 0
168 +
169 if not hasattr(request, '_fmt_hd_counters'):
170 request._fmt_hd_counters = []
171
172 @@ -584,7 +593,22 @@
173 # remember depth of first heading, and adapt counting depth accordingly
174 if not self._base_depth:
175 self._base_depth = depth
176 -
177 +
178 + # section editing configuration
179 + if self._allow_section_edit is None:
180 + # need to add config
181 + self._allow_section_edit = self.cfg.allow_section_edit
182 + # self._allow_section_edit = 1
183 + sectionediting = self.request.getPragma('section-edit', '').lower()
184 + if sectionediting in ['off']:
185 + self._allow_section_edit = 0
186 + elif sectionediting in ['on']:
187 + self._allow_section_edit = 1
188 +
189 + if self._allow_section_edit:
190 + if not self.request.user.may.write(self.page.page_name):
191 + self._allow_section_edit = 0
192 +
193 count_depth = max(depth - (self._base_depth - 1), 1)
194
195 # check numbering, possibly changing the default
196 @@ -603,7 +627,34 @@
197
198 # closing tag, with empty line after, to make source more readable
199 if not on:
200 - return self.close('h%d' % heading_depth) + '\n'
201 + result = self.close('h%d' % heading_depth) + '\n'
202 +
203 + lineno = kw.get('lineno', 0)
204 +
205 + sectionscript = ''
206 + if self._allow_section_edit and lineno:
207 +
208 + self.request.sectionindex += 1
209 + sectionindex = self.request.sectionindex
210 + sectionscript = self.savesectioninfor(sectionindex, depth, lineno)
211 +
212 + attr = 'id="sectionedit%d"' % sectionindex
213 +
214 + backto = u''
215 + if self._is_included and hasattr(self.request, "_Include_backto"):
216 + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
217 +
218 + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
219 + srev = self.page.current_rev()
220 + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, lineno)
221 +
222 + result = ('%s%s%s%s' %
223 + (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr),
224 + self.icon('edit'),
225 + self.url(0),
226 + result))
227 +
228 + return ' %s%s' % (result, sectionscript)
229
230 # create section number
231 number = ''
232 @@ -734,6 +785,51 @@
233 return self.open(tag, newline=1, attr=attrs)
234 return self.close(tag)
235
236 + def savesectioninfor(self, index, depth, lineno, save=1):
237 + # store section information
238 + section = {}
239 + sectionscriptlist = []
240 + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
241 + scriptresult = ''
242 +
243 + lastdepth = self.sectionlastdepth
244 + sectionindex = index
245 +
246 + if lastdepth >= depth:
247 + while 1:
248 + if len(self.sectionstack):
249 + lastsection = self.sectionstack.pop()
250 + lastdepth = lastsection['depth']
251 + if lastdepth >= depth:
252 + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
253 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
254 + else:
255 + self.sectionstack.append(lastsection)
256 + break
257 + else:
258 + break
259 +
260 + if save:
261 + section['index'] = sectionindex
262 + section['startlineno'] = lineno
263 + section['depth'] = depth
264 + section['endlineno'] = -1
265 + self.sectionlastdepth = depth
266 + self.sectionpool[sectionindex] = section
267 + self.sectionstack.append(section)
268 +
269 + if len(sectionscriptlist) > 0:
270 +
271 + scriptresult = u"""
272 +<script type="text/javascript">
273 +<!--
274 +%s
275 +//-->
276 +</script>
277 +""" % u'\n'.join(sectionscriptlist)
278 +
279 + return scriptresult
280 +
281 def escapedText(self, text):
282 return wikiutil.escape(text)
283
284 diff -ur 1.35/wiki.py modified/wiki.py
285 --- 1.35/wiki.py 2005-07-30 21:51:12.000000000 +0900
286 +++ modified/wiki.py 2005-11-29 17:45:17.546875000 +0900
287 @@ -798,7 +798,7 @@
288 result += self.formatter.heading(1, depth, id="head-"+sha.new(pntt.encode(config.charset)).hexdigest()+unique_id)
289
290 return (result + self.formatter.text(title_text) +
291 - self.formatter.heading(0, depth))
292 + self.formatter.heading(0, depth, lineno=self.lineno))
293
294 def _processor_repl(self, word):
295 """Handle processed code displays."""
296 diff -ur 1.35/wikiaction.py modified/wikiaction.py
297 --- 1.35/wikiaction.py 2005-06-27 00:43:06.000000000 +0900
298 +++ modified/wikiaction.py 2005-11-29 17:48:42.875000000 +0900
299 @@ -541,10 +541,32 @@
300 category = request.form.get('category', [None])[0]
301 rstrip = int(request.form.get('rstrip', ['0'])[0])
302 trivial = int(request.form.get('trivial', ['0'])[0])
303 +
304 + # section editing
305 + startline = int(request.form.get('startline', ['0'])[0])
306 + endline = int(request.form.get('endline', ['0'])[0])
307 +
308 + if startline or endline:
309 + issectionedit = 1
310 +
311 + if not startline:
312 + startline = 1
313 +
314 + if not endline:
315 + endline = -1
316
317 + else:
318 + issectionedit = 0
319 +
320 + if issectionedit:
321 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
322 + sectiontext = savetext
323 + savetext = mergesection(pg.get_raw_body(), savetext, startline, endline)
324 +
325 # IMPORTANT: normalize text from the form. This should be done in
326 # one place before we manipulate the text.
327 - savetext = pg.normalizeText(savetext, stripspaces=rstrip)
328 + if not issectionedit:
329 + savetext = pg.normalizeText(savetext, stripspaces=rstrip)
330
331 # Add category
332
333 @@ -594,7 +616,10 @@
334 if (request.form.has_key('button_preview') or
335 request.form.has_key('button_spellcheck') or
336 request.form.has_key('button_newwords')):
337 - pg.sendEditor(preview=savetext, comment=comment)
338 + if issectionedit:
339 + pg.sendEditor(preview=sectiontext, comment=comment, pagetext=savetext)
340 + else:
341 + pg.sendEditor(preview=savetext, comment=comment)
342
343 # Edit was canceled
344 elif request.form.has_key('button_cancel'):
345 @@ -620,7 +645,10 @@
346 querystr='action=diff&rev=%d' % rev)
347 }
348 # We don't send preview when we do merge conflict
349 - pg.sendEditor(msg=conflict_msg, comment=comment)
350 + if issectionedit:
351 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
352 +
353 + pg.sendEditor(msg=conflict_msg, comment=comment, issectionedit=0)
354 return
355 else:
356 savemsg = conflict_msg
357 @@ -871,5 +899,16 @@
358 return handler
359
360
361 -
362 +def mergesection(pagetext, newsectiontext, startline, endline):
363 +
364 + pagetext = pagetext.split('\n')
365 +
366 + prevtext = u'%s\n' % u'\n'.join(pagetext[:startline-1])
367 + if endline == -1:
368 + nexttext = ''
369 + else:
370 + nexttext = u'\n%s' % u'\n'.join(pagetext[endline:])
371 +
372 + return u'%s%s%s' % (prevtext, newsectiontext, nexttext)
373 +
374
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.