Attachment 'modern_cms.py'

Download

   1 """
   2 Modern based cms theme
   3 ======================
   4 
   5 If you want to use a wiki as a tool to create a regular site easily,
   6 this theme is for you. The wiki looks like a plain site to visitors or
   7 users without edit rights, and a wiki to users with edits rights. 
   8 
   9 This is also a replacement for the readonly theme that was part of release 1.2.
  10 
  11 
  12 Problems
  13 --------
  14 Some actions are not available for visitors:
  15 
  16 - Show Raw Text
  17 - Show Print Preview
  18 - Show Like Pages
  19 - Show Local Site Map
  20 - Delete Cache
  21 
  22 Most of these are not really needed for a visitor. Print style sheet is
  23 used transparently when you print a page. Like Pages and Local Site Map
  24 should be available, but are not really needed if you have a good
  25 search.
  26 
  27 Missing page will suggest visitors to create a new page, but they will
  28 always fail because they don't have acl rights. This should be fixed in
  29 other place.
  30 
  31 
  32 Install
  33 -------
  34 
  35 1. Put in your wiki/data/plugin/theme/
  36 
  37 2. Prevent visitors from writing using acl::
  38 
  39     acl_rights_before = (u"WikiAdmin:read,write,delete,revert,admin "
  40                          u"EditorsGroup:read,write,delete,revert ")
  41     acl_rights_default = u"All:read "
  42                           
  43 Remember that acl you put on a page will override the default acl!
  44 
  45 3. Make it the default and only theme on your site::
  46 
  47     theme_default = 'modern_cms'
  48     theme_force = True
  49     
  50     
  51 Compatibility
  52 --------------
  53 Tested with release 1.3.5, should work with any 1.3 release.
  54 
  55 
  56 Legal
  57 -----
  58 @copyright (c) 2005 Nir Soffer <nirs@freeshell.org>
  59 
  60 This program is free software; you can redistribute it and/or modify
  61 it under the terms of the GNU General Public License as published by
  62 the Free Software Foundation; either version 2 of the License, or
  63 (at your option) any later version.
  64 
  65 This program is distributed in the hope that it will be useful,
  66 but WITHOUT ANY WARRANTY; without even the implied warranty of
  67 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  68 GNU General Public License for more details.
  69 
  70 You should have received a copy of the GNU General Public License
  71 along with this program; if not, write to the Free Software
  72 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  73 """
  74 
  75 from MoinMoin import wikiutil, config
  76 from MoinMoin.Page import Page
  77 from MoinMoin.theme import modern
  78 
  79 
  80 class Theme(modern.Theme):
  81     
  82     # Uses modern CSS and images
  83     name = "modern"
  84 
  85     def shouldShowEditbar(self, page):
  86         """ Hide the edit bar if you can't edit """
  87         if self.request.user.may.write(page.page_name):
  88             return modern.Theme.shouldShowEditbar(self, page)
  89         return False
  90 
  91     def navigation(self, d):
  92         """ Return page navigation interface 
  93         
  94         e.g. Parent/Child/Child, where each part is a link to that part. Some
  95         people call this bread crumbs.
  96         """
  97         if not config.allow_subpages:
  98             return ''
  99         links = []
 100         parents = d['page'].page_name.split('/')[:-1]
 101         parts = []
 102         for name in parents:
 103             parts.append(name)
 104             leaf = '/'.join(parts)
 105             link = Page(self.request, leaf).link_to(self.request, name)
 106             links.append(link)
 107         links = '/'.join(links)
 108         return u'<div id="navigation">\n%s\n</div>\n' % links
 109         
 110     def title(self, d):
 111         """ Return page title with optional navigation interface """
 112         _ = self.request.getText
 113         title = '<h1 id="title">%s</h1>'
 114         if d['title_link']:
 115             # Page views
 116             name = d['title_text']
 117             content = ('<a title="%(title)s" href="%(href)s">%(text)s</a>') % {
 118                 'title': _('Click to do a full-text search for this title'),
 119                 'href': d['title_link'],
 120                 'text': wikiutil.escape(self.pageLastName(name)),
 121                 }
 122             return self.navigation(d) + title % content
 123         else:
 124             # Search results and other actions
 125             return title % wikiutil.escape(d['title_text'])
 126 
 127     def pageLastName(self, name):
 128         """ This should be in the Page class, but its not """
 129         if not config.allow_subpages:
 130             return name
 131         return name[name.rfind('/') + 1:]
 132 
 133     def shortenPagename(self, name):
 134         """ Shorten page names
 135         
 136         This is a modified copy from theme/__init__.py. Modified to
 137         show only the last name of a page, even if there is room for
 138         the full name.
 139         """
 140         name = self.pageLastName(name)
 141         maxLength = self.maxPagenameLength()
 142         if len(name) > maxLength:
 143             half, left = divmod(maxLength - 3, 2)
 144             name = u'%s...%s' % (name[:half + left], name[-half:])
 145         return name
 146 
 147     def editbar(self, d):
 148         """ Return edit bar interface
 149         
 150         This is a copy of modern editbar, modified to remove the
 151         'Show Parent' link.
 152         """
 153         page = d['page']       
 154         if not self.shouldShowEditbar(page):
 155             return ''
 156 
 157         # Use cached editbar if possible.
 158         cacheKey = 'editbar'
 159         cached = self._cache.get(cacheKey)
 160         if cached:
 161             return cached
 162 
 163         # Make new edit bar
 164         request = self.request
 165         _ = self.request.getText
 166         link = wikiutil.link_tag
 167         quotedname = wikiutil.quoteWikinameURL(page.page_name)
 168         links = []
 169         add = links.append
 170         
 171         # Page actions
 172         if page.isWritable() and request.user.may.write(page.page_name):
 173             add(link(request, quotedname + '?action=edit', _('Edit')))
 174         else:
 175             add(_('Immutable Page', formatted=False))              
 176         
 177         add(link(request, quotedname + '?action=diff',
 178                  _('Show Changes', formatted=False)))
 179         add(link(request, quotedname + '?action=info',
 180                  _('Get Info', formatted=False)))
 181         add(self.subscribeLink(page))
 182         add(self.actionsMenu(page))
 183         
 184         # Format
 185         items = '\n'.join(['<li>%s</li>' % item for item in links 
 186                            if item != ''])
 187         html = u'<ul class="editbar">\n%s\n</ul>\n' % items
 188         
 189         # cache for next call
 190         self._cache[cacheKey] = html
 191         return html
 192 
 193 
 194 def execute(request):
 195     return Theme(request)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-12-02 20:43:13, 0.6 KB) [[attachment:login.diff]]
  • [get | view] (2005-08-21 19:25:43, 6.1 KB) [[attachment:modern_cms.py]]
  • [get | view] (2006-02-01 16:48:28, 3.2 KB) [[attachment:modern_cms15.py]]
  • [get | view] (2006-12-03 18:50:48, 0.4 KB) [[attachment:multiconfig_moin1-5-5-a-1.diff]]
  • [get | view] (2006-12-03 18:51:24, 0.4 KB) [[attachment:wikiaction_moin1-5-5-a-1.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.