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.

Category Hook
This extension sets up a new hook called CategoryHook to which you can add auto-categorisation rules to LocalSettings.php (after including CategoryHook.php--see ). 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
The extension also adds a parser-function which allows article categorisation to be done using curly-brace syntax instead of a square-bracket link. This is useful for articles which do not use the wiki-parser for their output, but still have their templates expanded, such as CSS articles. The following example categorises the article into Category:Foo with sort-key "Bar".

Category conditional parser-function
A second parser-function called #ifcat was added in version 1.2.0 (2007-10-09) which allows content to be rendered conditionally based on whether or not the current title is a member of a specified category. The following example uses the new parser-function to render a help-related template if the current article is a member of the Help category, or renders an advertising template if not.

Installation
Save the code from OrganicDesign:Extension: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.

Change log

 * Version 0.2.0 (2007-10-09): Added #ifcat parser-function