paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - ep2008 (EuroPython 2008) theme |
paul@0 | 4 | |
paul@0 | 5 | @copyright: 2003-2007 by Nir Soffer, Thomas Waldmann, Paul Boddie |
paul@0 | 6 | @license: GNU GPL, see COPYING for details. |
paul@0 | 7 | """ |
paul@0 | 8 | |
paul@0 | 9 | from MoinMoin.theme import ThemeBase |
paul@12 | 10 | from MoinMoin.action import AttachFile |
paul@12 | 11 | import random |
paul@0 | 12 | |
paul@0 | 13 | class Theme(ThemeBase): |
paul@0 | 14 | |
paul@0 | 15 | name = "ep2008" |
paul@0 | 16 | |
paul@0 | 17 | def header(self, d, **kw): |
paul@0 | 18 | """ Assemble wiki header |
paul@0 | 19 | |
paul@0 | 20 | @param d: parameter dictionary |
paul@0 | 21 | @rtype: unicode |
paul@0 | 22 | @return: page header html |
paul@0 | 23 | """ |
paul@0 | 24 | html = [ |
paul@0 | 25 | # Pre header custom html |
paul@0 | 26 | self.emit_custom_html(self.cfg.page_header1), |
paul@0 | 27 | |
paul@0 | 28 | # Header |
paul@0 | 29 | u'<div id="header">', |
paul@0 | 30 | self.logo(), |
paul@0 | 31 | |
paul@0 | 32 | # Banner |
paul@12 | 33 | self.banner(d), |
paul@0 | 34 | |
paul@0 | 35 | self.searchform(d), |
paul@0 | 36 | self.navibar(d), |
paul@0 | 37 | self.msg(d), |
paul@0 | 38 | |
paul@0 | 39 | # NOTE: Hack everything into the header |
paul@0 | 40 | u'<div id="end-of-header">', |
paul@0 | 41 | u'</div>', |
paul@0 | 42 | u'</div>', |
paul@0 | 43 | |
paul@0 | 44 | # Post header custom html (not recommended) |
paul@0 | 45 | self.emit_custom_html(self.cfg.page_header2), |
paul@0 | 46 | |
paul@0 | 47 | # Start of page |
paul@0 | 48 | u'<div class="page-%s">' % d['page_name'], |
paul@0 | 49 | self.startPage(), |
paul@0 | 50 | ] |
paul@0 | 51 | return u'\n'.join(html) |
paul@0 | 52 | |
paul@0 | 53 | def editorheader(self, d, **kw): |
paul@0 | 54 | """ Assemble wiki header for editor |
paul@0 | 55 | |
paul@0 | 56 | @param d: parameter dictionary |
paul@0 | 57 | @rtype: unicode |
paul@0 | 58 | @return: page header html |
paul@0 | 59 | """ |
paul@0 | 60 | html = [ |
paul@0 | 61 | # Pre header custom html |
paul@0 | 62 | self.emit_custom_html(self.cfg.page_header1), |
paul@0 | 63 | |
paul@0 | 64 | # Header |
paul@0 | 65 | u'<div id="header">', |
paul@0 | 66 | self.title(d), |
paul@0 | 67 | self.msg(d), |
paul@0 | 68 | u'</div>', |
paul@0 | 69 | |
paul@0 | 70 | # Post header custom html (not recommended) |
paul@0 | 71 | self.emit_custom_html(self.cfg.page_header2), |
paul@0 | 72 | |
paul@0 | 73 | # Start of page |
paul@0 | 74 | u'<div class="page-%s">' % d['page_name'], |
paul@0 | 75 | self.startPage(), |
paul@0 | 76 | ] |
paul@0 | 77 | return u'\n'.join(html) |
paul@0 | 78 | |
paul@0 | 79 | def footer(self, d, **keywords): |
paul@0 | 80 | """ Assemble wiki footer |
paul@0 | 81 | |
paul@0 | 82 | @param d: parameter dictionary |
paul@0 | 83 | @keyword ...:... |
paul@0 | 84 | @rtype: unicode |
paul@0 | 85 | @return: page footer html |
paul@0 | 86 | """ |
paul@0 | 87 | page = d['page'] |
paul@11 | 88 | |
paul@11 | 89 | if self.cfg.special_username: |
paul@11 | 90 | username = self.specialUsername(d) |
paul@11 | 91 | else: |
paul@11 | 92 | username = self.username(d) |
paul@11 | 93 | |
paul@0 | 94 | html = [ |
paul@0 | 95 | # End of page |
paul@0 | 96 | self.pageinfo(page), |
paul@0 | 97 | self.endPage(), |
paul@0 | 98 | u'</div>', |
paul@0 | 99 | |
paul@0 | 100 | # Pre footer custom html (not recommended!) |
paul@0 | 101 | self.emit_custom_html(self.cfg.page_footer1), |
paul@0 | 102 | |
paul@0 | 103 | # Footer |
paul@0 | 104 | u'<div id="footer">', |
paul@0 | 105 | self.cfg.contact_string, |
paul@10 | 106 | u'<div id="contribute">', |
paul@10 | 107 | #self.cfg.contribute_string, |
paul@10 | 108 | #u'<div class="contribute-hidden">', |
paul@10 | 109 | #self.username(d), |
paul@10 | 110 | #u'<div id="locationline">', |
paul@10 | 111 | #self.interwiki(d), |
paul@10 | 112 | #self.title(d), |
paul@10 | 113 | #u'</div>', |
paul@11 | 114 | username, |
paul@10 | 115 | self.editbar(d), |
paul@0 | 116 | self.trail(d), |
paul@10 | 117 | #u'</div>', |
paul@0 | 118 | u'</div>', |
paul@0 | 119 | self.credits(d), |
paul@0 | 120 | self.showversion(d, **keywords), |
paul@0 | 121 | u'</div>', |
paul@0 | 122 | |
paul@0 | 123 | # Post footer custom html |
paul@0 | 124 | self.emit_custom_html(self.cfg.page_footer2), |
paul@0 | 125 | ] |
paul@0 | 126 | return u'\n'.join(html) |
paul@0 | 127 | |
paul@10 | 128 | def editbarItems(self, page): |
paul@10 | 129 | """ Return list of items to show on the editbar |
paul@10 | 130 | |
paul@10 | 131 | This is separate method to make it easy to customize the |
paul@10 | 132 | editbar in sub classes. |
paul@10 | 133 | """ |
paul@10 | 134 | |
paul@10 | 135 | request = self.request |
paul@10 | 136 | |
paul@10 | 137 | items = [self.editorLink(page), |
paul@10 | 138 | self.infoLink(page), |
paul@10 | 139 | self.subscribeLink(page), |
paul@10 | 140 | self.quicklinkLink(page),] |
paul@10 | 141 | |
paul@10 | 142 | if page.isWritable() and request.user.valid and request.user.may.write(page.page_name): |
paul@10 | 143 | items.append(self.attachmentsLink(page)) |
paul@10 | 144 | |
paul@10 | 145 | if request.user.valid: |
paul@10 | 146 | items.append(self.actionsMenu(page)) |
paul@10 | 147 | |
paul@10 | 148 | return items |
paul@10 | 149 | |
paul@10 | 150 | def specialUsername(self, d): |
paul@10 | 151 | request = self.request |
paul@10 | 152 | _ = request.getText |
paul@10 | 153 | |
paul@10 | 154 | if request.user.valid and request.user.name: |
paul@10 | 155 | return u'<div class="username">%s</div>' % request.formatter.text(request.user.name) |
paul@10 | 156 | else: |
paul@10 | 157 | # NOTE: Using the contribute string! |
paul@10 | 158 | return u'<div class="no-username">%s</div>' % \ |
paul@10 | 159 | d['page'].link_to(request, text=self.cfg.contribute_string, |
paul@10 | 160 | querystr={'action': 'login'}, id="login") |
paul@10 | 161 | |
paul@12 | 162 | def banner(self, d): |
paul@12 | 163 | request = self.request |
paul@12 | 164 | formatter = request.formatter |
paul@12 | 165 | |
paul@12 | 166 | # Either get banners per page or acquire them from a central source. |
paul@12 | 167 | |
paul@12 | 168 | if self.cfg.banner_per_page: |
paul@12 | 169 | pagename = d["page"].page_name |
paul@12 | 170 | else: |
paul@12 | 171 | pagename = self.cfg.banner_attachment_page |
paul@12 | 172 | |
paul@12 | 173 | # Only get attachments with a certain prefix. |
paul@12 | 174 | |
paul@12 | 175 | attachments = [] |
paul@12 | 176 | for filename in AttachFile._get_files(request, pagename): |
paul@12 | 177 | if filename.startswith(self.cfg.banner_prefix): |
paul@12 | 178 | attachments.append(filename) |
paul@12 | 179 | |
paul@12 | 180 | # Display the default banner if no attachments are found. |
paul@12 | 181 | |
paul@12 | 182 | if not attachments: |
paul@12 | 183 | return self.cfg.banner_string |
paul@12 | 184 | |
paul@12 | 185 | # Choose an attachment at random and return the HTML to show it. |
paul@12 | 186 | |
paul@12 | 187 | attachment = random.choice(attachments) |
paul@12 | 188 | |
paul@12 | 189 | kw = {} |
paul@12 | 190 | kw['src'] = AttachFile.getAttachUrl(pagename, attachment, request) |
paul@12 | 191 | kw['alt'] = self.cfg.banner_alt_text |
paul@12 | 192 | kw['id'] = u'banner' |
paul@12 | 193 | |
paul@12 | 194 | target = self.cfg.banner_link_page |
paul@12 | 195 | |
paul@12 | 196 | return "%s%s%s" % (formatter.pagelink(1, target), |
paul@12 | 197 | formatter.image(**kw), |
paul@12 | 198 | formatter.pagelink(0)) |
paul@12 | 199 | |
paul@0 | 200 | def execute(request): |
paul@0 | 201 | """ |
paul@0 | 202 | Generate and return a theme object |
paul@0 | 203 | |
paul@0 | 204 | @param request: the request object |
paul@0 | 205 | @rtype: MoinTheme |
paul@0 | 206 | @return: Theme object |
paul@0 | 207 | """ |
paul@0 | 208 | return Theme(request) |
paul@0 | 209 | |
paul@0 | 210 | # vim: tabstop=4 expandtab shiftwidth=4 |