Back to index

moin  1.9.0~rc2
modernized.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - modern theme
00004 
00005     @copyright: 2003-2005 Nir Soffer, Thomas Waldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 from MoinMoin.theme import ThemeBase
00010 from MoinMoin import wikiutil
00011 from MoinMoin.Page import Page
00012 
00013 class Theme(ThemeBase):
00014 
00015     name = "modernized"
00016 
00017     _ = lambda x: x     # We don't have gettext at this moment, so we fake it
00018     icons = {
00019         # key         alt                        icon filename      w   h
00020         # FileAttach
00021         'attach':     ("%(attach_count)s",       "moin-attach.png",   16, 16),
00022         'info':       ("[INFO]",                 "moin-info.png",     16, 16),
00023         'attachimg':  (_("[ATTACH]"),            "attach.png",        32, 32),
00024         # RecentChanges
00025         'rss':        (_("[RSS]"),               "moin-rss.png",      16, 16),
00026         'deleted':    (_("[DELETED]"),           "moin-deleted.png",  16, 16),
00027         'updated':    (_("[UPDATED]"),           "moin-updated.png",  16, 16),
00028         'renamed':    (_("[RENAMED]"),           "moin-renamed.png",  16, 16),
00029         'conflict':   (_("[CONFLICT]"),          "moin-conflict.png", 16, 16),
00030         'new':        (_("[NEW]"),               "moin-new.png",      16, 16),
00031         'diffrc':     (_("[DIFF]"),              "moin-diff.png",     16, 16),
00032         # General
00033         'bottom':     (_("[BOTTOM]"),            "moin-bottom.png",   16, 16),
00034         'top':        (_("[TOP]"),               "moin-top.png",      16, 16),
00035         'www':        ("[WWW]",                  "moin-www.png",      16, 16),
00036         'mailto':     ("[MAILTO]",               "moin-email.png",    16, 16),
00037         'news':       ("[NEWS]",                 "moin-news.png",     16, 16),
00038         'telnet':     ("[TELNET]",               "moin-telnet.png",   16, 16),
00039         'ftp':        ("[FTP]",                  "moin-ftp.png",      16, 16),
00040         'file':       ("[FILE]",                 "moin-ftp.png",      16, 16),
00041         # search forms
00042         'searchbutton': ("[?]",                  "moin-search.png",   16, 16),
00043         'interwiki':  ("[%(wikitag)s]",          "moin-inter.png",    16, 16),
00044 
00045         # smileys (this is CONTENT, but good looking smileys depend on looking
00046         # adapted to the theme background color and theme style in general)
00047         #vvv    ==      vvv  this must be the same for GUI editor converter
00048         'X-(':        ("X-(",                    'angry.png',         16, 16),
00049         ':D':         (":D",                     'biggrin.png',       16, 16),
00050         '<:(':        ("<:(",                    'frown.png',         16, 16),
00051         ':o':         (":o",                     'redface.png',       16, 16),
00052         ':(':         (":(",                     'sad.png',           16, 16),
00053         ':)':         (":)",                     'smile.png',         16, 16),
00054         'B)':         ("B)",                     'smile2.png',        16, 16),
00055         ':))':        (":))",                    'smile3.png',        16, 16),
00056         ';)':         (";)",                     'smile4.png',        16, 16),
00057         '/!\\':       ("/!\\",                   'alert.png',         16, 16),
00058         '<!>':        ("<!>",                    'attention.png',     16, 16),
00059         '(!)':        ("(!)",                    'idea.png',          16, 16),
00060         ':-?':        (":-?",                    'tongue.png',        16, 16),
00061         ':\\':        (":\\",                    'ohwell.png',        16, 16),
00062         '>:>':        (">:>",                    'devil.png',         16, 16),
00063         '|)':         ("|)",                     'tired.png',         16, 16),
00064         ':-(':        (":-(",                    'sad.png',           16, 16),
00065         ':-)':        (":-)",                    'smile.png',         16, 16),
00066         'B-)':        ("B-)",                    'smile2.png',        16, 16),
00067         ':-))':       (":-))",                   'smile3.png',        16, 16),
00068         ';-)':        (";-)",                    'smile4.png',        16, 16),
00069         '|-)':        ("|-)",                    'tired.png',         16, 16),
00070         '(./)':       ("(./)",                   'checkmark.png',     16, 16),
00071         '{OK}':       ("{OK}",                   'thumbs-up.png',     16, 16),
00072         '{X}':        ("{X}",                    'icon-error.png',    16, 16),
00073         '{i}':        ("{i}",                    'icon-info.png',     16, 16),
00074         '{1}':        ("{1}",                    'prio1.png',         15, 13),
00075         '{2}':        ("{2}",                    'prio2.png',         15, 13),
00076         '{3}':        ("{3}",                    'prio3.png',         15, 13),
00077         '{*}':        ("{*}",                    'star_on.png',       16, 16),
00078         '{o}':        ("{o}",                    'star_off.png',      16, 16),
00079     }
00080     del _
00081     def header(self, d, **kw):
00082         """ Assemble wiki header
00083 
00084         @param d: parameter dictionary
00085         @rtype: unicode
00086         @return: page header html
00087         """
00088         html = [
00089             # Pre header custom html
00090             self.emit_custom_html(self.cfg.page_header1),
00091 
00092             # Header
00093             u'<div id="header">',
00094             self.searchform(d),
00095             self.logo(),
00096             self.username(d),
00097             u'<h1 id="locationline">',
00098             self.interwiki(d),
00099             self.title_with_separators(d),
00100             u'</h1>',
00101             self.trail(d),
00102             self.navibar(d),
00103             #u'<hr id="pageline">',
00104             u'<div id="pageline"><hr style="display:none;"></div>',
00105             self.msg(d),
00106             self.editbar(d),
00107             u'</div>',
00108 
00109             # Post header custom html (not recommended)
00110             self.emit_custom_html(self.cfg.page_header2),
00111 
00112             # Start of page
00113             self.startPage(),
00114         ]
00115         return u'\n'.join(html)
00116 
00117     def editorheader(self, d, **kw):
00118         """ Assemble wiki header for editor
00119 
00120         @param d: parameter dictionary
00121         @rtype: unicode
00122         @return: page header html
00123         """
00124         html = [
00125             # Pre header custom html
00126             self.emit_custom_html(self.cfg.page_header1),
00127 
00128             # Header
00129             u'<div id="header">',
00130             u'<h1 id="locationline">',
00131             self.title_with_separators(d),
00132             u'</h1>',
00133             self.msg(d),
00134             u'</div>',
00135 
00136             # Post header custom html (not recommended)
00137             self.emit_custom_html(self.cfg.page_header2),
00138 
00139             # Start of page
00140             self.startPage(),
00141         ]
00142         return u'\n'.join(html)
00143 
00144     def footer(self, d, **keywords):
00145         """ Assemble wiki footer
00146 
00147         @param d: parameter dictionary
00148         @keyword ...:...
00149         @rtype: unicode
00150         @return: page footer html
00151         """
00152         page = d['page']
00153         html = [
00154             # End of page
00155             self.pageinfo(page),
00156             self.endPage(),
00157 
00158             # Pre footer custom html (not recommended!)
00159             self.emit_custom_html(self.cfg.page_footer1),
00160 
00161             # Footer
00162             u'<div id="footer">',
00163             self.editbar(d),
00164             self.credits(d),
00165             self.showversion(d, **keywords),
00166             u'</div>',
00167 
00168             # Post footer custom html
00169             self.emit_custom_html(self.cfg.page_footer2),
00170             ]
00171         return u'\n'.join(html)
00172 
00173     def username(self, d):
00174         """ Assemble the username / userprefs link
00175 
00176         @param d: parameter dictionary
00177         @rtype: unicode
00178         @return: username html
00179         """
00180         request = self.request
00181         _ = request.getText
00182 
00183         userlinks = []
00184         # Add username/homepage link for registered users. We don't care
00185         # if it exists, the user can create it.
00186         if request.user.valid and request.user.name:
00187             interwiki = wikiutil.getInterwikiHomePage(request)
00188             name = request.user.name
00189             aliasname = request.user.aliasname
00190             if not aliasname:
00191                 aliasname = name
00192             title = "%s @ %s" % (aliasname, interwiki[0])
00193             # link to (interwiki) user homepage
00194             homelink = (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki) +
00195                         request.formatter.text(name) +
00196                         request.formatter.interwikilink(0, title=title, id="userhome", *interwiki))
00197             userlinks.append(homelink)
00198             # link to userprefs action
00199             if 'userprefs' not in self.request.cfg.actions_excluded:
00200                 userlinks.append(d['page'].link_to(request, text=_('Settings'),
00201                                                querystr={'action': 'userprefs'}, id='userprefs', rel='nofollow'))
00202 
00203         if request.user.valid:
00204             if request.user.auth_method in request.cfg.auth_can_logout:
00205                 userlinks.append(d['page'].link_to(request, text=_('Logout'),
00206                                                    querystr={'action': 'logout', 'logout': 'logout'}, id='logout', rel='nofollow'))
00207         else:
00208             query = {'action': 'login'}
00209             # special direct-login link if the auth methods want no input
00210             if request.cfg.auth_login_inputs == ['special_no_input']:
00211                 query['login'] = '1'
00212             if request.cfg.auth_have_login:
00213                 userlinks.append(d['page'].link_to(request, text=_("Login"),
00214                                                    querystr=query, id='login', rel='nofollow'))
00215 
00216         userlinks_html = u'<span class="sep"> | </span>'.join(userlinks)
00217         html = u'<div id="username">%s</div>' % userlinks_html
00218         return html
00219 
00220     def trail(self, d):
00221         """ Assemble page trail
00222 
00223         @param d: parameter dictionary
00224         @rtype: unicode
00225         @return: trail html
00226         """
00227         request = self.request
00228         user = request.user
00229         html = ''
00230         if not user.valid or user.show_page_trail:
00231             trail = user.getTrail()
00232             if trail:
00233                 items = []
00234                 for pagename in trail:
00235                     try:
00236                         interwiki, page = wikiutil.split_interwiki(pagename)
00237                         if interwiki != request.cfg.interwikiname and interwiki != 'Self':
00238                             link = (self.request.formatter.interwikilink(True, interwiki, page) +
00239                                     self.shortenPagename(page) +
00240                                     self.request.formatter.interwikilink(False, interwiki, page))
00241                             items.append(link)
00242                             continue
00243                         else:
00244                             pagename = page
00245 
00246                     except ValueError:
00247                         pass
00248                     page = Page(request, pagename)
00249                     title = page.split_title()
00250                     title = self.shortenPagename(title)
00251                     link = page.link_to(request, title)
00252                     items.append(link)
00253                 html = u'<div id="pagetrail">%s</div>' % u'<span class="sep"> &raquo; </span>'.join(items)
00254         return html
00255 
00256     def interwiki(self, d):
00257         """ Assemble the interwiki name display, linking to page_front_page
00258 
00259         @param d: parameter dictionary
00260         @rtype: string
00261         @return: interwiki html
00262         """
00263         if self.request.cfg.show_interwiki:
00264             page = wikiutil.getFrontPage(self.request)
00265             text = self.request.cfg.interwikiname or 'Self'
00266             link = page.link_to(self.request, text=text, rel='nofollow')
00267             html = u'<span id="interwiki">%s<span class="sep">: </span></span>' % link
00268         else:
00269             html = u''
00270         return html
00271 
00272 def execute(request):
00273     """
00274     Generate and return a theme object
00275 
00276     @param request: the request object
00277     @rtype: MoinTheme
00278     @return: Theme object
00279     """
00280     return Theme(request)
00281