Mobile app version of vmapp.org
Login or Join
Murphy175

: How to add a page to a category in MediaWiki from a tag extension I would like to put `<my-extension/>` onto a page and for the page's categories to be equivalent to if I put [[Category:Pages

@Murphy175

Posted in: #Mediawiki

I would like to put

`<my-extension/>`


onto a page and for the page's categories to be equivalent to if I put

[[Category:Pages with the my-extension tag]]


straight onto the page.

How is that done, please?
I tried to add to the function that's ?hooked to ParserFirstCallInit

$localParser = new Parser();
$localParser->parse("n [[Category::Pages with the my-extension tag]] n");


but it didn't work.

Edit 28-10-2015:
I want to sub-categorise the page according to the parameters provided to the tag, so that if I put

`<my-extension/>Input 1</my-extension>`


on a page, the page's categories are equivalent to putting

[[Category:Pages with the my-extension tag]]
[[Category:Pages using Input 1]]


straight onto the page.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murphy175

1 Comments

Sorted by latest first Latest Oldest Best

 

@Goswami781

For predefined categories, you can use tracking categories which have the advantage of being translatable and can be disabled by editing the MediaWiki namespace.

In your extension.json:

"TrackingCategories": ["my-extension-category"],


In the function that implements <my-extension>:

$parser->addTrackingCategory( 'my-extension-category' );


In your en.json:

"my-extension-category": "Pages with the my-extension tag",


For dynamic categories, you can just call

$parser->getOutput()->addCategory( 'Pages with the my-extension tag', '*' /* sort key */ );

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme