Extension talk:CategoryTree

From MediaWiki.org
Jump to: navigation, search
Start a new discussion
First page
First page
Previous page
Previous page
Last page
Last page

Insert CategoryTree right of Content?

How can i insert the categoryTree to the right of the Contents box? Also, can i encapsulate the categoryTree in a box like the Content?

AmazingTrans (talk)16:17, 29 June 2015

Split a long list into Multi-Column Lists

Edited by 2 users.
Last edit: 21:51, 21 June 2015

Hi all,

Would it be possible to split a long list into multiple horizontal columns?

For example, every 50 categories, a new list is created on the right (keeping the alphabetical order)

Thanks for your help!

Samuel Goujon (talk)14:39, 4 May 2015

Replacing ► with +

Hi all, Is it possible to replace ► sign with +? My users does not find it obvious that ► is for expanding.

Grerika (talk)16:13, 21 April 2015

There are 3 system messages that MediaWiki administrators can change to get the behavior you desire:

siebrand (talk)14:23, 24 May 2015

Hide hidden categories

Is there a way to hide hidden categories from the tree?


Amichai Nachmani (talk)13:58, 12 May 2015

Fix for making CategoryTree work in sidebar again with MW 1.24.1 and Vector skin

Edited by 0 users.
Last edit: 11:07, 12 March 2015

Hi all, I used to offer a CategoryTree in my MediaWiki sidebar with MW 1.20.4. Everything worked well, but since my update to MW 1.24.1 all appropriate releases of CategoryTree stopped working in the sidebar. This includes the REL1_24 version but also the development master version. The problem is, that the expandable symbols are not shown at all and no click handle is registered. Interestingly CategoryTree works perfect as part of a WikiPage in parallel to not work at all in the sidebar.

I figured out that the way how the ext.CategoryTree.js works is that it uses a mw.hook to access the WikiPage content and to make CategoryTree working there. But obviously the sidebar is not part of the content which is access by this approach. I tested it by just removing the whole content in the ext.CategoryTree.js and literally just the inner section of my page disappeared but the sidebar was still there together with some other navigation content. So I am looking for a fix to have ext.CategroyTree.js to access the whole content including the sidebar.

I am no MediaWiki nor js nor php specialist, but after looking into the vector skin, I figured out how the skin accesses the whole content. I decided to give this appraoch a try, so I modified the beginning of ext.CategoryTree.js (which is located in extensions/CategoryTree/modules by the way) to make it look like this:

//( function ( $, mw ) {
//   mw.hook( 'wikipage.content' ).add( function ( $content ) {
jQuery( function ( $ ) {
                * Sets display inline to tree toggle
               function showToggles() {

and the end of ext.CategoryTree.js to look like this;

        // Register click events and show toggle buttons
        $( '.CategoryTreeToggle' ).click( handleNode );
   } );
//}( jQuery, mediaWiki ) );

From my understanding this gives the ext.CategoryTree.js access to the whole page content. So good news is, that everything works well after this modification, CategoryTree in the sidebar works like expected.

So now I have a question to all MediaWiki specialists: is this a valid approach to solve the problem? Or does it cause tremendous load to the system or break system concepts?

Bhuber (talk)11:07, 12 March 2015

I think a crucial change is missing from the js code you posted, something like:

jQuery( function ( $ ) { var $fullcontent = $(this);

And later, access fullcontent instead of content, e.g.

function showToggles() { $fullcontent.find( 'span.CategoryTreeToggle' ).css( 'display', 'inline' ); }

Anyway, the hints about the sidebar not being part of the content and looking at vector.js for reference were very helpful to me, and I can now show a category tree anywhere in the skin. Thanks!

As for your question: Don't know. I haven't noticed any problems.

Also, sorry about editing the subject of your post. Initially, I couldn't respond because of this:

This page can only be edited by users with the autoconfirmed right because it matches the following title blacklist entry: .*Make.*cat.* autoconfirmed

By now, my account is confirmed. Changing the subject hadn't helped either.

David6243 (talk)08:52, 19 March 2015


you are absolutely right, for some weird reason I missed to add two really important changes...

Generally speaking, you want to replace any use of the term $content.find by a single $, which refers to the whole DOM from my understanding. This needs to happen two time in the ext.categoryTree.js:

               function showToggles() {
                       $content.find( 'span.CategoryTreeToggle' ).css( 'display', 'inline' );

needs to be modified to look like this:

               function showToggles() {
                       $( 'span.CategoryTreeToggle' ).css( 'display', 'inline' );


               // Register click events and show toggle buttons
               $content.find( '.CategoryTreeToggle' ).click( handleNode );

needs to be modified to look like this:

               // Register click events and show toggle buttons
               $( '.CategoryTreeToggle' ).click( handleNode );

So there is absolutely no need to search or build another $content var, obviously you can work on the whole DOM like the skin sample does.

PS: There is absolutely no need to excuse for making my post usable to you and others by doing whatever is required...

Bhuber (talk)16:21, 21 March 2015

Output a category tree anywhere in the skin

Edited by 2 users.
Last edit: 09:09, 6 June 2014

Hi all! I'm designing a skin, and I want to include a category tree in the footer. I'm trying to figure out the code necessary to output it, by I've been failing for hours. The problem is always the same: the tag gets parsed, but the ext.CategoryTree.js is not loaded, so the JavaScript is never run and the tree doesn't work. Below are some of my attempts, but none worked. They were all within the skin template class, which extends BaseTemplate. Thanks!

echo efCategoryTreeParserHook( 'Some category', array( 'mode' => 'all' ) );
$parser = new Parser();
echo efCategoryTreeParserHook( 'Some category', array( 'mode' => 'all' ), $parser );
$title = $this->getTitle();
$parser = new Parser();
$parserOptions = new ParserOptions();
$parserOutput = $parser->parse( '<CategoryTree mode=all>Some category</CategoryTree>', $title, $parserOptions );
echo $parserOutput->getText();
LFS (talk)22:45, 13 May 2014
Edited by another user.
Last edit: 16:17, 20 March 2015

I'm trying to do the same thing as Luis, unfortunately, with the same results. Actually, showing a tree in the regular sidebar would be good enough for me, but setting SidebarRoot and ForceHeaders has no visible effect, nor does adding "** categorytree-portlet" to MediaWiki:Sidebar.

Invoking the parser explicitly from the skin, using the third method above, produces a non-interactive tree, matching the description under no effect/error/sits on loading.

Any ideas? A quick hack would suffice ... Some more info below, but it's perhaps not that helpful -- I'm not a web developer, and still don't know much about MW. My version is 1.24 by the way. Cheers, David

Update: The solution that Bhuber outlined here is the quick fix I was hoping for. That in combination with the explicit call to Parser::parse.

Inside an article, the tree works flawlessly. When inspecting the source code of the generated webpage, I see no difference between the (working) tree inside the article and the tree in the sidebar. The showToggles() JavaScript function is even called in both cases; that function is supposed to make the expand/collapse arrows visible. However, after calling "css('display', 'inline')", the value of 'display' remains 'undefined' in the case of the sidebar tree. If I make the arrows visible by setting $linkattr['style'] = 'display: inline;' in CategoryTreeFunctions.php, clicking them has no effect; handleNode isn't called.

My custom skin is not derived from Monobook or Vector; switching to either of those makes no visible difference though., 10 March 2015

Only show pages with specific form

Hi, I really like this extension! I am wondering if it is possible in pages mode to show only pages which have given default form. I mean something like this: {{#categorytree: [[Page has default form::Person]] Person|mode=pages}}

Grerika (talk)14:13, 17 March 2015

Sorting articles in category - numbers

Is there any option to sort articles' names in such order as below?

I have now:

  xxx 1 yy
xxx 10 yy
xxx 11 yy
xxx 2 yy
xxx 20 yy
xxx 3 yy

And I want this:

  xxx 1 yy
xxx 2 yy
xxx 3 yy
xxx 10 yy
xxx 11 yy
xxx 20 yy
Monic abc (talk)09:54, 11 February 2015

Have you looked at these help files...

  1. Help:Categories#Sort_key and...
  2. Help:Sorting...?
Dennis J au (talk)11:55, 11 February 2015

Yes, but I don't know how to use these tips. I tried do sth like this:


but it doesn't really works - nothing has changed. ("Levels" is my category with articles)

Monic abc (talk)07:56, 13 February 2015

I'm not a programmer, but when you add your articles to your "Levels" category you do it by adding something like this...


... to your article page.

If your article needs to be at the top of the sort list, e.g. for 'xxx 1 yy' do this


The '1' after the pipe character '|' is a 'sort key' which will bring the article with that key to the top of the sort.

For the rest of the articles in your example, just make the sort key equal to the number of the article, like this

For article 'xxx 10 yy' make the sort key '10' by adding the following to that article's page...


For article 'xxx 11 yy' add this...


for 'xxx 2 yy' add this...


for 'xxx 20 yy' add this...


for 'xxx 3 yy' add this...



Try that and see how it goes.

Dennis J au (talk)08:05, 14 February 2015

Thanks a lot! I thought that I have to edit some options in line with CategoryTree, not article's category. What works for me:


Number without brackets didn't work, so I used this "[number]".

Monic abc (talk)09:19, 16 February 2015

CategoryTree broken after updating to 1.21.1 and installing new CategoryTree Snapshot

I had a mediawiki with version 1.20.3 and just updated to 1.21.1. The update was successful and I was able to restore my database and other extensions.

However CategoryTree was not working after installing new mediawiki version 1.21.1. The Category list populates, but you cannot drill down through the category lists. The category arrows/+ do not display AT ALL, it is just a straight list of categories I could not even try to expand them because there is no option available to do so.
SO I downloaded the new snapshot of category tree for version 1.21.
Installed the extension.
Confirmed LocalSettings are configured for CategoryTree as such:
require_once( "$IP/extensions/CategoryTree/CategoryTree.php" );
$wgUseAjax = true;
and to get it in sidebar:
$wgCategoryTreeSidebarRoot = 'Category:article_name';
$wgCategoryTreeForceHeaders = true;

I have even tried following previous guides and modifying my CategoryTreeFunctions.php (ref: [1])
from $linkattr['style'] = 'display: none;'; // Unhidden by JS
$linkattr['style'] = 'display: inline !important;'; // Unhidden by JS
and tried changing CategoryTree.php (ref:[2])
function efCategoryTreeParserOutput( $outputPage, $parserOutput ) { if ( !empty( $parserOutput->mCategoryTreeTag ) ) { CategoryTree::setHeaders( $outputPage ); } return true;
function efCategoryTreeParserOutput( $outputPage, $parserOutput ) { CategoryTree::setHeaders( $outputPage ); } return true;
but making those above changes to CategoryTree.php/CategoryTreeFunction.php causes the whole site to goto a Error 500 page, so I have undone the above two changes, but I am still back to the point where I cannot drill down thru the category tree it only shows the top level categories now. I have even tried running update.php again but still does not resolve the issue. I have tried to find other threads regarding this, but I could not find any. Any help will be greatly appreciated, thanks...

Afinderp (talk)19:53, 14 June 2013

i'm having this same issue. upgrading from 1.19 to 1.23. upgraded mediawiki and database as well as moving from php 5.3 to php 5.6. pulled latest 1.23 code from here.

afinderp were you ever able to resolve this issue? it's pretty sad that no one ever responded to your post.

Zeefreak (talk)20:14, 12 December 2014


as I just ran into the same problem on my installation, please check the /var/log/apache2/[yourwikiname]-error.log

It might be that you get some pcfg_openfile: unable to check htaccess file, ensure it is readable errors. In that case, make sure the permissions for the folders of the extension are set correctly. I was able to overcome my problem by doing a chmod 755 /var/lib/mediawiki/extensions/CategoryTree/modules

You can check if that's your problem by issuing the following command: su – www-data -s /bin/bash -c “cd [replacebyyourextensionpath]/CategoryTree/modules; ls -la”

If that returns a "permission denied" on top of the results, then you have the same problem I had

~~----, 20 January 2015

so it turns out my issue was PEBCAK. my upgrade script had an error and i was actually pointing to the old 1.19 CatagoryTree code and not the new. once i fixed that and everything was running the new code it worked fine.

sorry it took me so long to report back.

Zeefreak (talk)16:01, 12 February 2015

Category link to expand functions

Is it possible to make Category and Subcategory link with expand functions. And disable link to category page.

Skontakt (talk)16:39, 31 January 2015

There have been a number of requests for this feature to be added to CategoryTree, see here... Thread:Extension talk:CategoryTree/Suggestion: CategoryTree enhancement for touch screens from May 2013 and here... Thread:Extension talk:CategoryTree/Suppress links to categories, only link to pages. from Oct 2013. Perhaps if someone logged a bug with this feature request it might get actioned? I don't understand Mediawiki extension development and enhancement processes.

Dennis J au (talk)13:09, 1 February 2015

Problem loading data. Please wait a moment and try again

With MW git master + CategoryTree git master, my category tree shows one level. Clicking on the arrow produces the message: Problem loading data. Please wait a moment and try again

If I turn on debugging, I see the following in the backtrace:

[GlobalTitleFail] MessageCache::parse called by CategoryTreePage::execute/Message::parse/Message::toString/Message::parseText/MessageCache::parse with no title set.

Could be related to this: https://phabricator.wikimedia.org/T25307

Wmat (talk)21:49, 15 January 2015

There is a bug logged directly relevant to this: T44938 Expanding widgets fails for numerical-only categories with "Problem loading data", no request sent

The problems is still present in MW 1.24.0

If you look at this bug log, a user known as Schnark has noted that there is a problem with some Javascript code that turns numeric categories into 'null' titles. This situation would tie in with your debugging backtrace message.

Of course there could be more to your problem than this.

Dennis J au (talk)00:36, 16 January 2015

I got this fixed today. It turns out that HotCat from https://commons.wikimedia.org/wiki/MediaWiki:Gadget-HotCat.js fixed my issue. There must be some caching going on somewhere though as it took a number of hours for my wiki to start working again. Apparently this problem struck Commons around Jan.14th or so. Hence, the updated HotCat.

Wmat (talk)19:42, 16 January 2015

<categorytree> in Special pages

After installing CategoryTree (Mediawiki 1.23) on my Special pages, I am seeing <categorytree> as a link. Anyone know how to fix this? The extension is working fine other than that.

Kmacdowe (talk)22:32, 7 November 2014

This means that MediaWiki:Categorytree is missing though this is pretty strange. I have seen this on the Wiki of the Free Software Foundation, too. Probably some other extension you installed does not play with the CategoryTree extension.

[[kgh]] (talk)18:59, 8 November 2014

Thanks kgh. It is installed, and the tag works on my regular pages so this isn't a show stopper but it is odd. Thanks for the help.

Kmacdowe (talk)03:50, 11 November 2014

Permissions issue using version c7333ea on mediawiki 1.23

I've an issue with some users with restricted (read only) access being unable to expand any node, seeing the tree wherever it is rendered, but getting a load failure, try again later message whatever node they try to expand.

I suspect it is an incompatibility with my own extension Extension:NSWhitelist but haven't been able to figure out what, yet.

I've ruled out browser issues, and a user with full rights can use it fine. Can someone tell me what user rights are needed to expand a node? Must you be able to read a particular namespace?

Hoggle42 (talk)10:31, 31 October 2014

Have narrowed it down to a read permission issue - whitelistread is not sufficient for this url:


The user has read access to the three indicated namespaces, but without a title there appears to be no way to grant access to this url

Hoggle42 (talk)13:48, 31 October 2014

ajax dispatcher checks

( !User::isEveryoneAllowed( 'read' ) && !$wgUser->isAllowed( 'read' ) )

and throws an error if this is not the case - this means the TitleReadWhitelist is not checked, as no reference to the title is given.

So, if the user does not have global read access, they can't use categorytree.

hacked the core code to be (bad fix)

( !User::isEveryoneAllowed( 'read' ) && !$wgUser->isAllowed( 'read' )  && !$this->func_name == 'efCategoryTreeAjaxWrapper')
Hoggle42 (talk)14:16, 31 October 2014

Does userCan( 'read' ) work any better?

Nemo13:37, 1 November 2014

that's a title method - no title in the request.

The problem is that titlereadwhitelist gives permissions on a per-title basis (in this case to user groups) and the ajax request only cares about the user's global permissions. I could use canRead if the request included a title.

Hoggle42 (talk)09:26, 3 November 2014

{{FULLPAGENAME}} in Category Tree

Hey there!

I wanted to make a template taking some work from me adding the category tree the category pages. It looks like this:


Sense behind that was to just add the template without having the need to type in the whole category:xy-thing.

Do you have an idea why it doesn´t work?

Thanks and best regards!, 10 September 2014

force categorytree to update when add new page.

I am invoking categorytree with the syntax {{#categorytree:Embryo|mode=pages|showcount|depth=2 etc. When I create a new page and add it to the category Embryo, categorytree will not list the new page. I can close/open the page that invoked categorytree, login again with no effect. If I look directly at the page Category:Embryo the new member page is listed immediately. The only way I can get the {{#categorytree:Embryo etc to update is to resave the page where it occurs. Same behavior if I use the tag syntax.

There must be a better way, I thought this function was dynamic. No obvious warnings of this behavior on the relevant help page or in discussions. Suggestions?

Siggiae (talk)02:53, 27 August 2014

I too would like a solution to this., 5 September 2014

Do not show the page you are on

Could a new attribute be implemented that would allow the current page you are on to be not shown in the list? For example, if there are 10 pages in a category and you are on one of them (it's opened), only nine pages would be shown in the list as the page you are on (that is opened) would not be shown. Sometimes it's useless to list the page you are on, if you are already on it.

Hartz (talk)17:37, 2 September 2014

The attribute could be for example: except=current.

Hartz (talk)17:41, 2 September 2014

How to keep CategoryTree stayed opened after clicking any category in sidebar in Vector skin?

When I am going down in one category and subcategories (depth 5-6), after loading the specified category and then hitting the "back" button on the browser , the category tree is folded again. Is there any chance the tree stays opened? Please reply ASAP... How to keep nodes expaneded even after clicking back button in browser.Any code changes to be done in Categorytree extension? It would be great to have the tree expanded to the current page after clicking any article , so that the users can get a quick impression about the location of the current article in the overall context.

Satyamcompany (talk)21:30, 25 April 2013

iam also facing same problem.., any solution??, 17 December 2013

Hi, I did a small dev to offer this feature to everybody. Please refer to "CategoryTree in Sidebar stayed opened". Do not hesitate to comment :-)

Cornucopia (talk)11:48, 20 February 2014


I can't get it to work. Is it all to just copy the JavaScript to ext.categoryTree.js ?, 24 February 2014

Hi, in the version of CategoryTree I am using, it is not the file ext.categoryTree.js but the file CategoryTree.js.

Be sure you are using a similar version of CategoryTree else you may need to merge my modifications.

FYI, sometimes it does not work with recent IE due to the default compatibility mode set to a "too old" IE version (the IE "intranet mode" can also introduce such "too old" IE version). Tell me if it solves your issue. Best Regards

Cornucopia (talk)15:48, 24 February 2014

Hi, I am porting my patch to Mediawiki 1.22.2 and the related CategoryTree extension. I keep you in touch. Best regards.

Cornucopia (talk)19:37, 25 February 2014

CategoryTree in SideBar with HideRoot set to true

I changed the file "CategoryTreeFunctions.php" to the following:

if ( !$hideroot ) {
				$html .= $this->renderNode( $title, $depth, $wgCategoryTreeDynamicTag );
			} elseif ( $hideroot or !$wgCategoryTreeDynamicTag ) {
				$html .= $this->renderChildren( $title, $depth );
			} else {
				$uniq += 1;
				$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );

				$html .= Xml::openElement( 'script', array( 'type' => 'text/javascript', 'id' => $load ) );
				$html .= 'categoryTreeLoadChildren("' . Xml::escapeJsString( $title->getDBkey() ) . '", '
						. $this->getOptionsAsJsStructure( $depth )
						. ', document.getElementById("' . $load . '").parentNode);';
				$html .= Xml::closeElement( 'script' );

I added "$hideroot or" part. Don't know if this will have unwanted side affects in regular pages, but it does fix the problem of the Categories not displaying when hideroot is set to false., 1 June 2014

Upgraded to 1.22.6 & category tree not working

I have upgraded my wiki to 1.22.6 and downloaded the latest version of CategoryTree, I get this error:

"3d6d0149] 2014-05-16 13:07:35: Fatal exception of type MWException

Notice: Uncommitted DB writes (transaction from DatabaseBase::query (MessageBlobStore::clear)). in /home/wiki_op/website/mediawiki-1.22.6/includes/db/Database.php on line 3944"

Should there be DB updates for this version?

Thanks, Ailsa

AilsaNapier (talk)13:31, 16 May 2014

initial expanded categorytree tags

Until last year the categorytree-tag was initially expanded when I used wikitext like this: <categorytree mode=pages showcount="on" >Category:Tag_extensions</categorytree> . (=>

Tag extensions(574 P)


Since January, the tags are displayed collapsed. But I want to show the expanded version.

Boshomi (talk)13:43, 11 January 2014

The new default to collapsed didn't satisfact my needs either. Any workaround available?

Lugusto (talk)02:34, 14 February 2014
Tag extensions(574 P), 12 May 2014
First page
First page
Previous page
Previous page
Last page
Last page