Place the below favicons.py into your moin theme directory, and copy your base theme's web directory to favicons.

After that, everything should look like before, but now you are able to put this line to a page:

#pragma favicon IMAGE-URL

Example:

#pragma favicon /images/blah.ico

And it will use the image it finds at the given IMAGE-URL as favicon, so it will appear in the address bar of firefox.

favicons.py

   1 class Theme(modern.Theme):
   2 
   3     name = "favicons"
   4 
   5     def html_head(self, d):
   6         return modern.Theme.html_head(self, d) + self.faviconLink()
   7 
   8     def faviconLink(self):
   9         """ Create a favicon link based on page #pragma
  10         
  11         Use '#pragma favicon images/image.ico' to create the link.
  12 
  13         There seems to be no official spec for favicons. Based on
  14         Wikipedia, ico is the most compatible format, and both
  15         "shortcut icon" and "icon" links should be used.
  16         See http://en.wikipedia.org/wiki/Favicon
  17         """
  18         url = self.request.getPragma('favicon')
  19         if not url:
  20             return ''
  21         return ('<link rel="shortcut icon" href="%(url)s">\n'
  22                 '<link rel="icon" href="%(url)s">\n') % {'url': url}
  23 
  24 
  25 def execute(request):
  26     return Theme(request)


-- ArmelFortun

I've a theme here :

/usr/local/share/moin/wikiname/data/plugin/theme/mytheme.py

I edit the file "mytheme.py" and add this :

   1     # Add the favicon's link to the header
   2     def html_head(self, d):
   3         return ThemeBase.html_head(self, d) + '\n' + self.faviconLink()
   4 
   5     def faviconLink(self):
   6         """ Create a favicon link based on page #pragma
   7         
   8         Use '#pragma favicon img/image.ico' to create the link.
   9         
  10         There seems to be no official spec for favicons. Based on
  11         Wikipedia, ico is the most compatible format, and both
  12         "shortcut icon" and "icon" links should be used.
  13         See http://en.wikipedia.org/wiki/Favicon
  14         """
  15         prefix = self.cfg.url_prefix + '/'
  16         name = self.name
  17         url = self.request.getPragma('favicon')
  18         if not url:
  19             return ''
  20         return ('<link rel="shortcut icon" href="%(prefix)s%(name)s%(url)s">\n'
  21                 '<link rel="icon" href="%(prefix)s%(name)s%(url)s">\n') % {'url': url, 'prefix': prefix, 'name' : name }

MoinMoin: FaviconTheme (last edited 2007-10-29 19:08:38 by localhost)