~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/web/static/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - static files and serving them
 
4
 
 
5
    MoinMoin uses some static files, like css, js, images, applets etc. and
 
6
    they need to get served somehow.
 
7
 
 
8
    How does moin use the static files?
 
9
    -----------------------------------
 
10
    Well, in fact, the moin wiki engine code does not access those files at all,
 
11
    it just emits URLs to those files, so the browser of the wiki user will load
 
12
    these files by requesting them from these URLs.
 
13
 
 
14
    To generate correct URLs to these files, moin uses 2 configuration settings:
 
15
    url_prefix_static - this the URL moin uses to generate URLs for static files,
 
16
                        default: '/moin_staticXYZ' for moin version X.Y.Z
 
17
    url_prefix_local - same thing, but some stuff is required to be on same server
 
18
                       or the browser will reject it (e.g. FCKeditor javascript).
 
19
                       So, if you point url_prefix_static to another server, you
 
20
                       will have to give url_prefix_local with a URL on the same
 
21
                       server.
 
22
 
 
23
    Where are the static files located on your disk?
 
24
    ------------------------------------------------
 
25
    You can:
 
26
    * Just serve our builtin static stuff from STATIC_FILES_PATH (in the moin code
 
27
      at MoinMoin/web/static/htdocs) - in that case you should not modify the
 
28
      files or your modifications could be overwritten when you upgrade moin.
 
29
    * Copy that stuff to somewhere else and modify it THERE and use it from
 
30
      THERE.
 
31
 
 
32
    How to serve those static files?
 
33
    --------------------------------
 
34
    * Let moin serve them at <script_root>/moin_staticXYZ (this is the easiest
 
35
      way, you can optimize it later) and use that by setting:
 
36
      * for wikis running at root URL (/):
 
37
        url_prefix_static = '/moin_staticXYZ' # this is the default!
 
38
      * for wikis running at a non-root URL (like e.g. /mymoin):
 
39
        from MoinMoin import config
 
40
        url_prefix_static = '/mymoin' + config.url_prefix_static
 
41
    * Later, you can serve them with your web server (e.g. apache) - you need to
 
42
      configure apache to serve the url_prefix_static URL with the files from the
 
43
      static files path.
 
44
 
 
45
    @copyright: 2009 MoinMoin:ThomasWaldmann
 
46
    @license: GNU GPL, see COPYING for details.
 
47
"""
 
48
 
 
49
from os.path import join, abspath, dirname, isdir
 
50
 
 
51
from MoinMoin import config
 
52
 
 
53
from werkzeug import SharedDataMiddleware
 
54
 
 
55
STATIC_FILES_PATH = '/usr/share/moin/htdocs'
 
56
 
 
57
 
 
58
def make_static_serving_app(application, shared):
 
59
    """
 
60
    wrap application in a static file serving app
 
61
 
 
62
    @param application: WSGI wiki application that should be wrapped
 
63
    @param shared:  directory where static files are located (then we create the
 
64
                    usual mapping dict we need automatically), or a ready-to-use
 
65
                    mapping dict for SharedDataMiddleware.
 
66
                    If True, use builtin static files from STATIC_FILES_PATH.
 
67
    @returns: wrapped WSGI application
 
68
    """
 
69
    if not isinstance(shared, dict):
 
70
        if shared is True:
 
71
            shared = STATIC_FILES_PATH
 
72
        if isdir(shared):
 
73
            shared = {config.url_prefix_static: shared,
 
74
                      # XXX only works / makes sense for root-mounted wikis:
 
75
                      '/favicon.ico': join(shared, 'favicon.ico'),
 
76
                      '/robots.txt': join(shared, 'robots.txt')}
 
77
        else:
 
78
            raise ValueError("Invalid path given for shared parameter")
 
79
    return SharedDataMiddleware(application, shared)
 
80