Extension:CategoryTree
From MediaWiki.org
|
CategoryTree Release status: stable |
|
|---|---|
| Implementation | Tag |
| Description | Provides a dynamic view of the wiki's category structure as a tree. |
| Author(s) | Duesentrieb |
| MediaWiki | 1.8 (revision 16385 or later), 1.11 (CategoryTree revision 30515 or later) |
| Download | svn (browse), bundle README log |
| Parameters | $wgCategoryTreeMaxChildren, $wgCategoryTreeAllowTag, $wgCategoryTreeDynamicTag, $wgCategoryTreeDisableCache, $wgCategoryTreeHTTPCache, $wgCategoryTreeOmitNamespace, $wgCategoryTreeMaxDepth, $wgCategoryTreeDefaultMode, $wgCategoryTreeCategoryPageMode |
| Hooks used |
SkinTemplateTabs |
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.
Contents |
[edit] 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 just do nothing.
- Note to bot users: bots and scripts that parse the HTML of category pages can use the notree URL parameter to force the traditional output. However, HTML output is generally not stable, so it is recommended to change your script to use query.php or api.php to fetch category listings and similar.
[edit] The <categorytree> tag
Example:
<categorytree mode=pages style="float:right; clear:right; margin-left:1ex; border:1px solid gray; padding:0.7ex; background-color:white;">Manual</categorytree>
The custom tag is called <categorytree>. For example, if you put <categorytree>Foo</categorytree> 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
- can be "categories", "pages" or "all" - see the Modes section below for the meaning of each. The default for this attribute is controlled by $wgCategoryTreeDefaultMode, and is initially set to CT_MODE_CATEGORIES, the equivalent of setting the mode attribute to "categories".
- 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 rev:r20410 and rev:20840, Mar 30 2007) - note: depth values greater than 1 do not (yet) work with $wgCategoryTreeDynamicTag enabled!
- onlyroot
- set this to "on" to only show the "root" node of the tree initially. Equivalent to depth="0". (introduced in rev:20385, March 13 2007)
- hideroot
- set this to "on" to hide the "root" node of the tree, i.e. the mention of category Foo from the example.
- style
- can be used to specify any CSS styles you would like for the tree.
[edit] The {{#categorytree}} parser function
Since rev:25825 (2007-9-13), you can also use parser function syntax to place a category tree on a page. This works just like the <categorytree> tag, using a different syntax, e.g. {{#categorytree:Foo}}; options can be specified using the syntax for named template parameters, e.g. {{#categorytree:Foo|hideroot|mode=pages}}.
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): {{#categorytree:{{PAGENAME}}}}.
- Using a template to specify the category: {{#categorytree:{{root category}}}} - 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: {{#categorytree:{{{1}}}}} in Template:Baz can be called using {{Baz|Foo}}
[edit] 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. The CategoryTree extension also adds a tab for this special page to every category page.
[edit] Modes
The category tree can be shown in different modes, determining what types of "leaves" the "tree" has:
- categories (constant CT_MODE_CATEGORIES): show subcategories only
- pages (constant CT_MODE_PAGES): show subcategories and pages, except images
- all (constant CT_MODE_ALL): show all pages, subcategories, images, etc
The CT_MODE_XXX constants can be used with configuration options (see below).
[edit] Installing CategoryTree
Note: The CategoryTree extension requires MediaWiki 1.8 (revision 16385 or later).
To install the required files, download the files from the SVN-source, linked in the weblink-section below. Follow the instructions in the included README.
I.E. Try;
svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/CategoryTree
Copy the CategoryTree directory into the extensions folder of your MediaWiki installation. Then add the following lines to your LocalSettings.php file (near the end):
$wgUseAjax = true; require_once( 'extensions/CategoryTree/CategoryTree.php' );
Note that $wgUseAjax = true; 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.
[edit] Options
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 <categorytree> tag. Default is true.
- $wgCategoryTreeDynamicTag
- loads the first level of the tree in a <categorytree> dynamically. This way, the cache does not need to be disabled. Default is false
- $wgCategoryTreeDisableCache
- disables the parser cache for pages with a <categorytree> 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.
- $wgCategoryTreeMaxDepth
- an array defining the maximum depth for each mode, to which the tree may be expanded initially using the depth parameter in a <category> 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);.
- $wgCategoryTreeDefaultMode
- the default mode to use when no mode attribute is specified in a <categorytree> tag. May be CT_MODE_CATEGORIES (the default), CT_MODE_PAGES, or CT_MODE_ALL.
- $wgCategoryTreeCategoryPageMode
- the mode to use when rendering trees on category pages. May be CT_MODE_CATEGORIES (the default), CT_MODE_PAGES, or CT_MODE_ALL.
[edit] Troubleshooting
[edit] 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.
[edit] Options in LocalSettings.php have no effect
- Make sure you specify the options after including the extension.
[edit] Clicking the [+] has no effect / gives JavaScript error
- Note that using the <categorytree> tag in system messages (MediaWiki-Namespace) may not work as expected - this is a known caveat. For a workaround, see #Using CategoryTree in the Sidebar below.
- Make sure you have $wgUseAjax = true; in your LocalSettings.php before including the extension.
- Make sure you are using the latest version of the extension - the bleeding edge is at [1]
- 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.
[edit] 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.
[edit] See also
Related problems and solutions on Bugzilla
[edit] Hacks
[edit] Using CategoryTree in the Sidebar
To use the CategoryTree in the sidebar (or elsewhere in the user interface), that is, to use it in a system message, you have to modify it a bit 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). If you try this without the modification below, you will find that Clicking the [+] has no effect / gives JavaScript error.
So, to make the CategoryTree work in the sidebar (or elsewhere in the user interface), find the efCategoryTreeParserOutput function in the file CategoryTree.php, and remove the condition; i.e. it should then look like this:
function efCategoryTreeParserOutput( &$outputPage, &$parserOutput ) { CategoryTree::setHeaders( $outputPage ); return true; }
You'll also 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".
function AppendCategoryTreeToSidebar() { try { var node = document.getElementById( "p-tb" ) .getElementsByTagName('div')[0] .getElementsByTagName('ul')[0]; var aNode = document.createElement( 'a' ); var liNode = document.createElement( 'li' ); aNode.appendChild( document.createTextNode( 'CategoryTree' ) ); aNode.setAttribute( 'href' , 'http://en.wikipedia.org/wiki/Special:CategoryTree' ); liNode.appendChild( aNode ); liNode.className = 'plainlinks'; node.appendChild( liNode ); } catch(e) { // lets just ignore what's happened return; } } addOnloadHook( AppendCategoryTreeToSidebar );
A more generic version of this code can be found at Manual:Interface/Sidebar#content of sidebar and toolbox (javascript).
[edit] 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
This extension is being used on one or more of Wikimedia's wikis. It means that the extension is stable and works well enough to be used by such high traffic websites. A full list of the extensions installed on a particular wiki is produced by Special:Version on that wiki.

