|
1
by Matthew East
Adding files, first commit |
1 |
# -*- coding: iso-8859-1 -*-
|
2 |
"""
|
|
3 |
MoinMoin ubuntu theme
|
|
4 |
||
5 |
@copyright: (c) 2003-2004 by Nir Soffer, Thomas Waldmann
|
|
|
4
by Matthew East
Correcting copyright information |
6 |
(c) Henrik Omma / Heather Stern (ubuntu theme)
|
7 |
(c) 2008 by Matthew East (new ubuntu theme)
|
|
8 |
||
|
1
by Matthew East
Adding files, first commit |
9 |
@license: GNU GPL, see COPYING for details.
|
10 |
||
11 |
"""
|
|
12 |
||
13 |
from MoinMoin.theme import ThemeBase |
|
14 |
from MoinMoin import wikiutil |
|
15 |
from MoinMoin.Page import Page |
|
16 |
||
17 |
||
18 |
class Theme(ThemeBase): |
|
19 |
||
20 |
name = 'ubuntunew' |
|
21 |
||
22 |
def header(self, d, **kw): |
|
23 |
""" Assemble wiki header
|
|
24 |
|
|
25 |
@param d: parameter dictionary
|
|
26 |
@rtype: unicode
|
|
27 |
@return: page header html
|
|
28 |
"""
|
|
29 |
request = self.request |
|
30 |
||
31 |
html = [ |
|
32 |
# Pre header custom html
|
|
33 |
self.emit_custom_html(self.cfg.page_header1), |
|
34 |
||
35 |
# Header
|
|
36 |
u'<div id="round" class="roundme">', |
|
|
41
by Matthew East
Use full urls for image sources so that the theme works for local testing |
37 |
u'<img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png">', |
|
1
by Matthew East
Adding files, first commit |
38 |
u'<div id="layout" class="container clear-block">', |
39 |
u'<div id="header">', |
|
40 |
u'<div id="logo-floater">', |
|
|
41
by Matthew East
Use full urls for image sources so that the theme works for local testing |
41 |
u'<h1><a href="http://help.ubuntu.com" title="Ubuntu Documentation"><img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" /></a></h1>', |
|
1
by Matthew East
Adding files, first commit |
42 |
u'</div>', |
43 |
self.searchform(d), |
|
|
42
by Matthew East
* Adding breadcrumbs navigation links to the top of the page |
44 |
u'<div id="sitename"><a href="https://help.ubuntu.com/community"><img src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-faq.png" /><span>Community Documentation</span></a></div>', |
|
1
by Matthew East
Adding files, first commit |
45 |
u'</div> <!--header-->', |
|
33
by Matthew East
* cleanup ubuntunew.py by removing unnecessary title definition |
46 |
self.loginbar(d), |
|
1
by Matthew East
Adding files, first commit |
47 |
self.msg(d), |
48 |
||
49 |
# Post header custom html (not recommended)
|
|
50 |
self.emit_custom_html(self.cfg.page_header2),'<!--1-->', |
|
51 |
||
52 |
# Start of page
|
|
53 |
self.startPage(),'<!--2-->', |
|
|
42
by Matthew East
* Adding breadcrumbs navigation links to the top of the page |
54 |
self.breadcrumbs(d), |
55 |
# u'<div id="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/community">Community Documentation</a></div>',
|
|
|
1
by Matthew East
Adding files, first commit |
56 |
self.title(d),'<!--3-->', |
57 |
]
|
|
58 |
return u'\n'.join(html) |
|
59 |
||
|
10
by Matthew East
include header on edit page, solves footer issues |
60 |
editorheader = header |
|
1
by Matthew East
Adding files, first commit |
61 |
|
|
42
by Matthew East
* Adding breadcrumbs navigation links to the top of the page |
62 |
def breadcrumbs(self, d): |
63 |
""" Assemble the breadcrumb links, based on the "title" function
|
|
64 |
|
|
65 |
@param d: parameter dictionary
|
|
66 |
@rtype: string
|
|
67 |
@return: title html
|
|
68 |
"""
|
|
69 |
_ = self.request.getText |
|
70 |
content = [] |
|
71 |
if d['title_text'] == d['page'].split_title(): # just showing a page, no action |
|
72 |
curpage = '' |
|
73 |
segments = d['page_name'].split('/') # was: title_text |
|
74 |
for s in segments[:-1]: |
|
75 |
curpage += s |
|
76 |
content.append("%s" % Page(self.request, curpage).link_to(self.request, s)) |
|
77 |
curpage += '/' |
|
78 |
link_text = segments[-1] |
|
79 |
link_title = _('Click to do a full-text search for this title', formatted=False) |
|
80 |
link_query = { |
|
81 |
'action': 'fullsearch', |
|
82 |
'value': 'linkto:"%s"' % d['page_name'], |
|
83 |
'context': '180', |
|
84 |
}
|
|
85 |
# we dont use d['title_link'] any more, but make it ourselves:
|
|
86 |
link = d['page'].link_to(self.request, link_text, querystr=link_query, title=link_title, css_class='backlink', rel='nofollow') |
|
87 |
content.append(('%s') % link) |
|
88 |
else: |
|
89 |
content.append('%s' % wikiutil.escape(d['title_text'])) |
|
90 |
||
91 |
html = ''' |
|
92 |
<div id="breadcrumbs">
|
|
93 |
<a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/community">Community Documentation</a> > %s |
|
94 |
</div>
|
|
95 |
''' % "".join(content) |
|
96 |
return html |
|
97 |
||
|
35
by Matthew East
Adding search bar by Dustin Kirkland, some other minor fixes |
98 |
def searchform(self, d): |
99 |
"""
|
|
100 |
assemble Custom search form by Dustin Kirkland
|
|
|
39
by Matthew East
Include search bar for users without javascript too |
101 |
now works for browsers with and without javascript
|
|
35
by Matthew East
Adding search bar by Dustin Kirkland, some other minor fixes |
102 |
|
103 |
@param d: parameter dictionary
|
|
104 |
@rtype: unicode
|
|
105 |
@return: search form html
|
|
106 |
"""
|
|
107 |
_ = self.request.getText |
|
108 |
form = self.request.form |
|
109 |
updates = { |
|
110 |
'search_label': _('Search:', formatted=False), |
|
111 |
'search_value': wikiutil.escape(form.get('value', [''])[0], 1), |
|
112 |
'search_full_label': _('Text', formatted=False), |
|
113 |
'search_title_label': _('Titles', formatted=False), |
|
114 |
'baseurl': self.request.getScriptname(), |
|
115 |
'pagename_quoted': wikiutil.quoteWikinameURL(d['page'].page_name), |
|
116 |
}
|
|
117 |
d.update(updates) |
|
118 |
||
119 |
html = u''' |
|
|
39
by Matthew East
Include search bar for users without javascript too |
120 |
<noscript>
|
121 |
<form action="http://www.google.com/cse" id="cse-search-box">
|
|
122 |
<div>
|
|
|
45
by Matthew East
Update Google CSE id as per Dustin Kirkland |
123 |
<input type="hidden" name="cx" value="004599128559784038176:vj_p0xo-nng" />
|
|
39
by Matthew East
Include search bar for users without javascript too |
124 |
<input type="hidden" name="ie" value="UTF-8" />
|
125 |
<input type="text" name="q" size="27" />
|
|
126 |
<input type="submit" name="sa" value="Search" />
|
|
127 |
</div>
|
|
128 |
</form>
|
|
129 |
</noscript>
|
|
130 |
||
131 |
<script>
|
|
132 |
document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
|
|
133 |
document.write(' <div>');
|
|
134 |
document.write(' <input type="hidden" name="cof" value="FORID:9" />');
|
|
|
45
by Matthew East
Update Google CSE id as per Dustin Kirkland |
135 |
document.write(' <input type="hidden" name="cx" value="004599128559784038176:vj_p0xo-nng" />');
|
|
39
by Matthew East
Include search bar for users without javascript too |
136 |
document.write(' <input type="hidden" name="ie" value="UTF-8" />');
|
137 |
document.write(' <input type="text" name="q" size="27" />');
|
|
138 |
document.write(' <input type="submit" name="sa" value="Search" />');
|
|
139 |
document.write(' </div>');
|
|
140 |
document.write('</form>');
|
|
141 |
</script>
|
|
|
35
by Matthew East
Adding search bar by Dustin Kirkland, some other minor fixes |
142 |
''' % d |
143 |
return html |
|
144 |
||
|
1
by Matthew East
Adding files, first commit |
145 |
def editbar(self, d): |
146 |
""" Assemble the page edit bar.
|
|
147 |
||
148 |
Display on existing page. Replace iconbar, showtext, edit text,
|
|
149 |
refresh cache and available actions.
|
|
150 |
|
|
151 |
@param d: parameter dictionary
|
|
152 |
@rtype: unicode
|
|
153 |
@return: iconbar html
|
|
154 |
"""
|
|
155 |
page = d['page'] |
|
156 |
if not self.shouldShowEditbar(page): |
|
157 |
return '' |
|
158 |
||
159 |
# Use cached editbar if possible.
|
|
160 |
cacheKey = 'editbar' |
|
161 |
cached = self._cache.get(cacheKey) |
|
162 |
if cached: |
|
163 |
return cached |
|
164 |
||
165 |
# Make new edit bar
|
|
166 |
request = self.request |
|
167 |
_ = self.request.getText |
|
168 |
link = wikiutil.link_tag |
|
169 |
quotedname = wikiutil.quoteWikinameURL(page.page_name) |
|
170 |
links = [] |
|
171 |
add = links.append |
|
172 |
||
173 |
# Page actions
|
|
174 |
if page.isWritable() and request.user.valid and request.user.may.write(page.page_name): |
|
175 |
add(self.editorLink(page)) |
|
|
14
by Matthew East
restore Page History link to editbar as well as bottom of page |
176 |
add(self.infoLink(page)) |
|
1
by Matthew East
Adding files, first commit |
177 |
add(self.subscribeLink(page)) |
|
19
by Matthew East
add link to attachments action in editbar |
178 |
add(self.attachmentsLink(page)) |
|
1
by Matthew East
Adding files, first commit |
179 |
add(self.actionsMenu(page)) |
180 |
# Add link to RecentChanges
|
|
181 |
changesPage = wikiutil.getLocalizedPage(request, 'RecentChanges') |
|
182 |
title = changesPage.split_title(request) |
|
183 |
add(changesPage.link_to(request, text=title)) |
|
|
5
by Matthew East
add link to WikiGuide in editbar, note of TODO for Page History and |
184 |
# Add link to WikiGuide
|
185 |
guidePage = wikiutil.getLocalizedPage(request, 'WikiGuide') |
|
186 |
title = guidePage.split_title(request) |
|
187 |
add(guidePage.link_to(request, text=title)) |
|
|
16
by Matthew East
Moving username links into the editorbar, this prevents them from showing up on the edit page and ensures correct alignment with other links in that bar |
188 |
|
189 |
# Add username/homepage link for registered users. We don't care
|
|
190 |
# if it exists, the user can create it.
|
|
191 |
if request.user.valid and request.user.name: |
|
192 |
interwiki = wikiutil.getInterwikiHomePage(request) |
|
193 |
name = request.user.name |
|
194 |
aliasname = request.user.aliasname |
|
195 |
if not aliasname: |
|
196 |
aliasname = name |
|
197 |
title = "%s @ %s" % (aliasname, interwiki[0]) |
|
198 |
# link to (interwiki) user homepage
|
|
199 |
homelink = (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki) + |
|
200 |
request.formatter.text(name) + |
|
201 |
request.formatter.interwikilink(0, title=title, id="userhome", *interwiki)) |
|
202 |
add(homelink) |
|
203 |
# link to preferences page
|
|
204 |
add(d['page'].link_to(request, text=_('Preferences', formatted=False), |
|
205 |
querystr={'action': 'userprefs'}, id='userprefs', rel='nofollow')) |
|
206 |
# logout link
|
|
207 |
if request.cfg.show_login: |
|
208 |
if request.user.valid: |
|
209 |
add(d['page'].link_to(request, text=_('Logout', formatted=False), |
|
210 |
querystr={'action': 'logout', 'logout': 'logout'}, id='logout', rel='nofollow')) |
|
211 |
else: |
|
212 |
pass
|
|
|
5
by Matthew East
add link to WikiGuide in editbar, note of TODO for Page History and |
213 |
|
|
1
by Matthew East
Adding files, first commit |
214 |
elif not request.user.valid: |
215 |
pass
|
|
216 |
else: |
|
217 |
add(_('Immutable Page', formatted=False)) |
|
218 |
||
219 |
# Format
|
|
220 |
items = '\n'.join(['<li>%s</li>' % item for item in links if item != '']) |
|
|
27
by Matthew East
Working on javascript solution for editbar |
221 |
html = u'<ul id="showbar"><li><a href="#editbar" onclick="return togglebar()"><span id="showbarspan">Show</span> editing options</a></li></ul><ul id="editbar" style="">\n%s\n</ul>\n' % items |
|
1
by Matthew East
Adding files, first commit |
222 |
|
223 |
# cache for next call
|
|
224 |
self._cache[cacheKey] = html |
|
225 |
||
226 |
return html |
|
227 |
||
228 |
def infoLink(self, page): |
|
229 |
||
230 |
# Instead of "Info", Link text should read "Page History"
|
|
231 |
""" Return link to page information """
|
|
232 |
_ = self.request.getText |
|
233 |
return page.link_to(self.request, |
|
234 |
text=_('Page History', formatted=False), |
|
235 |
querystr={'action': 'info'}, css_class='nbinfo', rel='nofollow') |
|
236 |
||
237 |
||
238 |
def footer(self, d, **keywords): |
|
239 |
""" Assemble wiki footer
|
|
240 |
|
|
241 |
@param d: parameter dictionary
|
|
242 |
@keyword ...:...
|
|
243 |
@rtype: unicode
|
|
244 |
@return: page footer html
|
|
245 |
"""
|
|
246 |
page = d['page'] |
|
247 |
html = [ |
|
248 |
# End of page
|
|
249 |
self.pageinfo(page), |
|
|
11
by Matthew East
Adding new pagelinks module with Page History and Parent Page links |
250 |
self.pagelinks(d), |
|
1
by Matthew East
Adding files, first commit |
251 |
self.endPage(), |
252 |
||
253 |
# Pre footer custom html (not recommended!)
|
|
254 |
self.emit_custom_html(self.cfg.page_footer1), |
|
255 |
||
256 |
# Footer
|
|
257 |
u'<div id="footer">', |
|
|
18
by Matthew East
horizontal rule above footerlinks |
258 |
u'<hr width="550px">', |
|
1
by Matthew East
Adding files, first commit |
259 |
self.footerlinks(), |
260 |
self.showversion(d, **keywords), |
|
261 |
u'</div> <!-- footer -->', |
|
262 |
u'</div> <!-- layout -->', |
|
|
41
by Matthew East
Use full urls for image sources so that the theme works for local testing |
263 |
u'<img id="bottomcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png">', |
|
1
by Matthew East
Adding files, first commit |
264 |
u'</div> <!-- round -->', |
265 |
# Post footer custom html
|
|
266 |
self.emit_custom_html(self.cfg.page_footer2), |
|
267 |
]
|
|
|
16
by Matthew East
Moving username links into the editorbar, this prevents them from showing up on the edit page and ensures correct alignment with other links in that bar |
268 |
# For logged in users, show editbar
|
|
1
by Matthew East
Adding files, first commit |
269 |
request = self.request |
270 |
if request.user.valid: |
|
|
7
by Matthew East
Fixed cut-off footer for logged in users, thanks to ThomasWaldmann in #moin |
271 |
html.extend([ |
|
1
by Matthew East
Adding files, first commit |
272 |
self.editbar(d), |
|
7
by Matthew East
Fixed cut-off footer for logged in users, thanks to ThomasWaldmann in #moin |
273 |
])
|
|
1
by Matthew East
Adding files, first commit |
274 |
return u'\n'.join(html) |
275 |
||
|
11
by Matthew East
Adding new pagelinks module with Page History and Parent Page links |
276 |
def pagelinks(self, d): |
277 |
||
278 |
page = d['page'] |
|
279 |
request = self.request |
|
280 |
_ = self.request.getText |
|
281 |
link = wikiutil.link_tag |
|
282 |
quotedname = wikiutil.quoteWikinameURL(page.page_name) |
|
283 |
links = [] |
|
284 |
add = links.append |
|
285 |
||
286 |
# Parent page
|
|
287 |
parent = page.getParentPage() |
|
288 |
if parent: |
|
289 |
add(parent.link_to(request, _("Parent Page", formatted=False))) |
|
290 |
add(self.infoLink(page)) |
|
291 |
||
292 |
# Format
|
|
293 |
items = '\n'.join(['<li>%s</li>' % item for item in links if item != '']) |
|
294 |
html = u'<ul class="pagelinks">\n%s\n</ul>\n' % items |
|
295 |
||
296 |
return html |
|
297 |
||
298 |
||
|
1
by Matthew East
Adding files, first commit |
299 |
def footerlinks(self): |
300 |
""" Copyright notices
|
|
301 |
||
302 |
Nice and boring compared to the other stuff.
|
|
303 |
|
|
304 |
@rtype: unicode
|
|
305 |
@return: extra footer html
|
|
306 |
"""
|
|
307 |
||
308 |
html = u''' |
|
309 |
<div id="ubuntulinks">
|
|
|
6
by Matthew East
better footer text, mark TODO item with footer |
310 |
<p>
|
|
15
by Matthew East
Bring link and heading colours into line with Ubuntu website, reduce |
311 |
The material on this wiki is available under a free license, see <a href="https://help.ubuntu.com/community/License">Copyright / License</a> for details<br /><b>You</b> can contribute to this wiki, see <a href="https://help.ubuntu.com/community/WikiGuide">Wiki Guide</a> for details
|
|
8
by Matthew East
tiny tweak to footer margin |
312 |
</p><br>
|
|
1
by Matthew East
Adding files, first commit |
313 |
</div>
|
314 |
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
|
|
315 |
</script>
|
|
316 |
<script type="text/javascript">
|
|
317 |
_uacct = "UA-1018242-7";
|
|
318 |
urchinTracker();
|
|
319 |
__utmSetVar('UbuntuWiki');
|
|
320 |
</script>
|
|
|
27
by Matthew East
Working on javascript solution for editbar |
321 |
<script type="text/javascript">
|
322 |
function togglebar() {
|
|
323 |
obj = document.getElementById('editbar');
|
|
324 |
obj2 = document.getElementById('showbarspan');
|
|
|
30
by Matthew East
fix javascript to make editbar work as designed (by Matthew Nuzum) |
325 |
obj3 = document.getElementById('showbar');
|
|
27
by Matthew East
Working on javascript solution for editbar |
326 |
if (obj.style.position == 'fixed') {
|
|
30
by Matthew East
fix javascript to make editbar work as designed (by Matthew Nuzum) |
327 |
obj.style.position = 'static';
|
328 |
obj3.style.bottom = '0';
|
|
|
27
by Matthew East
Working on javascript solution for editbar |
329 |
obj2.innerHTML = 'Show';
|
330 |
} else {
|
|
331 |
obj.style.position = 'fixed';
|
|
332 |
obj2.innerHTML = 'Hide';
|
|
|
30
by Matthew East
fix javascript to make editbar work as designed (by Matthew Nuzum) |
333 |
obj3.style.bottom = '25px';
|
|
27
by Matthew East
Working on javascript solution for editbar |
334 |
}
|
335 |
return false;
|
|
336 |
}
|
|
337 |
</script>
|
|
|
1
by Matthew East
Adding files, first commit |
338 |
'''
|
339 |
return html |
|
340 |
return u'' |
|
341 |
||
342 |
def loginbar(self, d): |
|
343 |
""" If not logged in, offer to do so
|
|
344 |
|
|
345 |
@param d: parameter dictionary
|
|
346 |
@rtype: unicode
|
|
347 |
@return: username html
|
|
348 |
"""
|
|
349 |
request = self.request |
|
350 |
_ = request.getText |
|
351 |
||
352 |
loginbarlinks = [] |
|
353 |
# Add username/homepage link for registered users. We don't care
|
|
354 |
# if it exists, the user can create it.
|
|
355 |
if request.user.valid: |
|
356 |
pass
|
|
357 |
else: |
|
358 |
loginbarlinks.append(d['page'].link_to(request, text=_("Login to Edit", formatted=False), |
|
359 |
querystr={'action': 'login'}, id='login', rel='nofollow')) |
|
360 |
||
361 |
loginbarlinks = [u'<li>%s</li>' % link for link in loginbarlinks] |
|
362 |
html = u'<ul id="loginbar">%s</ul>' % ''.join(loginbarlinks) |
|
363 |
return html |
|
364 |
||
365 |
||
366 |
def execute(request): |
|
367 |
"""
|
|
368 |
Generate and return a theme object
|
|
369 |
|
|
370 |
@param request: the request object
|
|
371 |
@rtype: MoinTheme
|
|
372 |
@return: Theme object
|
|
373 |
"""
|
|
374 |
return Theme(request) |
|
375 |