Blame Identity/Webenv/Themes/Default/Moin/1.5.9/Modern.py

af7431
# -*- coding: iso-8859-1 -*-
af7431
"""
af7431
    MoinMoin - Modern Theme
af7431
af7431
    Created for the CentOS Project Wiki. This is a
af7431
    modification of the MoinMoin's modern default
af7431
    wiki theme, and a continuation of previous
af7431
    modern-CentOS theme.
af7431
af7431
    @copyright: 2008 by The CentOS ArtWork SIG.
af7431
    @license: GNU GPL, see COPYING for details.  
af7431
"""
af7431
af7431
from MoinMoin.theme import ThemeBase
af7431
from MoinMoin import wikiutil
af7431
af7431
class Theme(ThemeBase):
af7431
af7431
    name = "Modern"
af7431
af7431
    def header(self, d):
af7431
        """
af7431
        Assemble page header
af7431
        
af7431
        @param d: parameter dictionary
af7431
        @rtype: string
af7431
        @return: page header html
af7431
        """
af7431
af7431
        html = [
af7431
af7431
            # Header
af7431
            u'
',
af7431
            u'
af7431
            self.logo(),
af7431
            u'
af7431
            self.searchform(d),
af7431
            self.username(d),
af7431
            self.trail(d),
af7431
            u'',
af7431
	        self.navibar(d),
af7431
    	    u'

',
af7431
     	    self.editbar(d),
af7431
            u'',
af7431
af7431
            # Page
af7431
            self.msg(d),
af7431
            self.startPage(),
af7431
            ]
af7431
        return u'\n'.join(html)
af7431
af7431
    def editorheader(self, d):
af7431
        """
af7431
        Assemble page header for editor
af7431
        
af7431
        @param d: parameter dictionary
af7431
        @rtype: string
af7431
        @return: page header html
af7431
        """
af7431
af7431
        html = [
af7431
            # Custom html above header
af7431
            #self.emit_custom_html(self.cfg.page_header1),
af7431
af7431
            # Header
44f35b
            u'
',
af7431
            u'
af7431
            self.logo(),
af7431
            u'
af7431
            self.searchform(d),
af7431
            self.username(d),
af7431
            self.trail(d),
af7431
            u'',
af7431
    	    u'

',
af7431
            u'',
af7431
af7431
            # Custom html below header (not recomended!)
af7431
            # self.emit_custom_html(self.cfg.page_header2),
af7431
            
af7431
            # Page
af7431
            self.msg(d),
af7431
            u'
',
af7431
	        self.title(d),
af7431
            u'',
af7431
            ]
af7431
        return u'\n'.join(html)
af7431
af7431
    def footer(self, d, **keywords):
af7431
        """ Assemble wiki footer
af7431
        
af7431
        @param d: parameter dictionary
af7431
        @keyword ...:...
af7431
        @rtype: unicode
af7431
        @return: page footer html
af7431
        """
af7431
        page = d['page']
af7431
        html = [
af7431
            # End of page
af7431
            self.pageinfo(page),
af7431
            self.endPage(),
af7431
af7431
            # Pre footer custom html (not recommended!)
af7431
            # self.emit_custom_html(self.cfg.page_footer1),
af7431
af7431
            # Footer
af7431
	        u'
af7431
            self.editbar(d),
af7431
    	    u'

',
af7431
            self.navibar(d),
af7431
            self.credits(d),
af7431
            #self.showversion(d, **keywords),
af7431
            u'',
af7431
            u'',
af7431
            
af7431
            # Post footer custom html
af7431
            # self.emit_custom_html(self.cfg.page_footer2),
af7431
            ]
af7431
        return u'\n'.join(html)
af7431
af7431
    def errormsg(self, d): 
af7431
    	"""Assemble HTML code for CentOS Identification
af7431
        
af7431
        @rtype: unicode
af7431
        @return: CentOS Global Identification
af7431
        """
af7431
        html = [
af7431
            u'
',
af7431
	        u'Wiki',
af7431
    	    u'
af7431
    	    self.username(d),
af7431
	        self.searchform(d),
af7431
    	    u'',
af7431
            u'

Wiki

',
af7431
            self.navibar(d),
af7431
            self.editbar(d),
af7431
            self.interwiki(d),
af7431
            self.trail(d),
af7431
            self.title(d),
af7431
            u'',
af7431
            ]
af7431
        return u'\n'.join(html)
af7431
af7431
    def credits(self, d):
af7431
        """Assemble HTML code for the credits.
af7431
        
af7431
        @rtype: unicode
af7431
        @return: Creative Common Reference
af7431
        """
af7431
af7431
        html = u'''
af7431
        
af7431
        
af7431
            
af7431
            Creative Commons License
af7431
            
af7431
        
af7431
af7431
        
af7431
        This wiki is licensed under a  
af7431
        href="http://creativecommons.org/licenses/by-sa/3.0/">Creative
af7431
        Commons Attribution-Share Alike 3.0 Unported
af7431
        License.
af7431
        
af7431
af7431
af7431
''' % d
af7431
        return html
af7431
af7431
    def searchform(self, d):
af7431
        """
af7431
        assemble HTML code for the search forms
af7431
        
af7431
        @param d: parameter dictionary
af7431
        @rtype: unicode
af7431
        @return: search form html
af7431
        """
af7431
        _ = self.request.getText
af7431
        form = self.request.form
af7431
        updates = {
af7431
            'search_label' : _('Search:'),
af7431
            'search_value': wikiutil.escape(form.get('value', [''])[0], 1),
af7431
            'search_full_label' : _('Text', formatted=False),
af7431
            'search_title_label' : _('Titles', formatted=False),
af7431
            }
af7431
        d.update(updates)
af7431
af7431
        html = u'''
af7431
af7431
<form method="get" action="">
af7431
af7431
    <input type="hidden" name="action" value="fullsearch">
af7431
    <input type="hidden" name="context" value="180">
af7431
    <label for="searchinput">%(search_label)s</label>
af7431
    
af7431
    onfocus="searchFocus(this)" onblur="searchBlur(this)"
af7431
    onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search">
af7431
    
af7431
    value="%(search_full_label)s" alt="Search Full Text">
af7431
    
af7431
    value="%(search_title_label)s" alt="Search Titles">
af7431
</form>
af7431
af7431
af7431
<script type="text/javascript">
af7431
af7431
var f = document.getElementById('searchform');
af7431
f.getElementsByTagName('label')[0].style.display = 'none';
af7431
var e = document.getElementById('searchinput');
af7431
searchChange(e);
af7431
searchBlur(e);
af7431
//-->
af7431
</script>
af7431
''' % d
af7431
        return html
af7431
af7431
# The following code make the navibar visible to users with
af7431
# write access right ONLY!.
af7431
af7431
    def shouldShowEditbar(self, page):
af7431
        """ Hide the edit bar if you can't edit """
af7431
        if self.request.user.may.write(page.page_name):
af7431
            return ThemeBase.shouldShowEditbar(self, page)
af7431
        return False
af7431
af7431
# The follwing code is just to use class instead of id in
af7431
# the navibar element. It is not recommended by CCS v2.1
af7431
# standard the use of two equals id elements on the same
af7431
# page.
af7431
af7431
    def navibar(self, d):
af7431
        """ Assemble the navibar
af7431
af7431
        @param d: parameter dictionary
af7431
        @rtype: unicode
af7431
        @return: navibar html
af7431
        """
af7431
        request = self.request
af7431
        found = {} # pages we found. prevent duplicates
af7431
        items = [] # navibar items
af7431
        item = u'
  • %s
  • '
    af7431
            current = d['page_name']
    af7431
    af7431
            # Process config navi_bar
    af7431
            if request.cfg.navi_bar:
    af7431
                for text in request.cfg.navi_bar:
    af7431
                    pagename, link = self.splitNavilink(text)
    af7431
                    if pagename == current:
    af7431
                        cls = 'wikilink current'
    af7431
                    else:
    af7431
                        cls = 'wikilink'
    af7431
                    items.append(item % (cls, link))
    af7431
                    found[pagename] = 1
    af7431
    af7431
            # Add user links to wiki links, eliminating duplicates.
    af7431
            userlinks = request.user.getQuickLinks()
    af7431
            for text in userlinks:
    af7431
                # Split text without localization, user knows what he wants
    af7431
                pagename, link = self.splitNavilink(text, localize=0)
    af7431
                if not pagename in found:
    af7431
                    if pagename == current:
    af7431
                        cls = 'userlink current'
    af7431
                    else:
    af7431
                        cls = 'userlink'
    af7431
                    items.append(item % (cls, link))
    af7431
                    found[pagename] = 1
    af7431
    af7431
            # Add current page at end
    af7431
            if not current in found:
    af7431
                title = d['page'].split_title(request)
    af7431
                title = self.shortenPagename(title)
    af7431
                link = d['page'].link_to(request, title)
    af7431
                cls = 'current'
    af7431
                items.append(item % (cls, link))
    af7431
    af7431
            # Assemble html
    af7431
            items = u''.join(items)
    af7431
            html = u'''
    af7431
      af7431
      %s
      af7431
      af7431
      ''' % items
      af7431
              return html
      af7431
      af7431
      def execute(request):
      af7431
          """ Generate and return a theme object
      af7431
              
      af7431
          @param request: the request object
      af7431
          @rtype: MoinTheme
      af7431
          @return: Theme object
      af7431
          """
      af7431
          return Theme(request)