From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
Release status: experimental
Implementation Parser function
Author(s) Valerio Bozzolan
Latest version 1.0.0
Compatibility policy master
MediaWiki 1.27+
License GNU General Public License 3.0 or later
Download https://github.com/valerio-bozzolan/CategoryToolbox
Translate the CategoryToolbox extension if it is available at translatewiki.net
Check usage and version matrix.

The CategoryToolbox extension allows to retrieve from Lua some informations about category/page relations.


  • Discover if a certain page belongs to a certain category (also recursively!)
  • Discover the latest/oldest page added in a certain category


Don't install in production: this extension is in an experimental status.

You can install this extension as any other extension. Note that it requires Extension:Scribunto.


Note that the provided functions are expensive. See Manual:$wgExpensiveParserFunctionLimit.

The following documentation uses these terms:

It means the category title eventually prefixed. E.g. Category:Category name as well as just Category name.
It means the page title eventually prefixed. E.g. File:Example.svg.
It means the namespace number. E.g. 0.
It means the recursion maximum depth. Accepted values are:
no recursion (default)
deep recursion (very expensive)
choose your recursion limit (less expensive) [NOT YET IMPLEMENTED]


mw.ext.cattools.newestPage( category, [ namespace ] )

Returns the page that is most recently added to the category, eventually only from a certain namespace.

It returns nil or an object with some page informations. An example of result:

  ns    = 6,
  title = 'Example.svg',
  date  = '2017-10-28 23:59:59'


mw.ext.cattools.oldestPage( category, [ namespace ] )

Exactly as above, but about the less recently added page to the category.


mw.ext.cattools.hasPage( category, page, [ depth ] )

Returns a boolean if the page belongs to the category.

As default, there is no recursion, so the maximum depth is assumed as 0.


mw.ext.cattools.havePages( categories, pages, [ depth ], [ mode ] )

If you don't specify mode or if it's AND: for each page provided in the pages table, it checks if it belongs to every category, provided in the categories table.

If you specify mode as OR: for each page provided in the pages table, it checks if it belongs to at least one category, provided in the categories table.

It returns table of booleans that is made by matching pages' IDs. An example of result:

  123456: true

Note that the depth parameter is supported only in newer MediaWiki versions (see phab:T179065). For older versions it's just assumed a deep recursion (very expensive).