Extension:CategoryTree

The CategoryTree extension provides a dynamic view of the wiki's category structure as a tree. It uses AJAX to load parts of the tree on demand. CategoryTree was originally written by Daniel Kinzler as an external tool (see meta:User:Duesentrieb/CategoryTree). It was later integrated into the MediaWiki software with the help of Tim Starling.

Usage
CategoryTree can be used in three ways:
 * directly on the category pages,
 * as a "custom tag" (or "parser function") to show a category structure in-line on a wiki page,
 * and as a special page.

The CategoryTree extension adds [+] "expand" widgets to the subcategories listed on category pages. If Javascript is disabled, those widgets takes you to the category page (in earlier versions, it did nothing in that case).

The &lt;categorytree&gt; tag
Example:

The custom tag is called &lt;categorytree&gt;. For example, if you put &lt;categorytree&gt;Foo&lt;/categorytree&gt; on a wiki page, it will show the contents of category Foo as a dynamic tree on that page (see example to the right). The tag accepts the following attributes, using a HTML-like syntax :


 * mode: determines which pages are shown in the tree. This may be overridden by the use of the namespaces option. Possible values:
 * categories: show subcategories only (configuration constant CT_MODE_CATEGORIES)
 * pages: show subcategories and pages, except images (configuration constant CT_MODE_PAGES)
 * all: show all pages, subcategories, images, etc (configuration constant CT_MODE_ALL)
 * parents: list parent categories instead of subcategories (configuration constant CT_MODE_PARENTS). This puts CategoryTree into "inverse" operation (supported since 36892, July 2008).


 * depth: determines how many levels of the tree are shown initially. Default is 1, 0 means only the root node. The maximum value depends on the mode specified, and on the $wgCategoryTreeMaxDepth option. (introduced between r20410 and 20840, Mar 30 2007; fully functional even with $wgCategoryTreeDynamicTag since 36864, July 2008)
 * onlyroot : set this to "on" to only show the "root" node of the tree initially. Equivalent to depth="0". (introduced in 20385, March 13 2007) Deprecated as of 36864, July 2008: use depth="0" instead.
 * hideroot: set this to "on" to hide the "root" node of the tree, i.e. the mention of category Foo from the example.
 * hideprefix: determines when the namespace prefix should be hidden from entries in the tree (since 36864, July 2008). Possible values are:
 * always: always hide the prefix. Should be used only if all pages come from the same namespace (configuration constant CT_MODE_CT_HIDEPREFIX_ALWAYS).
 * never: never hide the namespace prefix, not even for categories (configuration constant CT_MODE_CT_HIDEPREFIX_NEVER</tt>).
 * auto: hide the namespace of categories, if only categories are shown, as with mode="categories"</tt> (configuration constant CT_MODE_CT_HIDEPREFIX_AUTO</tt>); This is equivalent to the old default behavior (before Jun 2008).
 * categories: always hide the namespace of categories, but show all other prefixes (configuration constant CT_MODE_CT_HIDEPREFIX_CATEGORIES</tt>). This is the new default behavior (since 36864, July 2008).


 * showcount: show the number of entries in subcategories (since 36864, July 2008). This is disabled per default for category trees inlined on pages, but enabled per default in category listings an on Special:CategoryTree.
 * namespaces: a list of namespaces from which pages should be shown in the tree (since 36864, July 2008). The entries in the list must be namespace names, separated by spaces. The main namespaces can be represented by "-" or "0". This overrides the mode</tt> option.
 * class, style, id, etc: The &lt;categorytree&gt; tag supports all standard HTML attributes for block elements (since 36864, July 2008. Before that, only style</tt> was supported).

The parser function
Since 25825 (2007-9-13), you can also use parser function syntax to place a category tree on a page. This works just like the &lt;categorytree&gt; tag, using a different syntax, e.g.  </tt>; options can be specified using the syntax for named template parameters, e.g.   </tt>.

Using the parser function syntax has the advantage that it allows you to use magic words, templates and template parameters when specifying the category to show. Some examples:
 * Using a magic variable to show "this pages" category tree (may be useful on category description pages):  </tt>.
 * Using a template to specify the category:  </tt> - the name of the root category would be defined by the contents of Template:Root_category.
 * Using a template parameter to specify the category, when using CategoryTree inside a template:  </tt> in Template:Baz can be called using

The Special:CategoryTree page
The special page is called Special:CategoryTree; there you can enter the name of a category and then browse its content.

Installing CategoryTree
Note: The latest version of the CategoryTree extension requires MediaWiki 1.13. The first version requires MediaWiki 1.8 (revision 16385 or later).

Download the latest snapshot and extract it into the extensions folder of your MediaWiki installation. Then add the following lines to your LocalSettings.php file (near the end):

Note that $wgUseAjax = true</tt> will enable the ajax framework in MediaWiki, which is required by the CategoryTree extension. AJAX is a term for using JavaScript to load parts of a page on demand. It is supported by all recent graphic web browsers.

Configuration
There are some options you can specify in your LocalSettings.php file:


 * $wgCategoryTreeMaxChildren: maximum number of children shown in a tree node. Default is 200.
 * $wgCategoryTreeAllowTag: enable &lt;categorytree&gt; tag. Default is true.
 * $wgCategoryTreeDynamicTag: loads the first level of the tree in a &lt;categorytree&gt; dynamically. This way, the cache does not need to be disabled. Default is false.
 * $wgCategoryTreeDisableCache: disables the parser cache for pages with a &lt;categorytree&gt; tag. Default is true.
 * $wgCategoryTreeHTTPCache: enable HTTP cache for anon users. Default is false.
 * $wgCategoryTreeOmitNamespace : do not show the namespace name for pages and categories. Default is false, namespaces are shown unless showing categories only. Deprecated as of 36864, July 2008: use $wgCategoryTreeDefaultOptions['hideprefix']</tt> instead.
 * $wgCategoryTreeMaxDepth: an array defining the maximum depth for each mode, to which the tree may be expanded initially using the depth parameter in a &lt;category&gt; tag. Per default, this is set to 2 for the "categories" mode, and 1 for other modes. To set it to 3 for categories and 2 for other modes, for example, you can use $wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 2, CT_MODE_ALL => 2, CT_MODE_CATEGORIES => 3);</tt>.
 * $wgCategoryTreeDefaultMode : the default mode to use when no mode attribute is specified in a &lt;categorytree&gt; tag. May be CT_MODE_CATEGORIES</tt> (the default), CT_MODE_PAGES</tt>, or <tt>CT_MODE_ALL</tt>.
 * $wgCategoryTreeCategoryPageMode : the mode to use when rendering trees on category pages. Deprecated as of 36864, July 2008: use <tt>$wgCategoryTreeCategoryPageOptions['mode']</tt> instead.
 * $wgCategoryTreeForceHeaders: if true, forces the scripts needed by CategoryTree on every page, instead of on-demand. This may be needed if a CategoryTree is embedded in an unusualy way, for example in a custom skin or in a system message (since 36888, July 2008).
 * $wgCategoryTreeSidebarRoot: root category to use for integrating the category tree in the sidebar (since 36920, July 2008). If not set, no tree is integrated (this is the default). Integrating a CategoryTree into the sidebar only works with skins based upon SkinTemplate, that is, Modern, Monobook, Chick, Simple, and MySkin, but not Standard, Nostalgia or CologneBlue.
 * $wgCategoryTreeDefaultOptions: default options to apply, as an array (since 36864, July 2008). The available options are described above. Example:
 * $wgCategoryTreeCategoryPageOptions: options to use on category pages, as an array (since 36864, July 2008).
 * $wgCategoryTreeSpecialPageOptions: options to use on Special:CategoryTree, as an array (since 36864, July 2008).
 * $wgCategoryTreeSidebarOptions: options to use when showing the tree in the sidebar, as an array (since 36920, July 2008).

Wiki is broken after installing CategoryTree

 * Turn on error reporting
 * Make sure you have all files installed
 * Make sure all of the CategoryTree extension files have mode 644, and the CategoryTree directory has mode 755.

Options in LocalSettings.php have no effect

 * Make sure you specify the options after including the extension.

Clicking the [+] has no effect, gives a JavaScript error or just sits on loading

 * Note that using the &lt;categorytree&gt; tag in system messages (MediaWiki-Namespace) may not work as expected - this is a known caveat. For a workaround, see  below.
 * Make sure you have <tt>$wgUseAjax = true;</tt> in your LocalSettings.php before including the extension.
 * Make sure you are using the latest version of the extension - the bleeding edge is at
 * If you are using rewrite rules or aliasing (e.g. to have "very short URLs" - i.e. wiki pages in the document root), make sure you have an exception in place for the /extensions directory, just like you would for the /skins directory. Also see below.

Browser reports a bad MIME type for CategoryTree.js and/or CategoryTree.css

 * Make sure your Webserver uses the correct mime types for .js and .css files
 * Enter the URLs directly into the browser and see if it is serving the pages at all, and not some error page; especially:
 * If you are using rewrite rules or aliasing (e.g. to have "very short URLs" - i.e. wiki pages in the document root), make sure you have an exception in place for the /extensions directory, just like you would for the /skins directory.

Member counts are wrong, [x] is shown instead of [+]
Since MediaWiki 1.13, CategoryTree can show the number of members of a category, and can show an [x] for tree nodes that do not have any children based on that number. This information is based on the new category table. However, populating that table with the current values does not always work when upgraring to 1.13. In that case, run the <tt>populateCategory.php</tt> maintenance script, if neccessary with the <tt>--force</tt> option.

Note to bot users
Bots and scripts that parse the HTML of category pages can use the <tt>notree</tt> URL parameter to force the traditional output. However, HTML output is generally not stable, so it is recommended to change your script to use the <tt>api.php</tt> to fetch category listings and similar.''

Using CategoryTree in system messages and custom skins
To use the CategoryTree in system messages or the sidebar, that is, to use it as part of the user interface instead of page content, you have to set <tt>wgCategoryTreeForceHeaders</tt> to <tt>true</tt>, so that the support scripts are linked on every page (normally, they are only linked "on demand", but that detection does not work for system messages). This works since 36888 (July 2008). If you try this without forcing the scripts to be included, you will find that Clicking the [+] has no effect / gives JavaScript error.

In older versions of CategoryTree, you have to modify the code to make this work: find the <tt>efCategoryTreeParserOutput</tt> function in the file <tt>CategoryTree.php</tt>, and remove the condition; i.e. it should then look like this:

Using CategoryTree in the Sidebar
Since 36920 (July 2008) with MediaWiki 1.13 (36917), you can integrate a CategoryTree in the sidebar simply by setting <tt>$wgCategoryTreeSidebarRoot</tt> to the category you want to use as a root. This only works with skins based upon SkinTemplate however, that is, Modern, Monobook, Chick, Simple, and MySkin, but not Standard, Nostalgia or CologneBlue.

For earlier versions of CategoryTree and/or MediaWiki, you'll need to install a mod to MonoBook.php to enable normal wikitext in the sidebar, see Wikitext in side bar --DJ 19:26, 24 January 2008 (UTC)

To append a link "CategoryTree" to your toolbox (sidebar) add following code to the javascript-page (e.g. monobook.js) of your skin and customize the URL "http://en.wikipedia.org/wiki/Special:CategoryTree".

A more generic version of this code can be found at Manual:Interface/Sidebar.

Weblinks

 * README file
 * SVN extensions module
 * download area with bundled version (alternative bundle). (NOTE: the bundled versions may not be up to date!)
 * Bug Search