Extension:CategoryToolbox

Category:Extensions without an imageCategory:GPL licensed extensions
MediaWiki extensions manual
CategoryToolbox
Release status: experimentalCategory:Experimental extensions
Implementation Parser function Category:Parser function extensions
Author(s) Valerio Bozzolan
Latest version 1.0.0
Compatibility policy Master maintains backward compatibility.Category:Extensions with master compatibility policy
MediaWiki 1.27+Category:Extensions with manual MediaWiki version
License GNU General Public License 3.0 or later
Download Category:Extensions in GitHub version control
Category:All extensions

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

Features

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

Installation

  • Make sure that the Extension:Scribunto is installed
  • Download and place the file(s) in a directory called CategoryToolbox in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'CategoryToolbox' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Manual

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

The following documentation uses these terms:

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

mw.ext.cattools.newestPage

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

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

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

mw.ext.cattools.hasPage

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

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).

Category:Category extensions
Category:All extensions Category:Category extensions Category:Experimental extensions Category:Extensions in GitHub version control Category:Extensions with manual MediaWiki version Category:Extensions with master compatibility policy Category:Extensions without an image Category:GPL licensed extensions Category:Parser function extensions Category:ScribuntoExternalLibraries extensions