[ info ]   [ edit ]

Programmers Notes

WikiEngine

Look at this class before any other, this is the heart of Pinkwino.

WikiContext

The WikiContext keeps track of the current request (and response) during the lifetime of a wiki request. Rather than passing WikiContext to almost every conceivable method, WikiContext uses java's ThreadLocal to allow each Thread to have one, and only one WikiContext objects.

Most (all?) servlet engines reuse a single Thread object between many http requests, so a single ThreadLocal could bleed information from one request to another. We don't want that! To mitigate this, WikiContext counts each "begin" and subtracts one for each "end". When the count gets down to zero, all of the information in the WikiContext is wiped.

To ensure this is sufficient, it is imporatant that every WikiContext.begin is paired with its corresponding WikiContext.end. If an end is missed, then the contents of the WikiContext will never be wiped (as the count will remain above zero forever).

WikiContexts are begun (and ended) in the WikiServlet class, and the WikiTag class. Both use try...finally constructs to ensure the end is always called.

If you attempt to do any wiki processing which is not within the WikiServlet, or within the body of the WikiTag, WikiContext will not have been initialised, and you will likely get exceptions thrown.

Wiki Storage

This interface is responsible for storing the contents of the wiki pages, and keeping track of the changes (the list of versions). Each namespace has its own WikiStorage, which allows great flexibility, including the ability to share one or more namespaces between wiki instances. This feature is used by me to have a single namespace called "wiki", which holds the help documentation, and is used by all of my wikis (mostly with a read-only wrapper).

Meta Data

This will (not written yet) hold the meta data for each page, including the backward dependancies for each page (so that you can find out which page links to a given page). This is completely seperate from WikiStorage, and therefore may look like an ugly solution at first. However, it does allow some neat tricks, for example, using the FileSystemStorage is simple to use command line tools such as "grep" and "cp" behind the scenes, and also benefit from the harder to maintain, but more powerful Lucene engine to store the meta data.

This also allows each wiki instance to have its own set of meta data, and yet share one or more namespaces.

Given that I plan to store who create each version in the MetaData, and that namespaces can be shared between wiki instances, this leads to a 'problem' :

If page X is changed by user Bob in one wiki instance, then this piece of meta information isn't visible from the other wiki instances. This is a good thing, because user Bob may not exists, or may not be the same person as the Bob, in the other wiki instance.