MercurialWikiTheme

Annotated themes/mercurialwiki/mercurialwiki.py

16:d3873556a599
2010-06-09 Paul Boddie Made the page trail and user controls larger.
paul@0 1
# -*- coding: iso-8859-1 -*-
paul@0 2
paul@0 3
"""
paul@0 4
    MoinMoin - MercurialWiki theme
paul@0 5
    @copyright: 2009, 2010 Paul Boddie <paul@boddie.org.uk>
paul@0 6
    @copyright: (portions) 2003-2008 MoinMoin:ThomasWaldmann, 2003-2005 Nir Soffer
paul@0 7
    @license: GNU GPL (v2 or later), see COPYING.txt for details.
paul@0 8
"""
paul@0 9
paul@0 10
from MoinMoin.theme import ThemeBase
paul@0 11
from MoinMoin import i18n
paul@0 12
from MoinMoin import wikiutil
paul@0 13
from MoinMoin import version
paul@0 14
from MoinMoin.Page import Page
paul@0 15
import re
paul@0 16
paul@0 17
class Theme(ThemeBase):
paul@0 18
paul@0 19
    name = "mercurialwiki"
paul@0 20
paul@0 21
    # Icon definitions from the modernized theme...
paul@0 22
paul@0 23
    _ = lambda x: x     # We don't have gettext at this moment, so we fake it
paul@0 24
    icons = {
paul@0 25
        # key         alt                        icon filename      w   h
paul@0 26
        # FileAttach
paul@0 27
        'attach':     ("%(attach_count)s",       "moin-attach.png",   16, 16),
paul@0 28
        'info':       ("[INFO]",                 "moin-info.png",     16, 16),
paul@0 29
        'attachimg':  (_("[ATTACH]"),            "attach.png",        32, 32),
paul@0 30
        # RecentChanges
paul@0 31
        'rss':        (_("[RSS]"),               "moin-rss.png",      16, 16),
paul@0 32
        'deleted':    (_("[DELETED]"),           "moin-deleted.png",  16, 16),
paul@0 33
        'updated':    (_("[UPDATED]"),           "moin-updated.png",  16, 16),
paul@0 34
        'renamed':    (_("[RENAMED]"),           "moin-renamed.png",  16, 16),
paul@0 35
        'conflict':   (_("[CONFLICT]"),          "moin-conflict.png", 16, 16),
paul@0 36
        'new':        (_("[NEW]"),               "moin-new.png",      16, 16),
paul@0 37
        'diffrc':     (_("[DIFF]"),              "moin-diff.png",     16, 16),
paul@0 38
        # General
paul@0 39
        'bottom':     (_("[BOTTOM]"),            "moin-bottom.png",   16, 16),
paul@0 40
        'top':        (_("[TOP]"),               "moin-top.png",      16, 16),
paul@0 41
        'www':        ("[WWW]",                  "moin-www.png",      16, 16),
paul@0 42
        'mailto':     ("[MAILTO]",               "moin-email.png",    16, 16),
paul@0 43
        'news':       ("[NEWS]",                 "moin-news.png",     16, 16),
paul@0 44
        'telnet':     ("[TELNET]",               "moin-telnet.png",   16, 16),
paul@0 45
        'ftp':        ("[FTP]",                  "moin-ftp.png",      16, 16),
paul@0 46
        'file':       ("[FILE]",                 "moin-ftp.png",      16, 16),
paul@0 47
        # search forms
paul@0 48
        'searchbutton': ("[?]",                  "moin-search.png",   16, 16),
paul@0 49
        'interwiki':  ("[%(wikitag)s]",          "moin-inter.png",    16, 16),
paul@0 50
paul@0 51
        # smileys (this is CONTENT, but good looking smileys depend on looking
paul@0 52
        # adapted to the theme background color and theme style in general)
paul@0 53
        #vvv    ==      vvv  this must be the same for GUI editor converter
paul@0 54
        'X-(':        ("X-(",                    'angry.png',         16, 16),
paul@0 55
        ':D':         (":D",                     'biggrin.png',       16, 16),
paul@0 56
        '<:(':        ("<:(",                    'frown.png',         16, 16),
paul@0 57
        ':o':         (":o",                     'redface.png',       16, 16),
paul@0 58
        ':(':         (":(",                     'sad.png',           16, 16),
paul@0 59
        ':)':         (":)",                     'smile.png',         16, 16),
paul@0 60
        'B)':         ("B)",                     'smile2.png',        16, 16),
paul@0 61
        ':))':        (":))",                    'smile3.png',        16, 16),
paul@0 62
        ';)':         (";)",                     'smile4.png',        16, 16),
paul@0 63
        '/!\\':       ("/!\\",                   'alert.png',         16, 16),
paul@0 64
        '<!>':        ("<!>",                    'attention.png',     16, 16),
paul@0 65
        '(!)':        ("(!)",                    'idea.png',          16, 16),
paul@0 66
        ':-?':        (":-?",                    'tongue.png',        16, 16),
paul@0 67
        ':\\':        (":\\",                    'ohwell.png',        16, 16),
paul@0 68
        '>:>':        (">:>",                    'devil.png',         16, 16),
paul@0 69
        '|)':         ("|)",                     'tired.png',         16, 16),
paul@0 70
        ':-(':        (":-(",                    'sad.png',           16, 16),
paul@0 71
        ':-)':        (":-)",                    'smile.png',         16, 16),
paul@0 72
        'B-)':        ("B-)",                    'smile2.png',        16, 16),
paul@0 73
        ':-))':       (":-))",                   'smile3.png',        16, 16),
paul@0 74
        ';-)':        (";-)",                    'smile4.png',        16, 16),
paul@0 75
        '|-)':        ("|-)",                    'tired.png',         16, 16),
paul@0 76
        '(./)':       ("(./)",                   'checkmark.png',     16, 16),
paul@0 77
        '{OK}':       ("{OK}",                   'thumbs-up.png',     16, 16),
paul@0 78
        '{X}':        ("{X}",                    'icon-error.png',    16, 16),
paul@0 79
        '{i}':        ("{i}",                    'icon-info.png',     16, 16),
paul@0 80
        '{1}':        ("{1}",                    'prio1.png',         15, 13),
paul@0 81
        '{2}':        ("{2}",                    'prio2.png',         15, 13),
paul@0 82
        '{3}':        ("{3}",                    'prio3.png',         15, 13),
paul@0 83
        '{*}':        ("{*}",                    'star_on.png',       16, 16),
paul@0 84
        '{o}':        ("{o}",                    'star_off.png',      16, 16),
paul@0 85
    }
paul@0 86
    del _
paul@0 87
paul@0 88
    def header(self, d, **kw):
paul@0 89
        """ Assemble page header
paul@0 90
paul@0 91
        @param d: parameter dictionary
paul@0 92
        @rtype: unicode
paul@0 93
        @return: page header html
paul@0 94
        """
paul@0 95
paul@0 96
        request = self.request
paul@0 97
        fmt = request.formatter
paul@0 98
        html = []
paul@0 99
paul@0 100
        # NOTE: Some pages cause section numbers to be enabled, affecting the
paul@0 101
        # NOTE: theme.
paul@0 102
paul@0 103
        show_section_numbers = fmt._show_section_numbers
paul@0 104
        fmt._show_section_numbers = 0
paul@0 105
paul@0 106
        # The header section.
paul@0 107
paul@0 108
        html.append(fmt.div(on=1, attr={"id" : "header"}))
paul@0 109
paul@0 110
        html.append(self.logo())
paul@5 111
paul@5 112
        html.append(fmt.div(on=1, attr={"class" : "controls"}))
paul@5 113
        html.append(self.navibar(d).strip())
paul@5 114
        html.append(self.searchform(d).strip())
paul@5 115
        html.append(fmt.div(on=0))
paul@2 116
paul@2 117
        # A separator.
paul@2 118
paul@2 119
        html.append(fmt.div(on=1, attr={"class" : "pageline"}))
paul@0 120
        html.append(fmt.div(on=0))
paul@0 121
paul@11 122
        html.append(self.trail(d))
paul@7 123
        html.append(self.username(d))
paul@7 124
paul@7 125
        html.append(fmt.div(on=0))
paul@7 126
paul@0 127
        # Show any pertinent message.
paul@0 128
paul@0 129
        html.append(self.msg(d))
paul@0 130
paul@0 131
        # Complete the header.
paul@0 132
paul@0 133
        html.append(self.startPage())
paul@0 134
paul@0 135
        # NOTE: Some pages cause section numbers to be enabled, affecting the
paul@0 136
        # NOTE: theme.
paul@0 137
paul@0 138
        fmt._show_section_numbers = show_section_numbers
paul@0 139
paul@0 140
        return u''.join(html)
paul@0 141
paul@0 142
    editorheader = header
paul@0 143
paul@0 144
    def footer(self, d, **kw):
paul@0 145
        """ Assemble page footer
paul@0 146
paul@0 147
        @param d: parameter dictionary
paul@0 148
        @rtype: unicode
paul@0 149
        @return: page footer html
paul@0 150
        """
paul@0 151
paul@0 152
        request = self.request
paul@0 153
        fmt = request.formatter
paul@0 154
        _ = request.getText
paul@0 155
        page = d["page"]
paul@0 156
        html = []
paul@0 157
paul@0 158
        # NOTE: Some pages cause section numbers to be enabled, affecting the
paul@0 159
        # NOTE: theme.
paul@0 160
paul@0 161
        show_section_numbers = fmt._show_section_numbers
paul@0 162
        fmt._show_section_numbers = 0
paul@0 163
paul@0 164
        # End the page.
paul@0 165
paul@0 166
        html.append(self.endPage())
paul@0 167
paul@0 168
        # The footer section.
paul@0 169
paul@0 170
        html.append(fmt.div(on=1, attr={"id" : "footer"}))
paul@0 171
paul@0 172
        if self.shouldShowEditbar(page):
paul@5 173
            html.append(fmt.div(on=1, attr={"class" : "controls"}))
paul@0 174
            html.append(self.editbar(d))
paul@5 175
            html.append(fmt.div(on=0))
paul@2 176
paul@2 177
        # A separator.
paul@2 178
paul@2 179
        html.append(fmt.div(on=1, attr={"class" : "pageline"}))
paul@2 180
        html.append(fmt.div(on=0))
paul@2 181
paul@0 182
        html.append(self.credits(d))
paul@0 183
paul@0 184
        #html.append(self.trail(d))
paul@0 185
paul@0 186
        html.append(fmt.div(on=0))
paul@0 187
paul@0 188
        # NOTE: Some pages cause section numbers to be enabled, affecting the
paul@0 189
        # NOTE: theme.
paul@0 190
paul@0 191
        fmt._show_section_numbers = show_section_numbers
paul@0 192
paul@0 193
        return u''.join(html)
paul@0 194
paul@5 195
    def actionsMenu(self, page):
paul@5 196
paul@5 197
        """ An overridden version of the actions menu
paul@5 198
paul@5 199
        This method strips the adjacent white-space from the generated menu.
paul@5 200
paul@5 201
        @param page: current page, Page object
paul@5 202
        @rtype: unicode
paul@5 203
        @return: actions menu html fragment
paul@5 204
        """
paul@5 205
paul@5 206
        return ThemeBase.actionsMenu(self, page).strip()
paul@5 207
paul@0 208
# Theme instantiation.
paul@0 209
paul@0 210
def execute(request):
paul@0 211
    """
paul@0 212
    Generate and return a theme object
paul@0 213
paul@0 214
    @param request: the request object
paul@0 215
    @rtype: MoinTheme
paul@0 216
    @return: Theme object
paul@0 217
    """
paul@0 218
    return Theme(request)
paul@0 219
paul@0 220
# vim: tabstop=4 expandtab shiftwidth=4