Topic on Extension talk:CategoryTree

How to Restrict CategoryTree to a Particular Namespace?

9
Summary by Johnywhy

"Category" is a namespace. So, when you use the namespaces parameter, you must include Category in namespaces, if you want subcategories to show up in the result.

Example:

{{#categorytree:TOC|hideroot|namespaces=Main Category}}

If you don't include the namespaces parameter, then "namespaces=Category" is implied.

The "mode" parameter is disabled by the "namespaces" parameter, but you can achieve categories mode by leaving namespaces blank. Subcategories will appear, but not pages:

{{#categorytree:TOC|namespaces=}}

hideroot works as expected.

.

Notes added to the Extension documentation:

Extension:CategoryTree#Notes on the 'namespaces' parameter

and

Extension:CategoryTree#When i use the namespaces parameter, i don't get any pages

Johnywhy (talkcontribs)

Re gunretort.xyz

Doc says:

a list of namespaces from which pages should be shown in the tree (since rev: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 option. 

But, none of these work-- i get an empty tree

{{#categorytree:TOC|hideroot|mode=pages|namespaces=Main}}
{{#categorytree:TOC|hideroot|mode=pages|namespaces=-}}
{{#categorytree:TOC|hideroot|mode=pages|namespaces=0}}
{{#categorytree:TOC|hideroot|namespaces=Main}}
{{#categorytree:TOC|hideroot|namespaces=-}}
{{#categorytree:TOC|hideroot|namespaces=0}}
Tacsipacsi (talkcontribs)

Of course you get an empty tree, as Category:TOC is empty. I works for me with an existing category.

Johnywhy (talkcontribs)

TOC isn't empty

Tacsipacsi (talkcontribs)

Just click on the red link above. It’s completely empty. (If you use another wiki, where it’s not, you should mention it. This extension works perfectly on this wiki.)

Johnywhy (talkcontribs)

For gunretort.xyz

Note, TOC tree works fine on my site, gunretort.xyz: returns all categories and pages. This works, no prob:

{{#categorytree:TOC|hideroot|mode=pages}}

The problem is `namespaces=Main` doesn't work. None of these work:.

{{#categorytree:TOC|hideroot|mode=pages|namespaces=Main}}

{{#categorytree:TOC|hideroot|mode=pages|namespaces=-}}

{{#categorytree:TOC|hideroot|mode=pages|namespaces=0}}

{{#categorytree:TOC|hideroot|namespaces=Main}}

{{#categorytree:TOC|hideroot|namespaces=-}}

{{#categorytree:TOC|hideroot|namespaces=0}}

@Duesentrieb

Tacsipacsi (talkcontribs)

The first one (namespaces=Main) works for me using the API (I haven’t tested the other ones). I used the API because I can’t test using the normal edit interface, as anonymous users cannot edit pages. (Please note that some security software may warn for possible XSS (cross-site scripting) attack for the above URL. It’s because of the curly brackets in the wikicode, and the page is absolutely safe to visit.)

Johnywhy (talkcontribs)

Thx for testing. I see your url is:

https://gunretort.xyz/api.php?action=parse&text={{#categorytree:TOC|hideroot|mode=pages|namespaces=Main}}

It brings up a page of raw json. I notice that it only contains the word "Welcome". It doesn't show any of my subcategories or pages.

I tried your syntax on a wikipage

{{#categorytree:TOC|hideroot|mode=pages|namespaces=Main}}

Again, the result is just the word "Welcome", which is the only page in the top-level TOC category. It does not have an assigned namespace: https://gunretort.xyz/index.php/Welcome

Other pages are in sub-categories of TOC, with no assigned namespace. They don't appear in the tree. Shouldn't they?

This syntax shows all sub-categories, all pages:

{{#categorytree:TOC|hideroot|mode=pages}}

Clue: Extension doc says "namespaces" parameter: >"This overrides the mode option." It's unclear what "override" means. But it seems it actually disables subcategories.

I performed another test: i created a page in the TOC category, and the "Published" namespace. I also moved a different page to Published namespace, in a subcategory. We get only the page in the top-level TOC category, Published namespace. More evidence that 'namespaces' parameter ignores subcategories.

{{#categorytree:TOC|namespaces=Published}}
Tacsipacsi (talkcontribs)
Johnywhy (talkcontribs)