Blame Artworks/Webenv/Moin/1.5.9/Modern.py

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

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

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

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

Wiki

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