Extension:YearsOld

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
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"
Parameters

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

Check usage and version matrix

What can this extension do? [edit]

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

Usage [edit]

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)

Installation [edit]

Just unzip the content and add

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

to your LocalSettings.php.

Parameters [edit]

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.

Changes to LocalSettings.php [edit]

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

Code [edit]

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)) );
        }
}

See also [edit]

Language: English  • español