Extension:YearsOld

From MediaWiki.org

Jump to: navigation, search

               

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
YearsOld

Release status: stable

YearsOld.png
Implementation  Tag
Description To calculate the Years passed since Date
Author(s)  Hidalgo Rionda (HsilamotTalk)
Last Version  (1.1.82) (10 Feb 2008)
MediaWiki  1.10.0
License No license specified
Download From Author's Site
Example  At "Tengo XX Años"

check usage (experimental)

[edit] What can this extension do?

Return the Years Passed since the given day, month and year.

[edit] Usage

Just put <yearsold d="01" m="01" y="2000"></yearsold> where you want to say "7" (Today is 03 Dec 2007, So since that date have passed 7 years)

[edit] Installation

Just unzip the content and add

require_once( "{$IP}/extensions/YearsOld/YearsOld.php" );

to your LocalSettings.php.

[edit] Parameters

InLine HTML

d="Day"
m="Month"
y="Year"

$wgYearsOldLimit = 5000000;

Limit to avoid users to abuse the extension to DOS the server with a high number.

[edit] Changes to LocalSettings.php

require_once("$IP/extensions/YearsOld/YearsOld.php");

[edit] Code

YearsOld only has one file:

YearsOld.php

<?php
if (!defined('MEDIAWIKI')) die();
# Not a valid entry point, skip unless MEDIAWIKI is defined
/**
 * Returns Age from the day, month, year given.
 * 2008-02-10 Bug: Using MKTIME just returns with valid unix timestamps, corrected
 * 2008-02-10 Limit: Limit of 5'000'000 years for avoiding abuse
 */
 
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'YearsOld (1.1.82)',
	'author' => 'Hidalgo Rionda',
	'url' => 'http://www.mediawiki.org/wiki/Extension:YearsOld',
	'description' => 'Adds &lt;yearsold d=&quot;DAY&quot; m=&quot;MONTH&quot; y=&quot;YEAR&quot;&gt;&lt;/yearsold&gt; and returns the Years passed since',
);
 
$wgExtensionFunctions[] = 'efYearsOldSetup';
 
function efYearsOldSetup() {
    global $wgParser;
    $wgParser->setHook( 'yearsold', 'efYearsOldRender' );
}
 
function efYearsOldRender( $input, $args, $parser ) {
	global $wgYearsOldLimit;
	if (!$wgYearsOldLimit) { $wgYearsOldLimit = 5000000; }
	$anio = $args["y"];
	if ($anio > ($wgYearsOldLimit - $wgYearsOldLimit - $wgYearsOldLimit) && $anio < $wgYearsOldLimit) {
		$multicin = 0;
		while ($anio < 1950) {
			$anio = $anio + 50;
			$multicin = $multicin + 1;
		}
		while ($anio > 2025) {
			$anio = $anio - 50;
			$multicin = $multicin - 1;
		}
		return htmlspecialchars( (intval(((time() - mktime(0, 0, 0, $args["m"], $args["d"], $anio)) / 60 / 60 / 24 / 365)) + ($multicin * 50)) );
	}
}

[edit] See also