Extension:AgeParse

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
AgeParse

Release status:Extension status beta

ImplementationTemplate:Extension#type Parser extension
DescriptionTemplate:Extension#description Allows to calculate difference between two dates
Author(s)Template:Extension#username Mark Daly, Daniel Schuba
Latest versionTemplate:Extension#version 0.3.1 (2013-07-17)
MediaWikiTemplate:Extension#mediawiki 1.13+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
README
ExampleTemplate:Extension#example age from=1606-07-15 to=1669-10-04
ParametersTemplate:Extension#parameters
  • $wgAgeErrorBox
  • $wgAgeDefaultToday
  • $wgAgeZeroNegatives
Hooks usedTemplate:Extension#hook
ParserFirstCallInitManual:Hooks/ParserFirstCallInit

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

Check usage and version matrix.

The AgeParse extension calculates the number of years, months, and days between two dates (FROM and TO attributes). The extension does not use any PHP built-in functions so it can calculate an answer for dates before 1970 or after 2038. The purpose of this extension is to automatically calculate the difference between two dates. It is useful in historical or genealogical research sites since the author only needs to know the two dates and how he or she wants to show that information; the tag automatically calculates the difference. A global setting also allows FROM or TO (only one) to be optional, automatically using the current date (from the web site's server) for the missing date.


Repository[edit]

Download[edit]

Download using Git

git clone https://github.com/DaSchTour/AgeParse.git

Usage[edit]

Only the FROM and TO attributes are (usually) required. All other attributes are optional. The age tag is used in-line with text on the page so the calculated age becomes part of the sentence, list, etc.

Syntax[edit]

{{#age: from=yyyy-mm-dd | to=yyyy-mm-dd | format-ymd | left=c | right=c | errbox=yes | zeronegatives=yes}}

Attributes[edit]

Of the attributes below FROM and TO are required if $wgAgeDefaultToday is FALSE; otherwise, these attributes are optional. All other attributes are optional.

from=YYYY-MM-DD
  • ISO formatted starting date
  • Only optional if $wgAgeDefaultToday = TRUE
to=YYYY-MM-DD
  • ISO formatted ending date
  • Only optional if $wgAgeDefaultToday = TRUE
left=C
  • Optional text to prepend (add to left) of answer
  • Most commonly "(" to enclose answer in parenthesis
right=C
  • Optional text to append (add to right) of answer
  • Most commonly ")" to enclose answer in parenthesis
format=ymd | format=ym | format=y
  • Controls how much of answer to show
    • ymd = X years, Y months, Z days
    • ym = X years, Y months (days are not shown)
    • y = X years (months and days are not shown
  • Defaults to "ymd"
errbox=yes | errbox=no
  • Controls whether error box appears (if, of course, there is an error)
  • Overrides $wgAgeErrorBox
zeronegatives=yes | zeronegatives=no
  • Controls whether negative date-differences are rendered as '0 days' or whether an error is displayed instead.
  • This is useful when omitting FROM (which defaults to 'today') and setting an expiry date using TO.
  • After the expiry date the difference will show as '0 days'. Basically a days-countdown with a '0 days' floor.
  • Overrides $wgAgeZeroNegatives

Examples[edit]

{{#age: from=1368-01-01 | to=1644-01-01 |format=y}}
{{#age: from=1606-07-15 | to=1669-10-04 |left=( |right=)}}

Download instructions[edit]

Copy and paste the code found below and place them in files called $IP/extensions/AgeParse/AgeParse.php and $IP/extensions/AgeParse/AgeParse.body.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Copy and paste the language code found below and place it in a file called $IP/extensions/AgeParse/AgeParse.i18n.php.

Installation[edit]

To install this extension, add the following to LocalSettings.php:

require_once( "$IP/extensions/AgeParse/AgeParse.php" );
$wgAgeErrorBox      = true;  //true: show box if arguments/calculation cause error
$wgAgeDefaultToday  = true;  //true: FROM or TO default to current date if not provided
$wgAgeZeroNegatives = true;  //true: show '0 days' if calculated value is negative

Configuration parameters[edit]

The following settings can be added to LocalSettings.php:

$wgAgeDefaultToday = FALSE;
  • TRUE = automatically use current date if either FROM or TO attributes are not specified
    • Set this value then include FROM value in tag to calculate time between that date and the current date
    • Set this value then include TO value in tag to calculate time between current date and a future date (like a count down)
  • FALSE = FROM and TO values are required but will not default to the current date
  • Not set in LocalSettings.php defaults to FALSE
$wgAgeErrorBox = TRUE;
  • TRUE = show any errors using the 'errorbox' CSS format (usually a red box)
  • FALSE = show errors in-line with the page content
  • Not set in LocalSettings.php defaults to FALSE
  • This site-wide setting can be overridden using the 'errbox' attribute
$wgAgeZeroNegatives = FALSE;
  • TRUE = display '0 days' when the time difference is negative
  • FALSE = negative time difference will display an error
  • Not set in LocalSettings.php defaults to FALSE

See also[edit]