Difference between revisions of "Template:When"
m |
m |
||
Line 5: | Line 5: | ||
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: | 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: | ||
:<tt><nowiki>{{#dpl:category=2006|category=April}}</nowiki></tt> | :<tt><nowiki>{{#dpl:category=2006|category=April}}</nowiki></tt> | ||
− | The parser function which adds this is very simple consisting of the following code in the ''LocalSettings.php'' file. | + | The parser function which adds this is very simple consisting of the following [[when.php]] code in the ''LocalSettings.php'' file. |
− | <php> | + | <php>{{:When.php}}</php> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 21:27, 26 April 2007
This template is not actually used, the #when parser-function is used to add time information to articles. Just add a single parameter which can be arbitrarily formatted time information, for example:
- {{#when:2009/4/24}} - best to do dates backwards like this otherwise it tries to use some weird American format
- {{#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 when.php code in the LocalSettings.php file. <php><?php
- Extension:WhenTemplate:Php
- - See http://www.mediawiki.org/Extension:When for installation and usage details
- - Started 2007-04-27
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('WHEN_VERSION', '1.0.1, 2007-05-10');
$wgExtensionCredits['parserhook'][] = array( 'name' => 'When', 'author' => 'User:Nad', 'description' => 'adds a new parser function called #when which expands to easily queryable time categorisation', 'url' => 'http://www.mediawiki.org/wiki/Extension:When', 'version' => WHEN_VERSION );
$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 .= ; return $cats; }
function wfWhenLanguageGetMagic(&$magicWords,$langCode = 0) {
$magicWords['when'] = array(0,'when'); return true; }</php>