Attachment 'PageEditor.patch'
Download 1 --- PageEditor-1.5b2.py 2005-11-06 06:28:50.000000000 +0900
2 +++ PageEditor.py 2005-11-24 10:35:22.009242300 +0900
3 @@ -135,7 +135,28 @@
4 edit_lock_message = None
5 preview = kw.get('preview', None)
6 staytop = kw.get('staytop', 0)
7 +
8 + # for section editing
9 + issectionedit = kw.get('issectionedit', 1)
10 + pagetext = kw.get('pagetext', None)
11 + startline = int(form.get('startline', ['0'])[0])
12 + endline = int(form.get('endline', ['0'])[0])
13 + srev = int(form.get('srev', ['0'])[0])
14 +
15 + if startline or endline:
16 + if not startline:
17 + startline = 1
18 +
19 + if not endline:
20 + endline = -1
21 + else:
22 + issectionedit = 0
23
24 + if issectionedit:
25 + # need to add config
26 + self._allow_section_edit = self.cfg.allow_section_edit
27 + # self._allow_section_edit = 1
28 +
29 from MoinMoin.formatter.text_html import Formatter
30 self.request.formatter = Formatter(self.request, store_pagelinks=1)
31
32 @@ -174,7 +195,10 @@
33 title = _('Edit "%(pagename)s"')
34 else:
35 title = _('Preview of "%(pagename)s"')
36 - self.set_raw_body(preview, modified=1)
37 + if issectionedit and pagetext is not None:
38 + self.set_raw_body(pagetext, modified=1)
39 + else:
40 + self.set_raw_body(preview, modified=1)
41
42 # send header stuff
43 lock_timeout = self.lock.timeout / 60
44 @@ -214,9 +238,19 @@
45 # We don't show preview when in conflict
46 preview = None
47
48 + # no section-editing any more
49 + if issectionedit:
50 + conflict_msg = u'%s %s' % (conflict_msg, _('Section editing is canceled.'))
51 + issectionedit = 0
52 +
53 elif self.exists():
54 # revision of existing page
55 rev = self.current_rev()
56 +
57 + if issectionedit and preview is None:
58 + if not (srev and srev == rev):
59 + conflict_msg = u'%s %s' % (_('Section editing is canceled.'), _('Someone else updated this page. You are editing the updated revision.'))
60 + issectionedit = 0
61 else:
62 # page creation
63 rev = 0
64 @@ -273,6 +307,12 @@
65 # Generate default content for new pages
66 if not raw_body:
67 raw_body = _('Describe %s here.') % (self.page_name,)
68 + elif issectionedit:
69 + # for section editing
70 + if pagetext is not None:
71 + raw_body = preview
72 + else:
73 + raw_body = self.fetchsection(raw_body, startline, endline)
74
75 # send form
76 self.request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
77 @@ -290,6 +330,11 @@
78 # Send revision of the page our edit is based on
79 self.request.write('<input type="hidden" name="rev" value="%d">' % (rev,))
80
81 + # Send section startline and endline for section-editing
82 + if issectionedit:
83 + self.request.write('<input type="hidden" name="startline" value="%d">' % startline)
84 + self.request.write('<input type="hidden" name="endline" value="%d">' % endline)
85 +
86 # Save backto in a hidden input
87 backto = form.get('backto', [None])[0]
88 if backto:
89 @@ -391,6 +436,9 @@
90
91 badwords_re = None
92 if preview is not None:
93 + if issectionedit:
94 + self.set_raw_body(preview)
95 +
96 if SpellCheck and (
97 form.has_key('button_spellcheck') or
98 form.has_key('button_newwords')):
99 @@ -414,7 +462,12 @@
100 content_id = 'previewbelow'
101 else:
102 content_id = 'preview'
103 - self.send_page(self.request, content_id=content_id, content_only=1,
104 +
105 + if issectionedit:
106 + self.send_page(self.request, content_id=content_id, content_only=1,
107 + hilite_re=badwords_re, do_cache=False)
108 + else:
109 + self.send_page(self.request, content_id=content_id, content_only=1,
110 hilite_re=badwords_re)
111
112 self.request.write(self.request.formatter.endContent())
113 @@ -860,7 +913,7 @@
114 if newtext==saved_page.get_raw_body():
115 msg = _("You already saved this page!")
116 return msg
117 -
118 +
119 msg = _("""Sorry, someone else saved the page while you edited it.
120
121 Please do the following: Use the back button of your browser, and cut&paste
122 @@ -926,7 +979,17 @@
123 self.lock.release(force=not msg) # XXX does "not msg" make any sense?
124
125 return msg
126 -
127 +
128 + def fetchsection(self, pagetext, startline, endline):
129 +
130 + pagetext = pagetext.split('\n')
131 + if endline == -1:
132 + sectiontext = u'\n'.join(pagetext[startline-1:])
133 + else:
134 + sectiontext = u'\n'.join(pagetext[startline-1:endline])
135 +
136 + return sectiontext
137 +
138
139 class PageLock:
140 """
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.