Subdirectories: NewFeatures.
What Templates Can Contain
Templates are literal text except for four magic template expansions (call them substitutions or macros if you want):
${...},#{...},@{...}, and%{...}.Generally, it is a fatal error for any of the expansions not to work: undefined variables, missing templates, no renderer by the name you listed in the template, etc.
${...}inserts the value of the named global variable. There are three modifiers to variable expansion:
${|var1|var2|...}is alternatives: it inserts the value of the first of var1, var2, etc that are defined.${?...}is error-free expansion: it makes it not an error for the rest of the expansion to use undefined variables; instead an empty result is inserted.${?|...|..}works.${!...}is cancelling expansion: if the variable or variable sequence isn't defined, the whole template produces nothing.A
?or!modifier must come before a|modifier.Variable expansion always produces valid HTML-quoted results.
@{...}invokes the named renderer and inserts its output. That's it; renderers take no arguments (or guff).
%{...}invokes the named renderer and inserts its output, except that if the renderer produces no output the entire template will produce no output. Thus a template consisting ofLast modified: %{lastmodified} <br/>is entirely empty if the
lastmodifiedrenderer produces nothing, instead of being 'Last modified:' and a line break (which would look ugly).
#{...}is template inclusion: the named template is recursively expanded. Template names are just file names for files under the template root directory (set in DWiki's configuration file). There are three variations:
#{|t1|t2|...}is alternative expansion: it inserts the first of t1, t2, etc that expanded to something non-blank.#{?t1|t2|...}is conditional expansion: it only expands the additional templates if t1 expanded to something.#{<t1[|t2|...]}and#{!t1[|t2|...]}are first found expansion, and requires a longer explanation.First Found Expansion
First found expansion is a way of testing a number of possibly existing templates and using the first one that actually exists. With the
#{!...}form it is a fatal error for no template to be found; with the#{<...}form it is not, and the whole expansion is just empty.Each of the t1, t2, etc alternatives are paths, augmented with expansion operators. There are two:
$(<varname>)expands a global variable, like${...}at the template level. (Unlike${...}, the variable expansion is not HTML-quoted.)...<rest>first tries the full path<rest>, and then tries backing up to each of<rest>'s parent directories until they run out. (That's a literal three dots at the start.)An example may help. With a
$(pagename)ofdwiki/TemplateSyntaxand a$(view-format)ofnormal, the template inclusion#{<Overrides/...$(pagename)/magic.tmpl|default/$(view-format).tmpl}would first try Overrides/dwiki/TemplateSyntax/magic.tmpl, then Overrides/dwiki/magic.tmpl, then Overrides/magic.tmpl, and finally default/normal.tmpl.
An example:
This DWiki uses %{..} and #{|t1|t2} expansion to produce a nice message about a directory being entirely empty of pages if it is, instead of 'The following pages are available in this directory:' followed by nothing at all. (You can see this at Tests/SubTestDir.)
A simplified version of the template for directories is:
#{structure/header.tmpl} <h1> Directory ${pagename} </h1> #{|dir/dirconts.tmpl|dir/dirempty.tmpl} #{structure/footer.tmpl}The
dir/dirconts.tmpltemplate is:<p>The following pages are available in this directory: %{listdir}</p>while the the
dir/dirempty.tmpltemplate is:<p> This directory is empty. </p>The
%{listdir}in dirconts.tmpl makes the entire template empty if thelistdirrenderer returns nothing (ie, the directory is empty). Then the#{|..|..}sees that the first template is empty and goes on to use diremtpy.tmpl. If there are files in the directory, the dirconts.tmpl template has content and dirempty.tmpl does not get used.Available renders
For convenience (mostly ChrisSiebenmann's), here is the canonical list of all available renderers. This is generated by the code itself, so is is guaranteed to be 100% accurate (at least for names; your mileage may vary for documentation):
anchor::comment: Generate an anchor start for the current comment. You must close the anchor by hand.anchor::self: Generates an anchor start where the name is the full path to the current page. You must close the anchor by hand.anchor::short: Generates an anchor start where the name is the name of the current page. You must close the anchor by hand.atom::autodisc: Generate a suitable Atom feed autodiscovery<link>string, suitable for inclusion in the<head>section. Generates nothing if there is no Atom recent changes feed.atom::comment: Display the current comment in a way suitable for inclusion in an Atom feed.atom::commentfeed: Generate a link to the Atom comments feed for the current page, if comments are turned on.atom::commentid: Generate a hopefully unique ID for the current comment.atom::comments: Generate an Atom feed of recent comments on or below the current page. Each comment is rendered throughsyndication/atomcomment.tmpl. Supports VirtualDirectory restrictions, which limit which pages the feed will include comments for.atom::commentstamp: Generate an Atom feed format timestamp for the current comment.atom::commenturl: Generate the URL for the current comment.atom::dirfeed: Generate a link to the Atom feed for the current page if the current page is a directory or the wiki root.atom::feeds: Generate a comma-separated list of all Atom feed links, that are applicable for the current page.atom::feedtitle: Generate an Atom feed title for the current page.atom::feedurl: Generate the URL of this page for the current feed.atom::modstamp: Generate an Atom timestamp for the current page based on its change time.atom::now: Generate an Atom timestamp for right now.atom::pages: Generate an Atom feed of the current directory and all its descendants (showing only the most recent so many entries, newest first). Each page is rendered throughsyndication/atomentry.tmpl, which should result in a valid Atom feed entry. Supports VirtualDirectory restrictions.atom::pagetag: Generate an Atom entry ID. If theatomfeed-tagconfiguration option is not defined, this is the same as atom::pageurl. Ifatomfeed-tagis defined, the entry ID is <tag value>:/<page path>. Ifatomfeed-tag-timeis defined, only pages from after this time are given tag-based IDs; for pages before then, this is the same as atom::pageurl.atom::pageterse: Generate wikitext:terse run through a HTML entity quoter, thus suitable for use in Atom feeds.atom::pageterse:notitle: Generate wikitext:terse:notitle run through a HTML entity quoter, thus suitable for use in Atom feeds.atom::pageurl: Generate the URL of this page in its normal view.atom::recentcomment: Generate an Atom format timestamp for the most recent comment that will be displayed in a comment syndication feed.atom::recentpage: Generate an Atom format timestamp for an Atom page feed for the current directory (and all its descendants).atom::timestamp: Generate an Atom timestamp for the current page.auth::loginbox: Generate the form for a login or logout box. Generates nothing if DWiki authentication is disabled. As a side effect, kills page modification time if it generates anything.blog::blog: Generate a Blog rendering of the current directory: all descendant real pages, from most recent to oldest, possibly truncated at a day boundary if there's 'too many', and sets up information for blog navigation renderers. Each displayed page is rendered with theblog/blogentry.tmpltemplate. Supports VirtualDirectory restrictions.blog::blogdir: Generate a BlogDir rendering of the current directory: display all real pages in the current directory from most recent to oldest, rendering each with the templateblog/blogdirpage.tmpl. Supports VirtualDirectory restrictions.blog::date: Generates a YYYY-MM-DD timestamp of the current page.blog::datecrumbs: Create date breadcrumbs for the blog directory if the current page is in a blog directory but is not being displayed inside a virtual directory. The 'blog directory' is the directory that made the blog view the default view.blog::datemarker: Inside a blog::blog or blog::blogdir rendering, generate a YYYY-MM-DD date stamp for the current page if this has changed from the last page; otherwise, generates nothing.blog::namedate: Generate a Month DD, YYYY timestamp of the current page.blog::next:title: Create a link to the next page (if one exists) for the current page if the current page is in a blog directory but is not being displayed inside a virtual directory; the title of the link is the page's title if available. The 'blog directory' is the directory that made the blog view the default view.blog::owner: Display the owner of the current page.blog::prev:title: Create a link to the previous page (if one exists) for the current page if the current page is in a blog directory but is not being displayed inside a virtual directory; the title of the link is the page's title if available. The 'blog directory' is the directory that made the blog view the default view.blog::prevnext: Create Previous and Next links for the current page if the current page is in a blog directory but is not being displayed inside a virtual directory. The 'blog directory' is the directory that made the blog view the default view.blog::seemonthyear: With blog::blog, generate a 'see more' set of links for the month and the year of the next entry if the display of pages has been truncated.blog::seemore: With blog::blog, generates a 'see more' link to the date of the next entry if the display of pages has been truncated; the text of the link is the target date. This renderer is somewhat misnamed.blog::time: Generate a YYYY-MM-DD HH:MM:SS timestamp of the current page.blog::timeofday: Generates a HH:MM:SS timestamp of the current page.blog::titles: Likeblog::blog, except that instead of rendering entries through a template, it just displays a table of dates and entry titles (or relative paths for entries without titles), linking to entries and to the day pages. Respects VirtualDirectory restrictions. Unlikeblog::blog, it always displays information for all applicable entries.breadcrumbs: Display a 'breadcrumbs' hierarchy of links from the DWiki root to the current page.comment::atomlink: Just likecomment::countlink, except that the URL is absolute and the HTML is escaped so that it can be used in an Atom syndication feed.comment::author: Display the author information for a comment, drawing on the given name, website URL, DWiki login, and comment IP address as necessary and available. Only works inside comment::showall. This potentially generates HTML, not just plain text.comment::comment: Display a particular comment. Only works inside comment::showall.comment::count: Display a count of comments for the current page.comment::countlink: Display the count of comments as a link to show them for the current page.comment::date: Display the date of a comment. Only works inside comment::showall.comment::form: Create the form for writing a new comment in, if the page is commentable by the current user.comment::pre: In a comment-writing context, generate a <pre> block of the comment being written.comment::preview: In a comment-writing context, show a preview of the comment being written.comment::showall: Display all of the comments for the current page (if any), using the templatecomment/comment.tmplfor each in succession.comment::user: Display the user who wrote a comment if it isn't the default DWiki user. Only works inside comment::showall.comment::write: Generate a link to start writing comments on the current page, if the current user can comment on the page.cond::anonymous: Suceeds (by generating a space) if this is an anonymous request, one with no logged in real user. Fails otherwise.cond::blogclipped: Succeeds (by generating a space) if we are in a blog view that is clipped. Fails otherwise.cond::blogyearmonth: Suceeds (by generating a space) if we are a directory, in a blog view, and we are in a month or year VirtualDirectory. Fails otherwise.cond::invirtual: Succeed (by generating a space) if we are in a VirtualDirectory (either directly or during rendering of a subpage). Fails otherwise.cond::notblogroot: Succeds (by generating a space) if we are a directory that is in a default blog view but is not the directory that made it the default view. Fails otherwise.cond::pageinblog: Succeeds (by rendering a space) if the current page is in a blog directory but is not being displayed inside a virtual directory (ie the page itself is being displayed). This also excludes 'utility' pages.dir::altviews: Generate a list of links to acceptable alternate ways to view the page if it is a directory.error::body: Generates the body for an error page from a template inerrors/, if the template exists; otherwise uses a default. Only usable during generation of an error page.error::title: Generate the title for an error from a template inerrors/, if the template exists; otherwise uses a default. Only usable during generation of an error page.hist::dirty: If the current page has been RCS-locked, display whether or not it has been modified from the version in RCS.hist::lockedby: If the current page is under RCS and is locked, display who has locked it.hist::revtable: If the current page is under RCS, display a version history table.inject::blogreadme: Likeinject::readme, except it looks for__readmeonly in the 'blog directory', the directory that made the blog view the default view. If there is no such directory between the current directory and the DWiki root directory, this does nothing.inject::index: Insert the wikitext file__indexin HTML form, if such a file exists in the current directory.inject::readme: Insert the wikitext file__readme, in HTML form, if such a file exists in the current directory.inject::upreadme: Likeinject::readme, except it searches for__readmeall the way back to the DWiki root directory, not just in the current directory.lastchangetime: Display the page's last change time, if it has one. The change time is taken from the inode ctime.lastmodified: Display the page's last modification time, if it has one. (This is not the same as the last-modified time that the HTTP response will have, which is taken from all of the pieces that contribute to displaying the page, including all templates.)linkhistory: Generate a link to this page's history called 'View History', if it has any.linknormal: Generate a link to this page's normal view called 'View Normal' if it is a file and we are not displaying it in normal view.linkrelname: Inside blog::blog, generate a link to this page titled with the page's path relative to the blog::blog page. Outside that context, the same as linktoself.linkshort: A link to this page, titled with the page's name.linkshortnormal: A link to this page in the normal view, titled with the page's name.linksource: Generate a link to this page's source called 'View Source', if it has any and you can see it.linktocomments: Create a link to this page that will show comments (if any). Otherwise the same aslinktonormal.linktonormal: A link to this page in the normal view, titled with the full page path.linktoself: A link to this page, titled with the full page path.listdir: List the contents of the current directory, with links to each page and subdirectory. Supports VirtualDirectory restrictions, but always shows subdirectories.listofdirs: Display a list of the subdirectories in the current directory.pagetools: Generate a comma-separated list of all 'page tools' links, such as 'View Source' and alternate directory views, that are applicable to the current page.post::oldpage: Generate a link to the origin page for a POST request in a POST form context.range::bar: Display a simple range navigation bar inside a VirtualDirectory.range::blogrange: With blog::blog, generates a day navigation bar if the display of pages has been truncated.range::calbar: With blog::blog, generates a calendar-based navigation bar.range::moreclip: With blog::blog, generate a 'or back N more' link if the display of pages has been truncated outside of a VirtualDirectory context.readmore: Generate a 'Read more' link to this page.rooturl: Generate the URL to the root of this DWiki.rss2::pages: Generate a RSS 2.0 feed of the current directory and all its descendants (showing only the most recent so many entries, newest first). Each page is rendered throughsyndication/rss2entry.tmpl, which should result in a valid RSS 2.0 feed entry. Supports VirtualDirectory restrictions.rss2::recentpage: Generate an RSS 2.0 format timestamp for an RSS 2.0 page feed for the current directory (and all its descendants).rss2::timestamp: Generate a RSS 2.0 timestamp for the current page.search::display: Display the results of a search.search::enter: Create the search form, if searching is enabled.seterror:permissions: If we are rendering the top level page of a request (ie, not rendering a subpage for blog, blogdir, atom feed, etc context), mark this page as having a permission error. This causes the page to be reported as a HTTP 403 error.sitemap::minurlset: Generate a Google Sitemap set of <url> entities for the directory hierarchy starting at the current directory. Supports VirtualDirectory restrictions.wikitext: Convert wikitext into HTML.wikitext:cache: Convert wikitext into HTML but do not display the result; instead it is just cached for later (re)use. This has three effects. First, it makes variables like ${:wikitext:title} available (as do all other wikitext renderers). Second, it's somewhat more efficient if you intend to use a sequence of wikitext renderers, such as a title one followed by a text one. Third, it can be used as a conditional renderer to check permissions; this renderer succeeds (by generating a space) if permissions allow the wikitext to be displayed, and fails (generating nothing) if they don't.wikitext:firstpara: Convert wikitext into HTML, showing only the first paragraph (and the title) if this is possible. This renderer fails if there is no findable first paragraph. It honors the {{CutShort}} macro.wikitext:notitle: Convert wikitext into HTML but without the title.wikitext:short: Convert wikitext into HTML, honoring the {{CutShort}} macro.wikitext:terse: Convert wikitext into terse 'absolute' HTML, with all links fully qualified and no macros having any effect except CutShort, CanComment, IMG, and Restricted.wikitext:terse:notitle: Convert wikitext into terse 'absolute' HTML with all links fully qualified et al (as withwikitext:terse) but omit the title of the page, as withwikitext:notitle.wikitext:title: Generate and return the title of a wikitext page.wikitext:title:html: Generate and return the title of a wikitext page complete with its surrounding '<hN>' and '</hN>' tags.wikitext:title:nohtml: Generate and return the title of a wikitext page without HTML markup.wikitext:title:nolinks: Generate and return the title of a wikitext page without links.For quite a lot of these, the best real documentation is to see how they are used in the default DWiki template set. (Which is unfortunately a bit of a dark twisted maze at the moment.)
Renderers normally produce things about or from the current page, although some of them (for use in peculiar context) operate on other things. Unless otherwise specified, all renderers are silent if they can't produce something appropriate, which is handy for use in
%{....}or just in general.
Virtual Directories in DWiki
A virtual directory is a way of restricting what pages get shown out of a real directory. It works by tacking on 'virtual' directories after the real directory (ie, as subdirectories) to tell DWiki what you want to see.
Virtual directories restrict pages based on their most recent modification time. There are three versions available:
- calendar: with the format
<year>/[<month>/[<day>]], all as digits. Only pages most recently changed in the time period get selected.- latest: with the format
latest/<howmany>. They show just the most recently changed<howmany>pages.- oldest: with the format
oldest/<howmany>. They show just the least recently changed<howmany>pages.- range: with the format
range/<start>-<end>. They show the start'th to the end'th most recently changed page.All pieces of a virtual directory must really be virtual. If you have a directory
Foo/with aFoo/2005/subdirectory (or file), you cannot use the virtual directoryFoo/2005/05/to see things from May of 2005 inFoo/. Moral: let DWiki organize things based on time for you, don't do it yourself.Virtual directories are paid attention to by some renderers, which are generally used in some views. You can get the full list in TemplateSyntax.
DWiki Authentication
DWiki has optional support for authenticating users, which is a prerequisite for restricting access to pages and for allowing people to comment. User authentication is done by cookies, which means that people wanting to be authenticated have to accept cookies from the DWiki's web server.
Whether authentication is on is controlled by the
authfilesetting in the ConfigurationFile; if it is set, it specifies a password file for the DWiki. Once enabled, a login box will appear at the bottom of pages where people can enter their login and password into a form and submit it to the wiki. If the password is correct, DWiki will send back a login cookie and the session is now authenticated (provided that the user's browser then sends the cookie back to DWiki with future requests).An authenticated person has a login name and may optionally be in some groups. When checking permissions, logins and groups are treated the same (so you should not create groups that have the same name as users; this is either pointless or dangerous, depending on how many people are in the group). What groups a login is part of is specified in the password file.
To be precise, an authenticated request is any request that has a valid associated login name. Normally this happens because the user's browser sent back a valid DWiki login cookie, but a DWiki may have a default login, set in the ConfigurationFile. If the default login is set and exists in the password file, everything is authenticated; either as a 'real' (passworded) login or as the default login.
Because DWiki is hard-coded to require authentication before people can write comments, setting a default user is the only way to let the world (potentially) comment on your DWiki.
Using Authentication
Authentication is used by the
{{Restricted}}and{{CanComment}}DWikiText macros. Without arguments they restrict the page to authenticated people or allow comments by authenticated people (respectively). With arguments, they restrict things more tightly. There are two sorts of arguments:
- positive arguments are plain logins or groups, and require the authenticated session to be one of the things named.
- negative arguments start with '
-' and are then logins or groups, and require the authenticated session to not be one of the things named.If only negative arguments are given, anyone not mentioned passes; if both positive and negative arguments are given, you must pass the positive arguments and not fail the negative arguments.
Directories can create default permissions for everything under them by having a special file called
__accesswith either or both of Restricted and CanComment macros.__accessfiles are checked backwards from the page being looked at, and the first one that contains a Restricted or a CanComment (depending on what is at issue) wins.__accessfiles can have other content, although ChrisSiebenmann doesn't expect people to look at them very often.Note: this means that subdirectories can give back permissions that were denied by a higher-level directory. This is deliberate.
Authentication limits
DWiki authentication protects only file contents. It does not protect directory contents and it thus doesn't protect a page's (file) name. Moral: don't put sensitive information into page names.
Password security
Note: DWiki doesn't specially encrypt login / password information while it's being sent to the web server. Unless the entire connection is running over SSL, people can theoretically snoop the password in clear text.
DWiki doesn't store someone's clear text password (even in its password file); instead it stores a hash of the password, using a format that guarantees that if two different people use the same password they will get different hashes. (Barring the hash function itself being broken.)
As always, people should be strongly discouraged from using important passwords (eg, their Unix account passwords) for any web service, a DWiki included. Using one's Unix login name as one's DWiki login name is harmless and even convenient.
The cookie
The cookie DWiki uses has the login name in clear text, and is authenticated with an added hash value. If you want the gory details, see
authcookie.pyandhtmlauth.pyin the DWiki source code. With a properglobal-authseedsecret in the ConfigurationFile, it is believed to be secure from all brute-force attacks.The cookie is normally quite long-lived. It becomes invalid if the user's password or the DWiki global authseed change.
The cookie is not restricted to coming from a single IP address or anything like that.
Format of the password file
The password file has a simple format. Blank lines and comment lines (lines that have a '
#' character as their first non-whitespace) are ignored. Otherwise, lines have the format:<login> <password-hash> [<group> ....]There can be any amount of whitespace between elements; groups are optional.
The easy way to add logins or change passwords is with the
dpasswd.pyprogram in the DWiki source. Adding or changing groups, or deleting logins, you get to do by editing the file directly.DWiki has no support for creating logins or changing passwords over the web. This is deliberate.
How you manage this process in general is up to you; in non-paranoid environments ChrisSiebenmann uses a group-writeable password file owned by an appropriate (Unix) group.
DWiki bugs/needfix
/{....}as a template comment, because I think I want them. (maybe another character, but ehh; this sort of looks like a C/etc comment.)inode ctime is last modified, inode mtime is created. The split has started. This may or may not work well; I'll have to see. (Partly based on what else screws with ctimes in our Unix environment.)
It seems clear that ctime is not too useful in at least some context. I should use it for safety in Atom feed generation and some other contexts, but not otherwise by default.
http://projects.edgewall.com/trac/wiki/WikiFormatting documents some stuff better than me, plus has 'processors'. I could steal that.
Searching needs to be less lame, at least for searching through the searchbox. It probably wants to be case-independant and possibly only for word starts (instead of word boundaries on both sides; arguably all searches should be only word boundary start ones).
The real rule is not 'identifier boundary', it is 'identifier component boundary', which is \b or a-z0-9 at the start, and \b or A-Z at the end.
It should be possible to create an Atom feed template that included all of the comments as part of the page.
CSS work. This implies that I need to actually understand CSS. I laugh at myself, hollowly. (Progress: we now style some stuff with CSS.)
We should be able to see the history page for any RCS-but-not-displayable page.
There should be some form of RecentChanges that throws in time information. (Clearly not Striped'able.)
Open issues
Do I want a 'render this page as wikitext' magic template option? That's what the injectors hard-code right now.
writecomment needs some way to generate a good link to help/DWikiText, so that people can actually know what to write a comment in. (It has one now, but the way may be a bit lame.)
Do we need a way to turn off WikiWord links? (The current approach is to use
[[...|]], which is perhaps good enough for the rare cases.)Should we forbid switching to alternate views in a virtual directory? The 'normal' view doesn't work entirely right (drops subdirectories); this may be a bug. (Fixed now: the listdir renderer needs to always include all subdirectories, despite their timestamps possibly being outside the restriction.)
We need to sort out when a link stays in the same view and when it doesn't. At the moment it is somewhat ad-hoc.
[[...]]links don't chase redirects, and they should. Well, now they do and I'm not convinced it's the right thing. It's convenient, but it changes the explicitly written link text; this might be good or it might be bad.Decide: should access restrictions look sort of like Unix access restrictions, being enforced top-down, or the current bottom-up way? I am starting to think that bottom-up is open to some reliability issues. But on the other hand, top-down has semantic issues too.
Profile the code. Laugh hysterically. Fix what I can.
DWiki should be more configurable through the filesystem. Can we support adding new views (directory and/or file) by reading the canonical template directory, for example? This would suffice for anything that doesn't require special handling.
Long-range:
DWiki knows a lot about what views do what. Unfortunately I suspect that this is impossible to work around, especially given how
htmlviews.pyis set up.Templates should mark up with <div> and so on.
wikirend.py needs to style-mark much of the things that it emits. I would like to find some general augmentation mechanism, although it's probably not going to be pretty.We're going to need to genericize access control. I think it will be some matrix of view + file patterns + file attributes. (Punt for now, everyone can see everything.)
This is a permanently FIXME page.
Security Aspects of DWiki
DWiki has a general attitude about security: it really distrusts incoming requests, it somewhat distrusts itself, but it has a rational trust of the people creating DWiki templates and pages. DWiki will try to save people from accidental mistakes, but doesn't bother with things that are just half-hearted attempts to stop people from deliberately sidestepping security restrictions. Moral: don't let people write DWiki pages unless you trust them.
Some knowledge of the ProcessingModel and the ConfigurationFile (and what can be set there) may be helpful for the rest of this discussion.
A Quick Summary
DWiki itself is written in Python (a lot of Python). This means that unless there is a gross implementation error in the Python interpreter, it is secure from simple problems such as buffer overruns. While DWiki uses some components from the standard Python libraries, they too are well-tested and believed to be entirely safe.
Because it is quite careful at multiple levels about how it handles requests, hostile HTTP requests should not be able to trick DWiki into serving anything from outside the page directory (or the comments directory, or the static content directory). InvalidPageNames discusses things it won't serve even inside them.
DWiki doesn't attempt to stop insiders from using DWiki to serve 'bad' content, ultimately because there are so many ways a malicious insider can do that. ChrisSiebenmann feels that it is better to be honest about not making any attempt rather than making an attempt and causing people to put more trust in it than it warrants.
If run as a CGI-BIN, DWiki should not be run with a UID that has any special access to restricted files. But then, no CGI-BIN should be run that way.
DWiki has some degree of optional Authentication, but it is no stronger than the usual run of the mill login and password on other web sites. Really sensitive content is probably best not served from a web server that the public (whatever that means to you) can access.
Pages versus Templates
What people can do with the ability to write DWikiText in DWiki pages is somewhat less powerful than what they can do with the ability to write DWiki templates. Similarly, errors in DWikiText are considered far less fatal than errors in templates; DWikiText errors just result in funny-looking pages, while template errors result in terse web error pages.
Thus: while it's safe to let people write DWiki pages in general, you probably want to restrict (at least somewhat) who can write or modify your templates. Plus, your templates (being, you know, templates) shouldn't need modification all that often. People can create and modify pages all the time.
How DWiki tries to be secure
Cautious processing
Internally, DWiki tries to operate in a relatively 'security conservative' fashion. For example, the frontend rejects clearly invalid things without passing them through to the DWiki core, because the core has a lot more power than the frontend so a mistake has larger ramifications.
DWiki also is deliberately structured so as to give itself as little power as possible.
Errors Abort Processing
DWiki can hit a number of internal problems while processing a request; for example, a template that's called for might be missing. When this happens, DWiki aborts processing the entire request, throwing an error all the way back to the front end, which generates a terse error page about the situation.
This may be abrupt ... but it is safe.
File Access
DWiki reads only a few files: the ConfigurationFile, the global-authseed-file file, the authfile password file, and things under the page, template, RCS, static files, and comments directories (if those are configured on).
Except for the password file, the DWiki core only accesses files through a simple storage layer abstraction, which provides 'storage pools' to the rest of DWiki. Each storage pool confines all file requests to relative paths under the pool's root, explicitly ruling out InvalidPageNames when retrieving files for the rest of DWiki.
The storage layer has no general file writing capabilities. The only interface it has for writing files is specifically designed for comments, using a specific naming and storage scheme. And only the comments directory uses a storage pool that supports this abstraction.
Following Symlinks
Unlike some web servers (eg, Apache), DWiki takes no special care to not follow symbolic links that point outside one of its storage pool directory roots. If you put such a symbolic link into a storage pool area, DWiki assumes that you know what you're doing.
This is deliberate. Attempting to duplicate the kernel's
namei()function in user space is inevitably very complicated (and prone to surprising races). Rather than run the risk of making a mistake in the amount of code required, DWiki is honest about the whole situation.Limitations DWiki imposes on itself
Limited URL scope
DWiki refuses to serve any request that is not under
staticurl(if set) orrooturl. Anything understaticurlmust be a static request and is served only as such.Limited static-content serving
In addition to dynamic DWiki pages, DWiki can serve static content via the
staticdirConfigurationFile directive. Since DWiki's goals for serving static content are very modest (CSS files, images, etc), DWiki refuses requests for static directories. As mentioned in ProcessingModel, static content is served by the frontend, thereby keeping the amount of code involved in the process down.In addition, DWiki rejects any request for static content that is not in the default 'normal' view.
A brief sketch of the Dwiki processing model
The core of DWiki is a template expansion engine and a collection of (text) renderers; DWiki displays pages by figuring out what template to use and then rendering it out.
Renderers generate text based on the current context, such as the page that is being displayed. The most important (and largest) renderer is the wikitext renderer, which takes page content in DWiki's wiki text format and turns it into HTML.
Other renderers create things like the navigation 'breadcrumbs' up at the top of this page and and the page tools and last-modified lines at the bottom. Renderers generally create only the essential pieces of that information; surrounding text is created through template expansion. Renderers are hardcoded parts of DWiki and are thus written in Python.
Templates are text files; they get expanded by the template engine through a recursive process of applying template 'macros' to their text. Template macros can insert other (expanded) templates, insert text taken from context variables, and insert the results of renderers. A typical template might look like:
<html><head><title>${|wikititle|wikiname} :: ${page}</title></head> <body> @{breadcrumbs} <br/> @{wikitext} <hr> #{footer.tmpl} #{site-sig.tmpl} </body> </html>(the actual templates that render this DWiki are somewhat more complicated than that, but this shows the flavour.)
DWiki produces all pages this way. Displaying different types of pages (regular pages versus directories) and different views of the same page (such as the history view) is done by selecting a different starting template; the template (presumably) uses different renderers that the normal view.
Errors are also rendered using templates (if an appropriate template exists). This allows some error pages to reuse renderers as appropriate; for example, the no-such-page error template includes breadcrumbs just as regular pages do, as you can see at NoSuchPage.
Wart: the view source display is not done by a template: it just barfs the content out straight as plain text. One current limitation of renderers and templates is that they can't control the content-type, which is set in the HTML view core.
Wart: the mapping of view + file attributes to templates is currently hard-coded.
The frontend versus the core
DWiki is divided into two components: the front end and the core. The front end receives raw HTTP requests, figures out if they are proper requests, and then passes them to the core to go through the core's processing. If the front end can detect that a HTTP request is not something that the core can handle, it rejects it immediately with a terse error.
Similarly, if the core encounters a processing error it throws an exception up to the front end, which logs it and generates another terse error.
It is the front end that can optionally serve static files; the core is not involved in that process.
DWiki features
DWiki's job is to be a good way to display version controlled wiki-text pages that you write in a real editor.
The important DWiki features:
- simple but reasonably powerful text rendering (based on WikiText).
- natural support for arbitrarily-named links: you don't have to follow some magic page naming standard that doesn't fit well with the natural names for things.
- pages are normal, simple files, and you edit them directly in Unix.
- support for putting pages in RCS, with strong disincentives to hand-edit files without checking them out (they stop displaying).
- directories can display like changelogs: pages inline, most recent first.
- can generate Atom syndication feeds for recently changed things.
The inevitable feature list:
In no particular order:
- simple WikiText-like text rendering. (Chris wrote pages in GNU Emacs and relentlessly smushed anything that got in the way of how GNU Emacs wanted to autoformat things.)
- The text rendering choices are designed to make it easy to write about Unix systems.
- full support for directly editing wiki pages.
- does not force a flat page namespace; uses straightforward Unix files and directories to organize the DWiki page space. (Thereby keeping the Unix view of DWiki's pages simple.)
- supports a blog-like view of a directory that inlines pages there, most recent first.
- in-filesystem page redirects make it trivial to support plurals, moved/renamed pages, etc.
- text-based page templates control how all pages appear, making it easy to control various bits of a DWiki's appearance.
- pages can be put in RCS for version control and multi-person editing access. RCS files can live in either the page directory hierarchy (for simplicity) or another parallel directory tree (for neatness).
- forces people not to edit RCS-controlled files without locking them by refusing to display inconsistent unlocked files.
- generates Atom syndication feeds for recently changed pages and recent comments, for the entire DWiki or any subtree thereof.
- written in Python.
- simple-ish yet powerful enough (I hope) user authentication system, with an equally simple yet powerful way of restricting who can read DWiki pages.
- supports the option of letting people (possibly including the world) comment on some or all of the pages.
- takes some pride in properly generating and handling Last-Modified: and ETag: headers in HTTP responses.
- wikitext to HTML generates fully HTML 4.01 Transitional compliant HTML provided only that you don't jump multiple indent levels in at once in lists (thus Formatting doesn't validate).
- can run as a CGI-BIN or standalone, and support for additional environments (SCGI, WSGI, whatever) should be easy to add if it is needed. Disclaimer: standalone does not use a production-quality webserver implementation; it uses Python's
BaseHTTPServerwith a hack to use threading.Missing DWiki features
Also in no particular order:
- you can't edit DWiki pages from the web, but see WhyNotWebEditing.
- no user authentication.
- therefor, no access restrictions on who can read what.
- searching is primitive at best.
A necessary acknowledgement:
A number of DWiki's features and design decisions are shamelessly inspired by C.J. Silverio's as yet (22 May 2005) unfinished Snippy. Note that Snippy is much more powerful than DWiki probably ever will be, plus if it had been finished when I was writing DWiki I probably wouldn't have.
Page Names That DWiki Won't Serve
There are some paths and page names that DWiki categorically refuses to serve, even if they seem to resolve to real files. Because they're enforced by both low-level code and high-level code, they apply to DWiki pages, static files being served by DWiki, and even templates. (Technically they apply to comments too, but comments can't generate file names that violate these rules.)
What gets rejected:
Any path that includes a path component that starts with a
., ends with,vor a~, or isRCS.Any non-relative path that includes
..,., or a sequence//; usually this might appear in the URL of an incoming request. (Incoming requests are not supposed to include things like that. But ChrisSiebenmann declines to believe that everyone sending DWiki requests is going to do what they're supposed to.)DWiki will reject REDIRECT files that either have too many '..' entries (so that they are trying to escape the root of the page directory) or that fail these checks after they've potentially been converted from relative path names to absolute inside-DWiki paths.
When DWiki rejects bad paths, generally it says that there is no page by that name. Sometimes it rejects the request entirely in huge flames.
Redirection Files
Files in the page directory can create HTTP redirections, making it trivial to support plurals, moved/renamed pages, and so on. There are two ways of doing it:
REDIRECTcontent and symbolic links.If a file starts with a line that says '
REDIRECT somewhere', and does not have more than a few lines of content, DWiki considers it a redirection. The somewhere is basically interpreted as if it was appearing in a[[....]], so it can be:
- redirection to another DWiki page.
- redirection to an external web site, written as
http://....- redirection to an absolute URL on this web site, written as
<...>These files are generically called REDIRECT files.
A symbolic link is only considered a redirect if DWiki can 'resolve' it into an existing page. To resolve the symbolic link redirect, DWiki tries to interpret the symbolic link's value as if it was appearing in a
[[...]]as a DWiki relative page name.If the symbolic link doesn't resolve this way, DWiki treats the whole thing as an ordinary page; this keeps 'ordinary' uses of symlinks intact in most cases, including when the symlinks point to something outside the DWiki page directory.
Redirects to http:// links or absolute URL links are a convenient way of creating WikiWord abbreviations to external things for local use. Make an appropriate REDIRECT file, stick it in your Aliases area, and now every page in the DWiki can say GoogleSearch or something and get a link, bam.
(WikiWord redirection rewriting means that in many cases the generated link will even point to the real target instead of the REDIRECT file, as you can see here.)
Hello, I am a DWiki
DWiki stands for 'Dinky Wiki', which is what ChrisSiebenmann calls this for lack of a better name. As far as Chris knows on a casual scan, 'DWiki' is not being used as the name of any other Wiki software.
I (ChrisSiebenmann) wrote DWiki to have a good environment for writing documentation about how we do system administration work on our Unix systems. You can see a bigger list of Features if you want.
DWiki's design choices are very slanted towards making it as easy as possible for us to write, revise, and maintain system documentation. (Because on past evidence, it if isn't dirt easy we just aren't going to do it.)
I like WikiText, because it is a simple, low-effort way to write documentation that comes out looking decent. But I don't like the wiki interface for writing it: web browsers make crappy editing environments and limit the sort of changes you can easily do. So I wrote DWiki to have a good system for displaying wikitext that we'd write through other means.
Wiki or CMS?
Some people say (strongly) that DWiki is not a Wiki because people (currently) can't edit DWiki pages over the web; they argue that instead it should be called a CMS (a (web) Content Management System).
I'm willing to accept this argument in theory, but ...
I like punchy, usefully descriptive names. My personal opinion is that 'wiki' is one: calling DWiki a wiki tells you a great deal about it, while calling it a CMS tells you almost nothing.
So while I may be willing to accept the argument, DWiki stays being called a wiki (and keeps the 'Wiki' in the name).
I maintain web-based editing makes little sense for us, and wrote a bunch about why in WhyNotWebEditing.
And one can always have a big debate over at the granddaddy Wiki, at http://c2.com/cgi/wiki?WikiPrinciples.
(One comment.)
Why DWiki doesn't have web page editing
One of the signature Wiki features is that people edit pages over the web, often anyone and without restrictions (as the original Wiki was/is). It's said that this is a defining trait of Wikis, and that without it what you have isn't really a wiki.
DWiki has no from-web editing of pages. There are several reasons why.
Interface power
A web browser's form input text boxes are a totally crappy editing environment compared to what I have on a Unix system. Yeah, sure, I could require Javascript and load a huge editing library and maybe get somewhere, but a) I browse with Javascript off and b) am I going to get half as good as GNU Emacs or vi or sam? (I don't think so.)
So I want the primary way of editing DWiki pages to be from Unix, through the filesystem, with real editors. (And it is.)
Global edit doesn't make sense for us
The principles of global edit permissions leading to the world help write your pages simply don't make sense for us. DWiki's goal is to let us easily document how our Unix systems work. We're the only people who can write most of that documentation; outsiders can at best add side commentary.
This would be different if we were interested in running a Wiki on system administration best practices or the like. But we're not; we're just documenting our systems. We let other people read it so that they can learn from anything interesting we do (and that's primarily aimed at other people at the University of Toronto).
It's a drain we can't afford
Anything that allows semi-public writing on the Internet requires tending. Wikis are no exception to this rule.
Like many places, we are historically very bad at creating documentation. The more effortless I can make the process, the better the odds that we will actually write documentation.
Keeping DWiki running is part of the overall process; the less effort this takes, the better, especially if we aren't actively writing documentation at the time. Thus, I don't want DWiki to take up any time when we're not actively writing things with it.
If DWiki allowed web writing from anything except a small set of people, we would have to tend it. It is simpler and less risky to avoid that, especially given that we can't expect significant contributions from outsiders.
Skipping hard design problems
Eliminating web-based editing immediately kills the need to tackle a bunch of hard problems, because Unix handles them for me. Particularly, I don't need to authenticate people or do access control, provided I'm willing to let everyone read (I am, so far).
Access control, authentication, and registering people is not an easy area. It's also one where failures and program bugs can have severe consequences. Not having to worry about that means that DWiki is faster to write, smaller, and safer.
I also don't have to worry about random outsiders writing pages that make extensive use of expensive DWiki features, or writing things in pages that cause rendering errors.
But web editing can be done from anywhere!
Pragmatically, the odds of us wanting to edit our systems documentation from anywhere that we can't just run
sshto log in to our servers is fairly low. This is especially the case given that there are Java SSH applets, so that any browser that runs Java can let us log in to our servers.DWiki is aimed at the low-hanging fruit of the 90% or 80% or so solution. (I maintain that any wiki is, partly because the text rendering is deliberately simplified.)
The future: maybe limited web editing
The most likely web editing feature for DWiki to pick up is to let web people write comments on pages but not edit the pages themselves. This would let outsiders give us feedback and commentary without running the risks of scribbling over valuable page content.
This would still require me to either write an authentication system or live with the likelyhood of comment spammers showing up to yammer madly. Plus some of the above worries.
(The clever person will notice that some of this future has arrived. DWiki now has an authentication system and comments, although both will be improved in the future.)
(2 comments.)
The code structure:
There's three chunks of code: the HTTP layer, the HTML view core, and the model.
The model deals with view-independant wiki level things, primarily retrieving raw pages and templates. (To do this it calls on a storage pools managed by a storage layer; the storage layer handles much of the RCS magic.)
The DWiki HTML view core gets a request context and is responsible for returning a response, whether that be rendered page content, redirections, or (rendered) errors. Renderers and template expansion are part of the HTML view core.
The HTTP layer is responsible for generating the request context, sending the response (including conditional GETs and other fun), and giving the HTML view core ways of generating proper URLs for given wiki pages.
The split between HTML view core and HTTP layer exists because the HTML view core is agnostic about how it is connected to the web, while the HTTP layer is intimiately tied to CGI-BIN versus Python BaseHTTPServer versus etc. So the HTML view core has everything that is web server independant.
FIXME: investigate this Python SCGI thing I've heard bits about. Or is that WSGI? See http://www.python.org/peps/pep-0333.html and http://wiki.python.org/moin/WSGIImplementations. Unfortunately on a preliminary look it seems I might as well write to CGI-BIN to start with.
I think that this is almost but not quite Model-View-Controller, but then I don't understand how MVC works (especially on the web).
To look at:
- http://java.sun.com/blueprints/patterns/MVC-detailed.html
- http://www.phpwact.org/pattern/model_view_controller
This suggests I am almost MVC except that my Controller is smeared over View code and that I have split the View into two pieces: the HTTP layer and the HTML view core.