1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - static files and serving them
5
MoinMoin uses some static files, like css, js, images, applets etc. and
6
they need to get served somehow.
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.
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
23
Where are the static files located on your disk?
24
------------------------------------------------
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
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
45
@copyright: 2009 MoinMoin:ThomasWaldmann
46
@license: GNU GPL, see COPYING for details.
49
from os.path import join, abspath, dirname, isdir
51
from MoinMoin import config
53
from werkzeug import SharedDataMiddleware
55
STATIC_FILES_PATH = '/usr/share/moin/htdocs'
58
def make_static_serving_app(application, shared):
60
wrap application in a static file serving app
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
69
if not isinstance(shared, dict):
71
shared = STATIC_FILES_PATH
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')}
78
raise ValueError("Invalid path given for shared parameter")
79
return SharedDataMiddleware(application, shared)