comparison MoinMoin/action/diff.py @ 1384:d1ceb31f3d02

make more use of formatter
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 21 Aug 2006 09:59:57 +0200
parents f4558797325a
children 30116d7d098a
comparison
equal deleted inserted replaced
1383:fdb726f0f34f 1384:d1ceb31f3d02
115 newpage = Page(request, "$EmptyPage$") # hack 115 newpage = Page(request, "$EmptyPage$") # hack
116 newpage.set_raw_body("") # avoid loading from disk 116 newpage.set_raw_body("") # avoid loading from disk
117 oldrev2 = 0 # XXX 117 oldrev2 = 0 # XXX
118 118
119 edit_count = abs(oldcount1 - oldcount2) 119 edit_count = abs(oldcount1 - oldcount2)
120 120 f = request.formatter
121 # this should use the formatter, but there is none? 121 request.write(f.div(1, id="content"))
122 request.write('<div id="content">\n') # start content div 122 request.write(f.paragraph(1, css_class="diff-header"))
123 request.write('<p class="diff-header">') 123 request.write(f.text(_('Differences between revisions %d and %d') % (oldpage.get_real_rev(), newpage.get_real_rev())))
124 request.write(_('Differences between revisions %d and %d') % (oldpage.get_real_rev(), newpage.get_real_rev()))
125 if edit_count > 1: 124 if edit_count > 1:
126 request.write(' ' + _('(spanning %d versions)') % (edit_count,)) 125 request.write(f.text(' ' + _('(spanning %d versions)') % (edit_count,)))
127 request.write('</p>') 126 request.write(f.paragraph(0))
128 127
129 if request.user.show_fancy_diff: 128 if request.user.show_fancy_diff:
130 from MoinMoin.util import diff_html 129 from MoinMoin.util import diff_html
131 request.write(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body())) 130 request.write(f.rawHTML(diff_html.diff(request, oldpage.get_raw_body(), newpage.get_raw_body())))
132 newpage.send_page(request, count_hit=0, content_only=1, content_id="content-below-diff") 131 newpage.send_page(request, count_hit=0, content_only=1, content_id="content-below-diff")
133 else: 132 else:
134 from MoinMoin.util import diff_text 133 from MoinMoin.util import diff_text
135 lines = diff_text.diff(oldpage.getlines(), newpage.getlines()) 134 lines = diff_text.diff(oldpage.getlines(), newpage.getlines())
136 if not lines: 135 if not lines:
137 msg = _("No differences found!") 136 msg = f.text(_("No differences found!"))
138 if edit_count > 1: 137 if edit_count > 1:
139 msg = msg + '<p>' + _('The page was saved %(count)d times, though!') % { 138 msg = msg + f.paragraph(1) + f.text(_('The page was saved %(count)d times, though!') % {
140 'count': edit_count} 139 'count': edit_count}) + f.paragraph(0)
141 request.write(msg) 140 request.write(msg)
142 else: 141 else:
143 if ignorews: 142 if ignorews:
144 request.write(_('(ignoring whitespace)') + '<br>') 143 request.write(f.text(_('(ignoring whitespace)')), f.linebreak())
145 else: 144 else:
146 qstr = {'action': 'diff', 'ignorews': '1', } 145 qstr = {'action': 'diff', 'ignorews': '1', }
147 if rev1: 146 if rev1:
148 qstr['rev1'] = str(rev1) 147 qstr['rev1'] = str(rev1)
149 if rev2: 148 if rev2:
150 qstr['rev2'] = str(rev2) 149 qstr['rev2'] = str(rev2)
151 request.write(Page(request, pagename).link_to(request, 150 request.write(f.paragraph(1), Page(request, pagename).link_to(request,
152 text=_('Ignore changes in the amount of whitespace'), 151 text=_('Ignore changes in the amount of whitespace'),
153 querystr=qstr, rel='nofollow') + '<p>') 152 querystr=qstr, rel='nofollow'), f.paragraph(0))
154 153
155 request.write('<pre>') 154 request.write(f.preformatted(1))
156 for line in lines: 155 for line in lines:
157 if line[0] == "@": 156 if line[0] == "@":
158 request.write('<hr>') 157 request.write(f.rule(1))
159 request.write(wikiutil.escape(line)+'\n') 158 request.write(f.text(wikiutil.escape(line)+'\n'))
160 request.write('</pre>') 159 request.write(f.preformatted(0))
161 160
162 request.write('</div>\n') # end content div 161 request.write(f.div(0)) # end content div
163 request.theme.send_footer(pagename) 162 request.theme.send_footer(pagename)
164 request.theme.send_closing_html() 163 request.theme.send_closing_html()
165 164