Add support for multiple CSS.
authorBernardo Innocenti <bernie@codewiz.org>
Tue, 6 Nov 2007 11:41:23 +0000 (06:41 -0500)
committerBernardo Innocenti <bernie@codewiz.org>
Tue, 6 Nov 2007 11:41:23 +0000 (06:41 -0500)
geekigeeki.conf.py
geekigeeki.py

index 2c7b9bee86832f643ed094d6dcb80528a795d655..1e959b0686e10a08c57515159c57708ea9d67466 100644 (file)
@@ -6,7 +6,7 @@ site_name = 'Codewiz'
 privileged_url = 'https://www.codewiz.org/~bernie/wiki'
 
 data_dir = '/home/bernie/public_html/wiki/data'
-css_url = '../wikidata/geekigeeki.css'  # optional stylesheet link
+css_url = ['../wikidata/geekigeeki.css']  # optional stylesheet links
 
 history_url = '../wikigit/wiki.git'
 post_edit_hook = './post_edit_hook.sh'
index adc7d2a88f3bab4e8d2bb28a5fdc263841d7d2db..56d71f156f6b62984397e1b91d66ce73427b658e 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
 # Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
@@ -113,8 +113,8 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'):
     print ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'
     if not name:
         print ' <meta name="robots" content="noindex,nofollow" />'
-    if globals().has_key('css_url'):
-        print ' <link rel="stylesheet" type="text/css" href="%s" />' % css_url
+    for css in css_url:
+        print ' <link rel="stylesheet" type="text/css" href="%s" />' % css
     print '</head>'
 
     # Body
@@ -563,7 +563,6 @@ class Page:
         self.page_name = page_name
         self.msg = ''
         self.msg_type = 'error'
-        self.attrs = {}
 
     def split_title(self):
         # look for the end of words and the start of a new word,
@@ -602,8 +601,9 @@ class Page:
             raise er
 
     def get_attrs(self):
-        if self.attrs:
+        if self.__dict__.has_key('attrs'):
             return self.attrs
+        self.attrs = {}
         try:
             file = open(self._text_filename(), 'rt')
             attr_re = re.compile(r"^#(\S*)(.*)$")
@@ -618,11 +618,16 @@ class Page:
                 raise er
         return self.attrs
 
+    def get_attr(self, name, default):
+        if self.get_attrs().has_key(name):
+            return self.get_attrs()[name]
+        else:
+            return default
+
     def can(self, action, default=True):
-        attrs = self.get_attrs()
         try:
-            # SomeUser:read,write All:read
-            acl = attrs["acl"]
+            #acl SomeUser:read,write All:read
+            acl = self.get_attr("acl", None)
             for rule in acl.split():
                 (user,perms) = rule.split(':')
                 if user == remote_user() or user == "All":
@@ -645,6 +650,12 @@ class Page:
         page_name = None
         if self.can_write():
             page_name = self.page_name
+
+        #FIXME: are there security implications?
+        #css foo.css bar.css
+        global css_url
+        css_url = css_url + self.get_attr("css", "").split()
+
         send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
         if self.can_read():
             PageFormatter(self.get_raw_body()).print_html()