changeset 1582:f37b49b6313d

url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Sep 2006 11:01:54 +0200
parents 1393f9e111f4
children b8b3565887ac
files MoinMoin/config/__init__.py MoinMoin/config/multiconfig.py MoinMoin/server/__init__.py MoinMoin/server/standalone.py MoinMoin/server/twistedmoin.py MoinMoin/version.py docs/CHANGES wiki/config/wikiconfig.py wiki/config/wikifarm/farmconfig.py wiki/server/moin.py wiki/server/mointwisted.py
diffstat 11 files changed, 59 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/__init__.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/config/__init__.py	Mon Sep 25 11:01:54 2006 +0200
@@ -6,6 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 import re
+from MoinMoin import version
 
 # Threads flag - if you write a moin server that use threads, import
 # config in the server and set this flag to True.
@@ -19,6 +20,14 @@
 # When creating files, we use e.g. 0666 & config.umask for the mode:
 umask = 0770
 
+# Default value for the static stuff URL prefix (css, img, js).
+# Caution:
+# * do NOT use this directly, it is only the DEFAULT value to be used by
+#   server Config classes and by multiconfig.py for request.cfg.
+# * must NOT end with '/'!
+# * some servers expect '/' at beginning and only 1 level deep.
+url_prefix_static = '/moin_static' + version.release_short
+
 # Invalid characters - invisible characters that should not be in page
 # names. Prevent user confusion and wiki abuse, e.g u'\u202aFrontPage'.
 page_invalid_chars_regex = re.compile(
--- a/MoinMoin/config/multiconfig.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/config/multiconfig.py	Mon Sep 25 11:01:54 2006 +0200
@@ -12,7 +12,7 @@
 import sys
 import time
 
-from MoinMoin import error, util, wikiutil
+from MoinMoin import config, error, util, wikiutil
 import MoinMoin.auth as authmodule
 from MoinMoin.packages import packLine
 from MoinMoin.security import AccessControlList
@@ -161,13 +161,13 @@
     @rtype: DefaultConfig subclass instance
     @return: config object for specific wiki
     """
-    configName = _getConfigName(url)
+    cfgName = _getConfigName(url)
     try:
-        config = _config_cache[configName]
+        cfg = _config_cache[cfgName]
     except KeyError:
-        config = _makeConfig(configName)
-        config = _config_cache.setdefault(configName, config)
-    return config
+        cfg = _makeConfig(cfgName)
+        cfg = _config_cache.setdefault(cfgName, cfg)
+    return cfg
 
 
 # This is a way to mark some text for the gettext tools so that they don't
@@ -421,10 +421,10 @@
     # copy the value to url_prefix_static to ease transition.
     url_prefix = None
 
-    # include the moin version number, so we can have a unlimited cache lifetime
+    # includes the moin version number, so we can have a unlimited cache lifetime
     # for the static stuff. if stuff changes on version upgrade, url will change
     # immediately and we have no problem with stale caches.
-    url_prefix_static = '/moin_static160'
+    url_prefix_static = config.url_prefix_static
 
     # we could prefix actions to be able to exclude them by robots.txt:
     #url_prefix_action = 'action' # no leading or trailing '/'
--- a/MoinMoin/server/__init__.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/server/__init__.py	Mon Sep 25 11:01:54 2006 +0200
@@ -9,7 +9,7 @@
 """
 
 import os
-
+from MoinMoin import config
 
 def switchUID(uid, gid):
     """ Switch identity to safe user and group
@@ -45,6 +45,8 @@
     This class does all error checking needed for config values, and will
     raise a RuntimeError on any fatal error.
     """
+    # some defaults that should be common for all servers:
+    url_prefix_static = config.url_prefix_static
 
     def __init__(self):
         """ Validate and post process configuration values
--- a/MoinMoin/server/standalone.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/server/standalone.py	Mon Sep 25 11:01:54 2006 +0200
@@ -290,15 +290,11 @@
         """ Handle requests (request type GET/HEAD/POST is in self.command)
 
         Separate between wiki pages and css and image url by similar
-        system as cgi and twisted, the '/staticXXX/' url prefix.
-
-        TODO: should use url_prefix_static - and not a constant but
-        request is not available at this time.  Should be fixed by
-        having url_prefix_static in a server config.
+        system as cgi and twisted, the url_prefix_static prefix.
         """
-        PREFIX = '/moin_static160/'
-        if self.path.startswith(PREFIX): # XXX
-            self.path = self.path[len(PREFIX)-1:]
+        prefix = config.url_prefix_static
+        if self.path.startswith(prefix + '/'):
+            self.path = self.path[len(prefix):]
             self.serve_static_file()
         elif self.path in ['/favicon.ico', '/robots.txt']:
             self.serve_static_file()
--- a/MoinMoin/server/twistedmoin.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/server/twistedmoin.py	Mon Sep 25 11:01:54 2006 +0200
@@ -46,7 +46,6 @@
 # Server globals
 config = None
 
-url_prefix_static = 'moin_static160'
 
 class WikiResource(resource.Resource):
     """ Wiki resource """
@@ -61,12 +60,12 @@
 
     def getChild(self, name, request):
         # Serve images and css from url_prefix_static
-        if request.prepath == [] and name == url_prefix_static:
+        if request.prepath == [] and name == config.url_prefix_static[1:]:
             return resource.Resource.getChild(self, name, request)
 
         # Serve special 'root' files from url_prefix_static
         elif name in ['favicon.ico', 'robots.txt'] and request.postpath == []:
-            return self.children[url_prefix_static].getChild(name, request)
+            return self.children[config.url_prefix_static[1:]].getChild(name, request)
 
         # All other through moin
 
@@ -243,7 +242,7 @@
     default = WikiRoot()
 
     # Here is where img and css and some special files come from
-    default.putChild(url_prefix_static, static.File(config.docs))
+    default.putChild(config.url_prefix_static[1:], static.File(config.docs))
 
     # Generate the Site factory
     # TODO: Maybe we can use WikiRoot instead of this
--- a/MoinMoin/version.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/MoinMoin/version.py	Mon Sep 25 11:01:54 2006 +0200
@@ -15,6 +15,7 @@
 
 project = "MoinMoin"
 release = '1.6.0alpha'
+release_short = '160' # used for url_prefix_static
 revision = patchlevel
 
 def update():
--- a/docs/CHANGES	Wed Sep 20 15:08:47 2006 +0200
+++ b/docs/CHANGES	Mon Sep 25 11:01:54 2006 +0200
@@ -307,8 +307,10 @@
          For Apache, Lighttpd and other "external" servers, you have to care
          for configuring them to use a long expiry and change url_prefix_static
          related configuration on upgrade.
-      HINT: if you run standalone server you MUST use /moin_static160.
-      HINT: if you run Twisted server you MUST use /moin_static160.
+      HINT: if you run standalone or Twisted server, the easiest way to get a
+            working configuration (with server configuration matching wiki
+            configuration) is to NOT set url_prefix_static at all. Moin will
+            use matching configuration defaults in this case.
     * url_prefix_action ['action'] was introduced for lowering load and traffic
       caused by searchengine crawlers. Up to now, crawlers where causing a high
       load in internet moin wikis because they tried to get about everything,
--- a/wiki/config/wikiconfig.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/wiki/config/wikiconfig.py	Mon Sep 25 11:01:54 2006 +0200
@@ -74,9 +74,14 @@
     # backup it.
     data_underlay_dir = './underlay/'
 
-    # This must be '/wiki' for twisted and standalone. For CGI, it should
-    # match your Apache Alias setting.
-    url_prefix = '/wiki'
+    # The URL prefix we use to access the static stuff (img, css, js).
+    # NOT touching this is maybe the best way to handle this setting as moin
+    # uses a good internal default (something like '/moin_static160' for moin
+    # version 1.6.0).
+    # For Twisted and standalone server, the default will automatically work.
+    # For others, you should make a matching server config (e.g. an Apache
+    # Alias definition pointing to the directory with the static stuff).
+    #url_prefix_static = '/moin_static160'
 
 
     # Security ----------------------------------------------------------
--- a/wiki/config/wikifarm/farmconfig.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/wiki/config/wikifarm/farmconfig.py	Mon Sep 25 11:01:54 2006 +0200
@@ -91,9 +91,14 @@
     # backup it.
     data_underlay_dir = './underlay/'
 
-    # This must be '/wiki' for twisted and standalone. For CGI, it should
-    # match your Apache Alias setting.
-    url_prefix = '/wiki'
+    # The URL prefix we use to access the static stuff (img, css, js).
+    # NOT touching this is maybe the best way to handle this setting as moin
+    # uses a good internal default (something like '/moin_static160' for moin
+    # version 1.6.0).
+    # For Twisted and standalone server, the default will automatically work.
+    # For others, you should make a matching server config (e.g. an Apache
+    # Alias definition pointing to the directory with the static stuff).
+    #url_prefix_static = '/moin_static160'
 
 
     # Security ----------------------------------------------------------
--- a/wiki/server/moin.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/wiki/server/moin.py	Mon Sep 25 11:01:54 2006 +0200
@@ -38,6 +38,11 @@
     # If you installed with --prefix=PREFIX, use 'PREFIX/share/moin/wiki/htdocs'
     docs = '/usr/share/moin/htdocs'
 
+    # URL prefix for the static stuff (used to access stuff in docs) - you
+    # usually should not need to change this because moin standalone uses
+    # matching defaults for here and for wikiconfig.py:
+    #url_prefix_static = '/moin_static160'
+
     # The server will run with as this user and group (default 'www-data')
     user = 'www-data'
     group = 'www-data'
--- a/wiki/server/mointwisted.py	Wed Sep 20 15:08:47 2006 +0200
+++ b/wiki/server/mointwisted.py	Mon Sep 25 11:01:54 2006 +0200
@@ -39,6 +39,11 @@
     # Path to moin shared files (default '/usr/share/moin/wiki/htdocs')
     docs = '/usr/share/moin/htdocs'
 
+    # URL prefix for the static stuff (used to access stuff in docs) - you
+    # usually should not need to change this because Twisted moin uses
+    # matching defaults for here and for wikiconfig.py:
+    #url_prefix_static = '/moin_static160'
+
     # The server will run with as this user and group (default 'www-data')
     user = 'www-data'
     group = 'www-data'
@@ -73,7 +78,7 @@
     ## memoryProfile = TwistedProfiler('mointwisted',
     ##                            requestsPerSample=100,
     ##                            collect=0)
-    
+
     # Hotshot profile (default commented)
     # Not compatible with threads.
     ## hotshotProfile = name + '.prof'