This extension
comes with MediaWiki 1.31and above. Thus you do not have to download it again. However, you still need to follow the other instructions provided.
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, but was later integrated into the MediaWiki software with the help of Tim Starling.
CategoryTree
folder to your extensions/
directory.cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
wfLoadExtension( 'CategoryTree' );
CategoryTree can be used in three ways:
The CategoryTree extension adds ► "expand" widgets to the subcategories listed on category pages.
The <categorytree> tag[edit]Example. The result can be seen in the box below and on the right:
<categorytree mode="pages">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:
namespaces
option. Possible values:
0
)
10
), limited to 200 pages
20
)
100
). This puts CategoryTree into "inverse" operation (supported since r36892, July 2008).
$wgCategoryTreeMaxDepth
option. (Introduced between r20410 and r20840, Mar 30 2007; fully functional even with $wgCategoryTreeDynamicTag
since r36864, July 2008.)
depth="0"
. (Introduced in r20385, March 13 2007.) Deprecated as of r36864, July 2008: use depth="0"
instead.
hideroot=on
. For example, it will not display the category name Foo.
10
).
0
).
mode="categories"
(configuration constant 30
). This is equivalent to the old default behavior (before Jun 2008).
20
). This is the new default behavior (since r36864, July 2008).
showcount="on"
(since r36864, July 2008). This is disabled per default for category trees inlined on pages, but enabled per default in category listings and on Special:CategoryTree.
notranslations="on"
(since Gerrit change 526234, November 2019). This is disabled by default. If this option is set to "on", instead of the different translations (e.g. Page, Page/en, Page/fr, Page/de) only the standard translation "Page" is displayed and all translations are suppressed.
This doesn't affect "showcount", so still a bug.
<categorytree>
tag supports all standard HTML attributes for block elements (since r36864, July 2008; before that, only style
was supported).
Category is a namespace. Categories are shown in all modes by default, but specifying the namespaces
parameter hides them just like any other namespace not present on the list. If you want to list pages in a given namespace, including pages in subcategories, simply add Category to the namespace list.
Example:
<categorytree mode="pages" namespaces="Main">Manual</categorytree>
<categorytree mode="pages" namespaces="Main Category">Manual</categorytree>
The mode
parameter is overridden by namespaces
:
mode=categories
;mode=all
;mode=pages
will be used. It means that if the site configuration hasn't been changed, the following are equivalent (the first two are always equivalent, the third only if $wgCategoryTreeDefaultMode
is the default CategoryTreeMode::CATEGORIES
):<categorytree mode="categories">Manual</categorytree> <categorytree namespaces="Category">Manual</categorytree> <categorytree>Manual</categorytree>The {{#categorytree}} parser function[edit]
Since r25825 (Sep 13, 2007), 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:
{{#categorytree:{{PAGENAME}}}}
.{{#categorytree:{{root category}}}}
- the name of the root category would be defined by the contents of Template:Root_category.{{#categorytree:{{{1}}}}}
in Template:Baz can be called using {{Baz|Foo}}.The special page is called Special:CategoryTree; there you can enter the name of a category and then browse its content.
There are some options you can specify in your LocalSettings.php file.
You can no longer use CT_* constants in LocalSettings.php. Instead use 0
for category mode, 10
for pages, 20
for all, 100
for parents.
$wgCategoryTreeDefaultOptions['hideprefix']
instead.
$wgCategoryTreeMaxDepth = [10 => 2, 20 => 2, 0 => 3, 100 => 2];
.
0
(the default - categories), 10
(pages), or 20
(all).
$wgCategoryTreeCategoryPageOptions['mode']
instead.
$wgCategoryTreeDefaultOptions['mode'] = 'pages';
.
By default, when listing subcategories on a category page, each subcategory is followed by an integer, indicating how many subcategories lie beneath it, how many pages it contains, and how many files are in the category (if applicable):
You can change this behavior by overriding the system message MediaWiki:Categorytree-member-num. It takes five parameters:
The default value is ($5)
.
Tip: Use the ParserFunctions extension to provide if/then/else logic to display different parts conditionally. For example:
{{#ifeq:$1|0||$1 categories}}
A configuration to manage commas and spaces when outputting all info:
Abbreviation version:
({{#ifeq:$4|0|empty|{{#ifeq:$1|0||$1 C{{#ifeq:{{#expr:$3+$2}}|0||,}}}} {{#ifeq:$2|0||$2 P{{#ifeq:$3|0||,}}}} {{#ifeq:$3|0||$3 F}}}})
Full name version:
({{#ifeq:$4|0|empty|{{#ifeq:$1|0||$1 categories{{#ifeq:{{#expr:$3+$2}}|0||,}}}} {{#ifeq:$2|0||$2 pages{{#ifeq:$3|0||,}}}} {{#ifeq:$3|0||$3 files}}}})Wiki is broken after installing CategoryTree[edit]
$wgUseAjax = true;
in your LocalSettings.php before including the extension.$wgCategoryTreeDefaultOptions['namespaces'] = [ 0, NS_CATEGORY, NS_FILE ];
Since MediaWiki 1.13, CategoryTree can show the number of members of a category, and can show a grey arrow ► 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 upgrading to 1.13. In that case, run the populateCategory.php
maintenance script, if necessary with the --force
option.
In case you get only one level depth while visualing the tree, try to set in modules/ext.categoryTree.styles.css file display: none;
to display: inline !important;
.
The JavaScript intended to switch the tag style is somehow buggy.
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 the API to fetch category listings and similar.
"Category Not Found" message[edit]After you implement the CategoryTree plugin and add the code to show the tree, if you see a message that says Category Not Found, you need to add some content in your category pages. The category pages can't be red pages, basically. Click your category names, add some text in the category page, and then your tree should work fine.
Next 200 links do not work with CategoryTree installed[edit]Make sure the right version of this extension is installed, relative to the version of MediaWiki you have installed. In particular, versions of this extension made for versions of MediaWiki prior to 1.17 are not compatible with MediaWiki 1.17 and greater, and will cause issues where all the paging links on category pages are broken.
No pages are shown when using the "namespaces" parameter[edit]See above.
Using CategoryTree in system messages and custom skins[edit]In older versions of CategoryTree, you have to modify the code to make this work: 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; }
Since r36920 (July 2008) with MediaWiki 1.13 (r36917), you can integrate a CategoryTree in the sidebar simply by setting $wgCategoryTreeSidebarRoot
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.
If you want the CategoryTree on a different position in the sidebar, you can reference it on MediaWiki:Sidebar as "categorytree-portlet".
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 "w: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' , '[[w: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) .
Step by step if works easy:
$wgCategoryTreeSidebarRoot = 'Category:article_name';Using MediaWiki: namespace pages[edit]
If you want to create a link that goes to the generic categorytree (displayed as Category tree) when you're on a non-category page, and to a particular categorytree (displayed as View as category tree, with foo being the name of the category you're viewing) when you're on a category page:
** sidebarcategorytree-url|sidebarcategorytree
{{#ifeq: {{NAMESPACE}}|Category|View as category tree|Category tree}}
{{#ifeq: {{NAMESPACE}}|Category|Special:CategoryTree/{{BASEPAGENAME}}|Special:CategoryTree/Categories}}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4