Extension:IfTemplates

From MediaWiki.org
Jump to: navigation, search

Other languages:
català • ‎Deutsch • ‎English • ‎español • ‎suomi • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil • ‎sicilianu • ‎中文
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
IfTemplates

Release status:Extension status beta

ImplementationTemplate:Extension#type Parser function
DescriptionTemplate:Extension#description Tests if a given page contains only template calls
Author(s)Template:Extension#username Ike Hecht (tosfostalk)
Latest versionTemplate:Extension#version 0.1 (2014-05-22)
MediaWikiTemplate:Extension#mediawiki > 1.21, likely earlier versions as well
PHPTemplate:Extension#php 5.3+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GPL
Download
Hooks usedTemplate:Extension#hook
ParserFirstCallInitManual:Hooks/ParserFirstCallInit

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

Check usage and version matrix.

The IfTemplates extension adds a parser function that tests if a given page contains only template calls. This can have a number of uses. For example, in your wiki you may be able to make the assumption that any pages that only contain template calls are stubs with no real content.

Installation[edit]

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

Usage[edit]

The extension's usage is similar to the #ifexist parser function. It takes an input string, interprets it as a page title, and returns one of two values depending on whether or not the page contains only templates.

{{#iftemplates: page title | value if only templates | value if doesn't exist or has non-template text }}

The function evaluates to true if the page exists & contains only templates. Otherwise it evaluates to false. Note that if the page exists but contains no template calls, it evaluates to false.

Warning Warning: This is an expensive parser function and may not function correctly if called too many times on one page.Please see this page for more information.