Extension:CategoryHook

A big part of wiki content maintenance is keeping articles in structured categories, but often there'd be many aspects of an article we'd like to categorise by, such as whether or not they contain various kinds of content, or whether their title fits a certain format etc. Many sites have general caretaking bots for this, but a more dynamic and efficient solution for auto-categorisation is to update the list just before the databases category links are updated when an article is saved.

This extension sets up a new hook called CategoryHook to which you can add auto-categorisation rules. Following is an example which adds articles to Category:Articles containing trees if they have any parser functions in their content.

The hook function has four parameters, the first two are the parser object and the article's wikitext content. The third is an array of the categories which will be added or removed, and the forth is the default sort key to use if adding a category (which is just the title of the current article).

The array which is passed is a list of all the categories which need to be added or removed, and each of these is described by a two element array containing a boolean for add (true) or delete (false), and the sort-key to use if adding.

Categorisation parser-function
A new feature has been added on 2007-05-06 which allows article categorisation to be done using a parser-hook instead of a link (i.e. using curly-braces instead of square-brackets). This is useful for articles which do not use the wiki-parser for their output, but still have their templates expanded.
 *   ''- categorises the article into Category:Foo with sort-key "Bar".

Installation
Save the code from CategoryHook.php as a file in your extensions directory and append it to your LocalSettings.php file as usual. You might want to check to see if a later version is available.