Attachment 'text_html.patch'
Download 1 --- text_html-1.5b2.py 2005-10-31 08:39:10.000000000 +0900
2 +++ text_html.py 2005-11-24 11:11:23.384242300 +0900
3 @@ -39,6 +39,16 @@
4 self._is_included = kw.get('is_included',False)
5 self.request = request
6 self.cfg = request.cfg
7 +
8 + # for section editing
9 + self._allow_section_edit = None
10 + if not hasattr(request, 'sectionindex'):
11 + request.sectionindex = 0
12 +
13 + self.sectionstack = []
14 + self.sectionpool = {}
15 + self.sectionlastdepth = 0
16 + self.lineno = 0
17
18 if not hasattr(request, '_fmt_hd_counters'):
19 request._fmt_hd_counters = []
20 @@ -285,6 +295,7 @@
21 return '<a id="%s"></a>' % (id, ) # do not add a \n here, it breaks pre sections with line_anchordef
22
23 def line_anchordef(self, lineno):
24 + self.lineno = lineno
25 return self.anchordef("line-%d" % lineno)
26
27 def anchorlink(self, on, name='', id=None):
28 @@ -689,6 +700,21 @@
29 if not self._base_depth:
30 self._base_depth = depth
31
32 + # section editing configuration
33 + if self._allow_section_edit is None:
34 + # need to add config
35 + self._allow_section_edit = self.cfg.allow_section_edit
36 + # self._allow_section_edit = 1
37 + sectionediting = self.request.getPragma('section-edit', '').lower()
38 + if sectionediting in ['off']:
39 + self._allow_section_edit = 0
40 + elif sectionediting in ['on']:
41 + self._allow_section_edit = 1
42 +
43 + if self._allow_section_edit:
44 + if not self.request.user.may.write(self.page.page_name):
45 + self._allow_section_edit = 0
46 +
47 count_depth = max(depth - (self._base_depth - 1), 1)
48
49 # check numbering, possibly changing the default
50 @@ -707,7 +733,32 @@
51
52 # closing tag, with empty line after, to make source more readable
53 if not on:
54 - return self.close('h%d' % heading_depth) + '\n'
55 + result = self.close('h%d' % heading_depth)
56 +
57 + sectionscript = ''
58 + if self._allow_section_edit:
59 +
60 + self.request.sectionindex += 1
61 + sectionindex = self.request.sectionindex
62 + sectionscript = self.savesectioninfor(sectionindex, depth, self.lineno)
63 +
64 + attr = 'id="sectionedit%d"' % sectionindex
65 +
66 + backto = u''
67 + if self._is_included and hasattr(self.request, "_Include_backto"):
68 + backto = u'&backto=%s' % wikiutil.quoteWikinameURL(self.request._Include_backto)
69 +
70 + sectioneditpage = u'%s/%s' % (self.request.getScriptname(), wikiutil.quoteWikinameURL(self.page.page_name))
71 + srev = self.page.current_rev()
72 + querystring = u'%s?action=edit%s&srev=%d&startline=%d' % (sectioneditpage, backto, srev, self.lineno)
73 +
74 + result = ('%s%s%s%s' %
75 + (self.url(1, querystring, unescaped=1, title='Edit this section', attrs=attr),
76 + self.icon('edit'),
77 + self.url(0),
78 + result))
79 +
80 + return ' %s%s' % (result, sectionscript)
81
82 # create section number
83 number = ''
84 @@ -840,6 +891,53 @@
85 return self.open(tag, newline=1, attr=attrs)
86 return self.close(tag)
87
88 + def savesectioninfor(self, index, depth, lineno, save=1):
89 + # store section information
90 + section = {}
91 + sectionscriptlist = []
92 + sectionscript = u'document.getElementById("sectionedit%d").href += "&endline=%d";'
93 + scriptresult = ''
94 +
95 + lastdepth = self.sectionlastdepth
96 + sectionindex = index
97 +
98 + if lastdepth >= depth:
99 + while 1:
100 + if len(self.sectionstack):
101 + lastsection = self.sectionstack.pop()
102 + lastdepth = lastsection['depth']
103 + if lastdepth >= depth:
104 + self.sectionpool[lastsection['index']]['endlineno'] = lineno - 1
105 + sectionscriptlist.append(sectionscript % (lastsection['index'], lineno - 1))
106 + else:
107 + self.sectionstack.append(lastsection)
108 + break
109 + else:
110 + break
111 +
112 + if save:
113 + section['index'] = sectionindex
114 + section['startlineno'] = lineno
115 + section['depth'] = depth
116 + section['endlineno'] = -1
117 + self.sectionlastdepth = depth
118 + self.sectionpool[sectionindex] = section
119 + self.sectionstack.append(section)
120 +
121 + if len(sectionscriptlist) > 0:
122 +
123 + scriptresult = u"""
124 +<script type="text/javascript">
125 +<!--
126 +%s
127 +//-->
128 +</script>
129 +""" % u'\n'.join(sectionscriptlist)
130 +
131 + return scriptresult
132 +
133 +
134 +
135 def escapedText(self, text):
136 return wikiutil.escape(text)
137
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.