Extension:CategoryToolbox
CategoryToolbox Release status: experimental |
|
---|---|
Implementation | Parser function |
Author(s) | Valerio Bozzolan |
Latest version | 1.0.0 |
Compatibility policy | Master maintains backward compatibility. |
MediaWiki | 1.27+ |
License | GNU General Public License 3.0 or later |
Download | GitHub: Note: |
The CategoryToolbox extension allows to retrieve from Lua some informations about category/page relations.
Features
[edit]- Discover if a certain page belongs to a certain category (also recursively!)
- Discover the latest/oldest page added in a certain category
Installation
[edit]- Make sure that the Extension:Scribunto is installed
- Download and place the file(s) in a directory called
CategoryToolbox
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'CategoryToolbox' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Manual
[edit]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 justCategory 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
[edit]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
[edit]mw.ext.cattools.oldestPage( category, [ namespace ] )
Exactly as above, but about the less recently added page to the category
.
mw.ext.cattools.hasPage
[edit]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
[edit]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).