Extension:CategoryTests

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
Category Tests

Release status:Extension status stable

ImplementationTemplate:Extension#type Parser function
DescriptionTemplate:Extension#description Provides a set of parser functions that trigger on the current user
Author(s)Template:Extension#username Ryan Schmidt (Skizzerztalk)
Latest versionTemplate:Extension#version 1.6.0 (2014-03-30)
MediaWikiTemplate:Extension#mediawiki 1.17+
PHPTemplate:Extension#php 5.3+
LicenseTemplate:Extension#license GNU General Public License 2.0
Download
Hooks usedTemplate:Extension#hook
ParserFirstCallInitManual:Hooks/ParserFirstCallInit

Translate the CategoryTests extension if it is available at translatewiki.net

Check usage and version matrix.

The CategoryTests extension provides a set of dynamic parser functions that trigger on the current user

Usage[edit]

This currently defines 3 parser functions for category testing.

  • {{#ifcategory:category|then|else|page}} -- tests if the given page is in the category given, then displays "then" or "else" (or current page if no page is given).
  • {{#ifnocategories:then|else|page}} -- tests if the given page does not belong in any categories, then displays "then" or "else" (or current page if no page is given).
  • {{#switchcategory:category1=result1|category2=result2|...|default}} -- Operates like the ParserFunctions #switch, but doesn't take an initial parameter (it just starts cycling through right away) and tests if the page is in those categories instead of comparing it to a value. You can specify to test other pages using #page=pagename, where it would then test that page instead of the current page until the next #page definition, in which case it will test that page now instead. Making #page empty resets it to the current page. If your default case needs an equals sign, you may use #default to declare it.

Installation[edit]

  • Download and place the file(s) in a directory called CategoryTests in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/CategoryTests/CategoryTests.php";
    
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

See also[edit]

  • Extension:ParserFunctions (For more general conditional constructs)
  • Extension:PageInCat (The main difference seems to be that PageInCat will always try to use categories from the current revision, while CategoryTests may sometimes use the categories from the previous revision, which could result in unexpected page content)