1

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.

2
  • 1
    Do I understand this right; you want to be able to view which pages are using a specific extension within the article, as you would by reviewing a category page? – Alex Reid Oct 28 '15 at 20:59
  • @mezzo Yes, and also I want to further categorise the pages according to what parameters they use in the extension. – oks Oct 28 '15 at 22:48
1

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 */ );
2
  • It works great, thank you very much. The tracking and dynamic categories appear at the bottom of the page. (They don't appear in Special:Categories.) – oks Oct 29 '15 at 19:40
  • My mistake, it works perfectly. The tracking and dynamic categories appear at the bottom of the page, and (a little while later) in Special:Categories. – oks Oct 29 '15 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.