# -*- coding: iso-8859-1 -*-
"""MoinMoin theme "sinorca4moin" by David Linke.
Credits to "Haran" who published his sinorca-design at www.oswd.org
"""
from MoinMoin import wikiutil
from MoinMoin.Page import Page
from MoinMoin.theme import ThemeBase
class Theme(ThemeBase):
""" here are the functions generating the html responsible for
the look and feel of your wiki site
"""
name = "sinorca4moin"
def iconbar(self, d):
"""
Assemble the iconbar
@param d: parameter dictionary
@rtype: string
@return: iconbar html
"""
iconbar = []
if self.cfg.page_iconbar and self.request.user.show_toolbar and d['page_name']:
iconbar.append('
\n')
icons = self.cfg.page_iconbar[:]
for icon in icons:
if icon == "up":
if d['page_parent_page']:
iconbar.append('- %s
\n' % self.make_iconlink(icon, d))
elif icon == "subscribe":
iconbar.append('- %s
\n' % self.make_iconlink(
["subscribe", "unsubscribe"][self.request.user.isSubscribedTo([d['page_name']])], d))
elif icon == "home":
if d['page_home_page']:
iconbar.append('- %s
\n' % self.make_iconlink(icon, d))
else:
iconbar.append('- %s
\n' % self.make_iconlink(icon, d))
iconbar.append('
\n')
return ''.join(iconbar)
def editbar(self, d):
""" Assemble the page edit bar.
Display on existing page. Replace iconbar, showtext, edit text,
refresh cache and available actions.
@param d: parameter dictionary
@rtype: unicode
@return: iconbar html
"""
page = d['page']
if not self.shouldShowEditbar(page):
return ''
# Use cached editbar if possible.
cacheKey = 'editbar'
cached = self._cache.get(cacheKey)
if cached:
return cached
# Make new edit bar
request = self.request
_ = self.request.getText
link = wikiutil.link_tag
quotedname = wikiutil.quoteWikinameURL(page.page_name)
links = []
add = links.append
# Parent page
#parent = page.getParentPage()
#if parent:
# add(parent.link_to(request, _("Show Parent", formatted=False)))
# Page actions
if page.isWritable() and request.user.may.write(page.page_name):
add(link(request, quotedname + '?action=edit', _('Edit')))
else:
add(_('Immutable Page', formatted=False))
add(link(request, quotedname + '?action=info',
_('Get Info', formatted=False)))
add(self.actionsMenu(page))
# Format
items = '\n'.join(['%s' % item for item in links if item != ''])
html = u'\n' % items
# cache for next call
self._cache[cacheKey] = html
return html
def wikipanel(self, d):
""" Create wiki panel """
_ = self.request.getText
html = [
u'',
u' ' % _("Wiki"),
self.navibar(d),
u'
',
]
return u'\n'.join(html)
def pagepanel(self, d):
""" Create page panel """
_ = self.request.getText
if self.shouldShowEditbar(d['page']):
html = [
u'',
u' ' % _("Page"),
self.editbar(d),
u'
',
]
return u'\n'.join(html)
return ''
def userpanel(self, d):
""" Create user panel """
_ = self.request.getText
html = [
u'',
u' ' % _("User"),
self.username(d),
u'
'
]
return u'\n'.join(html)
def logo(self):
""" Assemble logo with link to front page
adds h1-tags for sinorca
"""
if self.cfg.logo_string:
pagename = wikiutil.getFrontPage(self.request).page_name
pagename = wikiutil.quoteWikinameURL(pagename)
logo = wikiutil.link_tag(self.request, pagename, self.cfg.logo_string)
html = u'''
''' % logo
return html
return u''
def header(self, d):
"""
Assemble page header
@param d: parameter dictionary
@rtype: string
@return: page header html
"""
_ = self.request.getText
trail = self.trail(d)
html = [
# Header
u'',
# Iconbar
self.iconbar(d),
# Sidebar
u'',
u'',
self.msg(d),
# Page
self.startPage(),
self.title(d),
]
return u'\n'.join(html)
def footer(self, d, **keywords):
""" Assemble page footer
@param d: parameter dictionary
@keyword ...:...
@rtype: string
@return: page footer html
"""
page = d['page']
html = [
# Page end
# Used to extend the page to the bottom of the sidebar
u'',
self.pageinfo(page),
self.endPage(),
# Custom html above footer
self.emit_custom_html(self.cfg.page_footer1),
# And bellow
self.emit_custom_html(self.cfg.page_footer2),
]
return u'\n'.join(html)
def execute(request):
"""
Generate and return a theme object
@param request: the request object
@rtype: MoinTheme
@return: Theme object
"""
return Theme(request)