Extension:When

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
When

Release status: stable

Implementation Parser functions
Description adds a new parser function called #when which expands to easily queryable time categorisation.
Author(s) User:Nad
Version 1.01 (2007-04-25)
MediaWiki 1.6.0+
Download no link

The #when parser-function is used to add time information categories to articles. Just add a single parameter which can be arbitrarily formatted time information, for example:

{{#when:2009/4/24}}
{{#when:24 apr 2009}}
{{#when:24 apr, 4:30pm}} - current year is used here since not specified

The function expands to a set of category links to categorise the article into year, month, day-of-month, full-weekday-name and time (24 hour HH:MM:SS format). Articles exhibiting time can then be matched with a DPL query, for example:

{{#dpl:category=2006|category=April}}

The parser function which adds this is very simple consisting of the following code in the LocalSettings.php file.

<?php
$wgExtensionFunctions[]        = 'wfSetupWhen';
$wgHooks['LanguageGetMagic'][] = 'wfWhenLanguageGetMagic';
 
function wfSetupWhen() {
        global $wgParser;
        $wgParser->setFunctionHook('when','wfExpandWhen');
        return true;
        }
 
function wfExpandWhen(&$parser,$when) {
        $time = strtotime($when);
        $cats = '';
        $formats = array('A','d','B','Y');
        if (ereg(':|[ap]m',$when)) array_unshift($formats,'T');
        foreach($formats as $f) $cats .= '[[Category:'.strftime("%$f",$time).']]';
        return $cats;
        }
 
function wfWhenLanguageGetMagic(&$magicWords,$langCode = 0) {
        $magicWords['when'] = array(0,'when');
        return true;
        }
?>
Personal tools