Back to index

moin  1.9.0~rc2
classic.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin classic theme
00004 
00005     This class can also be used as base class for other themes -
00006     if you make an empty child class, you will get classic behaviour.
00007 
00008     If you want modified behaviour, just override the stuff you
00009     want to change in the child class.
00010 
00011     @copyright: 2003-2006 MoinMoin:ThomasWaldmann
00012     @license: GNU GPL, see COPYING for details.
00013 """
00014 
00015 from MoinMoin import caching
00016 from MoinMoin.action import get_available_actions
00017 from MoinMoin.theme import ThemeBase
00018 
00019 
00020 class Theme(ThemeBase):
00021     """ here are the functions generating the html responsible for
00022         the look and feel of your wiki site
00023     """
00024 
00025     name = "classic"
00026 
00027     def footer(self, d, **keywords):
00028         """ Assemble wiki footer
00029 
00030         @param d: parameter dictionary
00031         @keyword ...:...
00032         @rtype: unicode
00033         @return: page footer html
00034         """
00035         page = d['page']
00036         parts = [# End of page
00037                  self.pageinfo(page),
00038                  self.endPage(),
00039 
00040                  # Pre footer custom html (not recommended!)
00041                  self.emit_custom_html(self.cfg.page_footer1),
00042 
00043                  # Footer
00044                  self.editbar(d, **keywords),
00045                  self.credits(d),
00046                  self.showversion(d, **keywords),
00047 
00048                  # Post footer custom html
00049                  self.emit_custom_html(self.cfg.page_footer2), ]
00050         return u'\n'.join(parts)
00051 
00052     def editbar(self, d, **keywords):
00053         if not self.shouldShowEditbar(d['page']):
00054             return ''
00055         parts = [u'<div id="footer">',
00056                  self.edit_link(d, **keywords),
00057                  self.availableactions(d),
00058                  u'</div>', ]
00059         return ''.join(parts)
00060 
00061     def iconbar(self, d):
00062         """
00063         Assemble the iconbar
00064 
00065         @param d: parameter dictionary
00066         @rtype: string
00067         @return: iconbar html
00068         """
00069         iconbar = []
00070         if self.cfg.page_iconbar and self.request.user.show_toolbar and d['page_name']:
00071             iconbar.append('<ul id="iconbar">\n')
00072             icons = self.cfg.page_iconbar[:]
00073             for icon in icons:
00074                 if icon == "up":
00075                     if d['page_parent_page']:
00076                         iconbar.append('<li>%s</li>\n' % self.make_iconlink(icon, d))
00077                 elif icon == "subscribe" and (self.cfg.mail_enabled or self.cfg.jabber_enabled):
00078                     iconbar.append('<li>%s</li>\n' % self.make_iconlink(
00079                         ["subscribe", "unsubscribe"][self.request.user.isSubscribedTo([d['page_name']])], d))
00080                 else:
00081                     iconbar.append('<li>%s</li>\n' % self.make_iconlink(icon, d))
00082             iconbar.append('</ul>\n')
00083         return ''.join(iconbar)
00084 
00085     def header(self, d):
00086         """
00087         Assemble page header
00088 
00089         @param d: parameter dictionary
00090         @rtype: string
00091         @return: page header html
00092         """
00093         newdict = {
00094             'config_header1_html': self.emit_custom_html(self.cfg.page_header1),
00095             'config_header2_html': self.emit_custom_html(self.cfg.page_header2),
00096             'search_form_html': self.searchform(d),
00097             'logo_html': self.logo(),
00098             'interwiki_html': self.interwiki(d),
00099             'title_html': self.title(d),
00100             'username_html': self.username(d),
00101             'navibar_html': self.navibar(d),
00102             'iconbar_html': self.iconbar(d),
00103             'msg_html': self.msg(d),
00104             'trail_html': self.trail(d),
00105             'startpage_html': self.startPage(),
00106         }
00107         newdict.update(d)
00108 
00109         html = """
00110 %(config_header1_html)s
00111 
00112 <div id="header">
00113 %(logo_html)s
00114 %(search_form_html)s
00115 %(username_html)s
00116 <div id="locationline">
00117 %(interwiki_html)s
00118 %(title_html)s
00119 </div>
00120 %(trail_html)s
00121 %(iconbar_html)s
00122 %(navibar_html)s
00123 %(msg_html)s
00124 </div>
00125 
00126 %(config_header2_html)s
00127 
00128 %(startpage_html)s
00129 """ % newdict
00130         return html
00131 
00132     def editorheader(self, d):
00133         """
00134         Assemble page header for editor
00135 
00136         @param d: parameter dictionary
00137         @rtype: string
00138         @return: page header html
00139         """
00140         dict = {
00141             'config_header1_html': self.emit_custom_html(self.cfg.page_header1),
00142             'config_header2_html': self.emit_custom_html(self.cfg.page_header2),
00143             'title_html': self.title(d),
00144             'msg_html': self.msg(d),
00145             'startpage_html': self.startPage(),
00146         }
00147         dict.update(d)
00148 
00149         html = """
00150 %(config_header1_html)s
00151 
00152 %(title_html)s
00153 %(msg_html)s
00154 
00155 %(config_header2_html)s
00156 
00157 %(startpage_html)s
00158 """ % dict
00159         return html
00160 
00161     # Footer stuff #######################################################
00162 
00163     def edit_link(self, d, **keywords):
00164         """
00165         Assemble EditText link (or indication that page cannot be edited)
00166 
00167         @param d: parameter dictionary
00168         @rtype: string
00169         @return: edittext link html
00170         """
00171         page = d['page']
00172         return  u'<ul class="editbar"><li>%s</li></ul>' % self.editorLink(page)
00173 
00174     def availableactions(self, d):
00175         """
00176         assemble HTML code for the available actions
00177 
00178         @param d: parameter dictionary
00179         @rtype: string
00180         @return: available actions html
00181         """
00182         request = self.request
00183         _ = request.getText
00184         rev = d['rev']
00185         html = []
00186         page = d['page']
00187         available = get_available_actions(request.cfg, page, request.user)
00188         if available:
00189             available = list(available)
00190             available.sort()
00191             for action in available:
00192                 # Always add spaces: AttachFile -> Attach File
00193                 # XXX do not make a page object just for split_title
00194                 #title = Page(request, action).split_title(force=1)
00195                 title = action
00196                 # Use translated version if available
00197                 title = _(title)
00198                 querystr = {'action': action}
00199                 if rev:
00200                     querystr['rev'] = str(rev)
00201                 link = page.link_to(request, text=title, querystr=querystr, rel='nofollow')
00202                 html.append(link)
00203 
00204         title = _("DeleteCache")
00205         link = page.link_to(request, text=title, querystr={'action': 'refresh'}, rel='nofollow')
00206 
00207         cache = caching.CacheEntry(request, page, page.getFormatterName(), scope='item')
00208         date = request.user.getFormattedDateTime(cache.mtime())
00209         deletecache = u'<p>%s %s</p>' % (link, _('(cached %s)') % date)
00210 
00211         html = deletecache + u'<p>%s %s</p>\n' % (_('Or try one of these actions:'),
00212                                        u', '.join(html))
00213         return html
00214 
00215 
00216 def execute(request):
00217     """
00218     Generate and return a theme object
00219 
00220     @param request: the request object
00221     @rtype: MoinTheme
00222     @return: Theme object
00223     """
00224     return Theme(request)
00225