~ubuntu-it-wiki/wiki-ubuntu-it/wiki-repo

« back to all changes in this revision

Viewing changes to data/plugin/theme/light.py

  • Committer: Leo Iannacone
  • Date: 2010-11-23 13:37:46 UTC
  • Revision ID: leo.iannacone@gmail.com-20101123133746-jnvr1g2tzvuba7h0
Added light theme from the lp:ubuntu-website/light-moin-theme branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin ubuntu theme
 
4
 
 
5
    @copyright: (c) 2003-2004 by Nir Soffer, Thomas Waldmann
 
6
    @license: GNU GPL, see COPYING for details.
 
7
 
 
8
    Borrows heavily from modern, a bit from Classic, and has a few 
 
9
    things of its own.
 
10
"""
 
11
 
 
12
from MoinMoin.theme import ThemeBase
 
13
from MoinMoin import wikiutil
 
14
from MoinMoin.Page import Page
 
15
 
 
16
 
 
17
class Theme(ThemeBase):
 
18
 
 
19
    name = 'light'
 
20
 
 
21
# Overriding theme/__init__.py #########################################
 
22
 
 
23
    # fake _ function to get gettext recognize those texts:
 
24
    _ = lambda x: x
 
25
       
 
26
    # TODO: remove icons that are not used any more.
 
27
    icons = {
 
28
        # key         alt                        icon filename      w   h
 
29
        # ------------------------------------------------------------------
 
30
        # navibar
 
31
        'help':       ("%(page_help_contents)s", "s-help.png",         20, 20),
 
32
        'find':       ("%(page_find_page)s",     "s-search.png",       20, 20),
 
33
        'diff':       (_("Diffs"),               "u-diff.png",         22, 22),
 
34
        'info':       (_("Info"),                "u-info.png",         22, 22),
 
35
        'edit':       (_("Edit"),                "u-edit.png",         20, 20),
 
36
        'unsubscribe':(_("Unsubscribe"),         "u-unsubscribe.png",  23, 21),
 
37
        'subscribe':  (_("Subscribe"),           "u-subscribe_dk.png", 23, 21),
 
38
        'raw':        (_("Raw"),                 "u-raw.png",          21, 23),
 
39
        'xml':        (_("XML"),                 "moin-xml2.png",      36, 14),
 
40
        'print':      (_("Print"),               "u-print.png",        20, 20),
 
41
        'view':       (_("View"),                "u-show.png",         20, 20),
 
42
        'home':       (_("Home"),                "u-home.png",         20, 20),
 
43
        'up':         (_("Up"),                  "u-parent.png",       20, 20),
 
44
        # FileAttach
 
45
        'attach':     ("%(attach_count)s",       "moin-attach.png",  7, 15),
 
46
        # RecentChanges
 
47
        'rss':        (_("[RSS]"),               "moin-rss.png",    36, 14),
 
48
        'deleted':    (_("[DELETED]"),           "u-deleted.png",      22, 22),
 
49
        'updated':    (_("[UPDATED]"),           "u-updated.png",      22, 22),
 
50
        'new':        (_("[NEW]"),               "u-new.png",          22, 22),
 
51
        'diffrc':     (_("[DIFF]"),              "u-diff.png",         22, 22),
 
52
        # General
 
53
        'bottom':     (_("[BOTTOM]"),            "u-bottom.png",       14, 10),
 
54
        'top':        (_("[TOP]"),               "u-top.png",          14, 10),
 
55
        'www':        ("[WWW]",                  "u-www.png",          16, 16),
 
56
        'mailto':     ("[MAILTO]",               "u-email.png",        23, 13),
 
57
        'news':       ("[NEWS]",                 "u-news.png",         16, 16),
 
58
        'telnet':     ("[TELNET]",               "u-telnet.png",       16, 16),
 
59
        'ftp':        ("[FTP]",                  "u-ftp.png",          16, 16),
 
60
        'file':       ("[FILE]",                 "u-ftp.png",          16, 16),
 
61
        # search forms
 
62
        'searchbutton': ("[?]",                  "s-search.png",       20, 20),
 
63
        'interwiki':  ("[%(wikitag)s]",          "u-inter.png",        16, 16),
 
64
        # smileys
 
65
        'X-(': ("Angry X-(","icon_mad.png",16,16),
 
66
        ':D': ("Big Grin :)","icon_biggrin.png",16,16),
 
67
        '<:(': ("Sad <:(","icon_sad.png",16,16),
 
68
        ':o': ("Surprised :o","icon_surprised.png",16,16),
 
69
        ':(': ("Sad :(","icon_sad.png",16,16),
 
70
        ':)': ("Smile :)","icon_smile.png",16,16),
 
71
        'B)': ("Awesome! B)","icon_cool.png",16,16),
 
72
        ':))': ("Funny :))","icon_razz.png",16,16),
 
73
        ';)': ("Wink ;)","icon_wink.png",16,16),
 
74
        '/!\\': ("Warning /!\\","icon_eek.png",16,16),
 
75
        '<!>': ("Info <!>","icon_cool.png",16,16),
 
76
        '(!)': ("Info (!)","icon_cool.png",16,16),
 
77
        ':-?': ("Tongue out :-?","icon_razz.png",16,16),
 
78
        '>:>': ("Angry >:>","icon_mad.png",16,16),#think this is meant to be devilish or something
 
79
        '|)': ("Smile |)","icon_smile.png",16,16),
 
80
        ':-(': ("Sad :-(","icon_sad.png",16,16),
 
81
        ':-)': ("Smile :-)","icon_smile.png",16,16),
 
82
        'B-)': ("Awesome B-)","icon_cool.png",16,16),
 
83
        ':\\': ("Confused :\\","icon_confused.png",16,16),
 
84
        ':-))': ("Funny :))","icon_razz.png",16,16),
 
85
        ';-)': ("Wink ;-)","icon_wink.png",16,16),
 
86
        '|-)': ("Smile |-)","icon_smile.png",16,16),
 
87
        '{*}': ("Ubuntu","icon_cof.png", 16,16),
 
88
        'renamed': ("Renamed","moin-renamed.png", 60,12),
 
89
        'conflict': ("Conflict","moin-conflict.png", 60,12),
 
90
        '(./)': ("(./)","checkmark.png", 16,16),
 
91
        '{OK}': ("(OK)","thumbs-up.png", 16,16),
 
92
        '{X}': ("(X)","icon-error.png", 16,16),
 
93
        '{i}': ("(i)","icon-info.png", 16,16), 
 
94
        '{1}': ("(1)","prio1.png", 16,16),
 
95
        '{2}': ("(2)","prio2.png", 16,16),
 
96
        '{3}': ("(3)","prio3.png", 16,16),
 
97
        '{o}': ("(o)","star_off.png", 16,16),
 
98
    }
 
99
    del _
 
100
 
 
101
# Public functions #####################################################
 
102
 
 
103
    def header(self, d, **kw):
 
104
        """ Assemble wiki header
 
105
        
 
106
        @param d: parameter dictionary
 
107
        @rtype: unicode
 
108
        @return: page header html
 
109
        """
 
110
        html = [
 
111
            # Pre header custom html
 
112
            self.emit_custom_html(self.cfg.page_header1),
 
113
            
 
114
            # Header
 
115
            u"""
 
116
    <div id="leftbanner">
 
117
    </div>
 
118
    <div id="rightbanner">
 
119
    </div>
 
120
    <div id="container">
 
121
        <div id="container-inner">
 
122
            <div id="header">
 
123
                <h1 id="ubuntu-header"><a href="http://www.ubuntu.com/">Ubuntu</a></h1>
 
124
                <ul id="main-menu">
 
125
                    <li><a href="http://www.ubuntu.com/desktop">Desktop</a></li>
 
126
                    <li><a href="http://www.ubuntu.com/netbook">Netbook</a></li>
 
127
                    <li><a href="http://www.ubuntu.com/server">Server</a></li>
 
128
                    <li><a href="http://www.ubuntu.com/cloud">Cloud</a></li>
 
129
                    <li><a href="http://www.ubuntu.com/support">Support</a></li>
 
130
                    <li><a href="http://www.ubuntu.com/project">Project</a></li>
 
131
                    <li class="active menuparent"><a href="http://www.ubuntu.com/community" class="active">Community</a></li>
 
132
                    <li><a href="http://www.ubuntu.com/partners">Partners</a></li>
 
133
                    <li><a href="http://shop.canonical.com/">Shop</a></li>
 
134
                </ul>
 
135
            </div>
 
136
            <div id="menu-search">
 
137
                <div id="subheader"> 
 
138
                    <div class="subheader-menu"> 
 
139
                        <div id="second-nav">""",
 
140
            self.username(d),
 
141
            """ </div> 
 
142
    <div id="user-info"> 
 
143
    </div>
 
144
 
 
145
 
 
146
                            
 
147
                        </div> 
 
148
                    </div> 
 
149
 
 
150
 
 
151
                    <div id="search-box">""",
 
152
            self.searchform(d),
 
153
            """
 
154
                    </div>
 
155
                </div>
 
156
                <div id="title"><h1>""",
 
157
                self.breadcrumb(d),
 
158
            u"""</h1>
 
159
                </div>
 
160
            <div id="cwt-nav3">""",
 
161
            self.editbar(d),
 
162
            """ <hr class="clear" />
 
163
            </div>
 
164
                <div id="cwt-content" class="clearfix content-area">""",
 
165
                self.msg(d),
 
166
            
 
167
            # Start of page
 
168
            self.startPage(),
 
169
            #self.title(d),
 
170
        ]
 
171
        return u'\n'.join(html)
 
172
 
 
173
    editorheader = header
 
174
        
 
175
    def breadcrumb(self, d):
 
176
        """ Build the breadcrumb
 
177
 
 
178
        @param d: parameter dectionary
 
179
        @return: breacrumb html
 
180
        """
 
181
        page_path = d['page'].split_title().split('/')
 
182
        page_path[0:0] = [self.request.cfg.sitename]
 
183
        if len(page_path) == 1:
 
184
            page_path[1] = u'' 
 
185
            # I don't think this should be needed but it's here
 
186
            # in case moin has some secret pages w/ no name
 
187
        # there's a diff between these two
 
188
        #  d['page'].split_title():
 
189
        #  wikiutil.escape(d['title_text']))
 
190
        return u'%s <span>%s</span>' % (page_path[-2], page_path[-1])
 
191
 
 
192
    def footer(self, d, **keywords):
 
193
        """ Assemble wiki footer
 
194
        
 
195
        @param d: parameter dictionary
 
196
        @keyword ...:...
 
197
        @rtype: unicode
 
198
        @return: page footer html
 
199
        """
 
200
        page = d['page']
 
201
        html = [
 
202
            # End of page
 
203
            self.endPage(),
 
204
            
 
205
            
 
206
            # Footer
 
207
            u"""
 
208
            </div>""",
 
209
            self.pageinfo(page),
 
210
            """</div>
 
211
            
 
212
            <div id="footer" class="clearfix">
 
213
                <div class="footer-div">
 
214
                    <p class="footer-title">Desktop</p>
 
215
                    <ul>
 
216
                        <li><a href="http://www.ubuntu.com/desktop/features">Features</a></li>
 
217
                        <li><a href="http://www.ubuntu.com/desktop/get-ubuntu">Get Ubuntu Desktop Edition</a></li>
 
218
                        <li><a href="http://www.ubuntu.com/desktop/services">Services</a></li>
 
219
                    </ul>
 
220
                </div>
 
221
                <div class="footer-div">
 
222
                    <p class="footer-title">Netbook</p>
 
223
                    <ul>
 
224
                        <li><a href="http://www.ubuntu.com/netbook/features">Features</a></li>
 
225
                        <li><a href="http://www.ubuntu.com/netbook/get-ubuntu">Get Ubuntu Netbook Edition</a></li>
 
226
                    </ul>
 
227
                </div>
 
228
                <div class="footer-div">
 
229
                    <p class="footer-title">Server</p>
 
230
                    <ul>
 
231
                        <li><a href="http://www.ubuntu.com/server/features">Features</a></li>
 
232
                        <li><a href="http://www.ubuntu.com/server/get-ubuntu">Get Ubuntu Server Edition</a></li>
 
233
                        <li><a href="http://www.ubuntu.com/server/services">Services</a></li>
 
234
                        <li><a href="http://www.ubuntu.com/server/technical-resources">Technical resources</a></li>
 
235
                    </ul>
 
236
                </div>
 
237
                <div class="footer-div">
 
238
                    <p class="footer-title">Cloud</p>
 
239
                    <ul>
 
240
                        <li><a href="http://www.ubuntu.com/cloud/why-ubuntu">Why Ubuntu?</a></li>
 
241
                        <li><a href="http://www.ubuntu.com/cloud/private">Private cloud</a></li>
 
242
                        <li><a href="http://www.ubuntu.com/cloud/public">Public cloud</a></li>
 
243
                        <li><a href="http://www.ubuntu.com/cloud/services">Services</a></li>
 
244
                    </ul>
 
245
                </div>
 
246
                <div class="footer-div">
 
247
                    <p class="footer-title">Support</p>
 
248
                    <ul>
 
249
                        <li><a href="http://www.ubuntu.com/support/community">Community</a></li>
 
250
                        <li><a href="http://www.ubuntu.com/support/training">Training</a></li>
 
251
                        <li><a href="http://www.ubuntu.com/support/services">Services</a></li>
 
252
                        <li><a href="http://www.ubuntu.com/usn">Security notices</a></li>
 
253
                    </ul>
 
254
                </div>
 
255
                <div class="footer-div">
 
256
                    <p class="footer-title">Project</p>
 
257
                    <ul>
 
258
                        <li><a href="http://www.ubuntu.com/project/about-ubuntu">About Ubuntu</a></li>
 
259
                        <li><a href="http://www.ubuntu.com/project/canonical-and-ubuntu">Canonical and Ubuntu</a></li>
 
260
                        <li><a href="http://www.ubuntu.com/project/open-source">Open source</a></li>
 
261
                        <li><a href="http://www.ubuntu.com/project/case-studies">Case studies</a></li>
 
262
                        <li><a href="http://www.ubuntu.com/project/derivatives">Derivatives</a></li>
 
263
                    </ul>
 
264
                </div>
 
265
                <div class="footer-div">
 
266
                    <p class="footer-title">Community</p>
 
267
                    <ul>
 
268
                        <li><a href="http://www.ubuntu.com/community/conduct">Code of conduct</a></li>
 
269
                        <li><a href="http://www.ubuntu.com/community/get-involved">Get involved</a></li>
 
270
                        <li><a href="http://www.ubuntu.com/community/report-problem">Report a problem</a></li>
 
271
                        <li><a href="http://www.ubuntu.com/community/ubuntu-and-debian">Ubuntu and Debian</a></li>
 
272
                    </ul>
 
273
                </div>
 
274
                <div class="footer-div">
 
275
                    <p class="footer-title">Partners</p>
 
276
                    <ul>
 
277
                        <li><a href="http://www.ubuntu.com/partners/programme">Partner programme</a></li>
 
278
                        <li><a href="http://partners.canonical.com/">Find a partner</a></li>
 
279
                        <li><a href="https://certification.canonical.com/">Certified Hardware</a></li>
 
280
                    </ul>
 
281
                </div>
 
282
                <div class="footer-div">
 
283
                    <p class="footer-title">Further Information</p>
 
284
                    <ul>
 
285
                        <li><a href="http://www.ubuntu.com/contact-us">Contact us</a></li>
 
286
                        <li><a href="http://www.ubuntu.com/trademarkpolicy">Trademark policy</a></li>
 
287
                        <li><a href="http://www.ubuntu.com/legal">Legal information</a></li>
 
288
                        <li><a href="http://www.canonical.com/about-canonical/careers">Careers</a></li>
 
289
                        <li><a href="http://www.ubuntu.com/rss.xml" class="newsfeed">Canonical news feed</a></li>
 
290
                    </ul>
 
291
                </div>
 
292
            </div>
 
293
            <div id="copyright">
 
294
                <p>&copy; 2010 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
 
295
                <a href="http://www.ubuntu.com/"><img src="/assets/light/images/footer_logo.png" alt="Ubuntu" /></a></p>
 
296
            </div>
 
297
        </div>"""
 
298
        ]
 
299
        return u'\n'.join(html)
 
300
 
 
301
    def extranav(self, d):
 
302
        """ Assemble the helpful extra navigation
 
303
 
 
304
    Of course in a normal theme these come from wikiconfig.py 
 
305
        
 
306
        @param d: parameter dictionary
 
307
        @rtype: unicode
 
308
        @return: extranav html
 
309
        """
 
310
        request = self.request
 
311
        _ = request.getText
 
312
        #changesPage = wikiutil.getSysPage(request, 'RecentChanges')
 
313
        changesPage = wikiutil.getLocalizedPage(request, 'UserPreferences')
 
314
        #findPage = wikiutil.getSysPage(request, 'FindPage')
 
315
        findPage = wikiutil.getLocalizedPage(request, 'FindPage')
 
316
        
 
317
        extralinks = []
 
318
        # Set page to localized RC page
 
319
        title = changesPage.split_title(request)
 
320
        extralinks.append(changesPage.link_to(request, text=title))
 
321
        # Set page to localized find page
 
322
        title = findPage.split_title(request)
 
323
        extralinks.append(findPage.link_to(request, text=title))
 
324
            
 
325
        extralinks = [u'<li>%s</li>\n' % link for link in extralinks]
 
326
        html = u'<ul class="extranav">\n%s</ul>' % ''.join(extralinks)
 
327
        return html
 
328
 
 
329
    def navibar(self, d):
 
330
        """ Assemble the navibar
 
331
 
 
332
        @param d: parameter dictionary
 
333
        @rtype: unicode
 
334
        @return: navibar html
 
335
        """
 
336
        request = self.request
 
337
        found = {} # pages we found. prevent duplicates
 
338
        items = [] # navibar items
 
339
        item = u'<li class="%s">%s</li>'
 
340
        current = d['page_name']
 
341
 
 
342
        # Add user links to wiki links, eliminating duplicates.
 
343
        userlinks = request.user.getQuickLinks()
 
344
        for text in userlinks:
 
345
            # Split text without localization, user know what she wants
 
346
            pagename, link = self.splitNavilink(text, localize=0)
 
347
            if not pagename in found:
 
348
                cls = 'userlink'
 
349
                if pagename == current:
 
350
                    cls = 'userlink current'
 
351
                items.append(item % (cls, link))
 
352
                found[pagename] = 1
 
353
 
 
354
        # Assemble html
 
355
        items = u'\n'.join(items)
 
356
        html = u'''
 
357
<ul id="navibar">
 
358
%s
 
359
</ul>
 
360
''' % items
 
361
        return html
 
362
 
 
363
    def username(self, d):
 
364
        """ Assemble the username / userprefs link
 
365
        
 
366
        @param d: parameter dictionary
 
367
        @rtype: unicode
 
368
        @return: username html
 
369
        """
 
370
        request = self.request
 
371
        _ = request.getText
 
372
        
 
373
        preferencesPage = wikiutil.getLocalizedPage(request, 'UserPreferences')
 
374
        
 
375
        helpPage = wikiutil.getLocalizedPage(request, 'HelpContents')
 
376
        
 
377
        userlinks = []
 
378
        # Add username/homepage link for registered users. We don't care
 
379
        # if it exists, the user can create it.
 
380
        if request.user.valid:
 
381
            homepage = Page(request, self.request.cfg.page_front_page)
 
382
            homepage_link = homepage.link_to(request, text=self.request.cfg.sitename)
 
383
            userlinks.append(homepage_link)
 
384
            userpage = Page(request, request.user.name)
 
385
            title = userpage.split_title(request)
 
386
            homelink = preferencesPage.link_to(request, text=title)
 
387
            userlinks.append(homelink)
 
388
            # logout link
 
389
            logout = _("Logout")
 
390
            userlinks.append("""<a href="?action=logout&logout=logout">%s</a>""" % logout)
 
391
        else:
 
392
            homepage = Page(request, self.request.cfg.page_front_page)
 
393
            homepage_link = homepage.link_to(request, text=self.request.cfg.sitename)
 
394
            userlinks.append(homepage_link)
 
395
            # Add prefpage links with title: Login
 
396
            login = _("Login")
 
397
            userlinks.append("""<a href="?action=login">%s</a>""" % login)
 
398
        userlinks.append(helpPage.link_to(request, text=_("Help")))
 
399
        userlinks = [u'<li>%s</li>\n' % link for link in userlinks]
 
400
        html = u'<ul id="username">\n%s</ul>' % ''.join(userlinks)
 
401
        return html
 
402
 
 
403
    def footerlinks(self):
 
404
        """ Copyright notices and local links
 
405
 
 
406
        Nice and boring compared to the other stuff. 
 
407
        
 
408
        @rtype: unicode
 
409
        @return: extra footer html
 
410
        """
 
411
 
 
412
        html = u'''
 
413
  <div id="ubuntulinks">
 
414
     &copy; 2008 <a href="http://www.canonical.com">Canonical Ltd</a>. Ubuntu, Kubuntu, Edubuntu, Xubuntu and Canonical are registered trademarks of Canonical Ltd.<br />
 
415
     <a href="http://www.ubuntu.com/about-us">Feedback</a> &mdash; 
 
416
     <a href="http://www.ubuntu.com/legal">Legal</a> &mdash; 
 
417
     <a href="https://wiki.ubuntu.com/wiki/credits">Credits</a> &mdash; 
 
418
     <a href="http://www.ubuntu.com/sitemap">Site Map</a> &mdash;
 
419
     <a href="http://moinmoin.wikiwikiweb.de/">Powered By the MoinMoin Wiki Engine</a>
 
420
  </div>
 
421
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
 
422
</script>
 
423
<script type="text/javascript">
 
424
_uacct = "UA-1018242-7";
 
425
urchinTracker();
 
426
__utmSetVar('UbuntuWiki');
 
427
</script>
 
428
%s
 
429
''' % self.breadcrumb(d)
 
430
        return html
 
431
        return u''
 
432
 
 
433
        
 
434
def execute(request):
 
435
    """
 
436
    Generate and return a theme object
 
437
        
 
438
    @param request: the request object
 
439
    @rtype: MoinTheme
 
440
    @return: Theme object
 
441
    """
 
442
    return Theme(request)
 
443