Extension:Countdown

This is a MediaWiki 1.5 (and up I guess) extension that allows a wiki page to display one or more DHTML countdowns to a specified date. It is designed to allow the countdown text to be formatted using wiki syntax. Once it is installed you invoke it via the  countdown  tag which expects two arguments; In the contents of the tag you can use normal wiki markup with the added "tags" See below for some usage examples.
 * name - must be unique within the page. Just use "CLOCK1", "CLOCK2" and so on and you should be safe
 * time - this is the target time to count down to.
 *  - days to target time
 *  - hours to target time
 *  - minutes to target time
 *  - seconds to target time

Caveats:
 * The "name" attribute must be a valid JavaScript name. If you're unsure what that means, use only uppercase letters in the English alphabet (A-Z).
 * The "time" attribute, while pretty flexible, must be written in some standard parsable form. Use the examples below and modify if you're not familiar with what formayts that work.
 * This is really just a quick hack in its first version. It will probably blow up if fed certain input. Feel free to help improve it. Specifically I would like to get rid of the need for using a "name" attribute.

-- PEZ 20:32, 24 November 2005 (UTC)

See http://h2wiki.halowiki.net/wiki/Help:Countdown_Extension for some examples on a site where the extension is installed:

Example: Countdown to New Year 2010

 * Days: 
 * Hours: 
 * Minutes: 
 * Seconds: 

Example: Countdown to 2005 Christmas Eve in Sweden
 Santa will arrive in  days,  hours,  minutes and  seconds. Have you been a good boy/girl?

Countdown.php
setHook("countdown", "renderCountdown"); }

function renderCountdown($input, $args) { $name = $args["name"]; $targetTime = $args["time"]; $text = ' '. "\n"; $text .= '<script language="javascript"> var '. $name. ' = new countdown("' . $name . '"); ' . $name. '.Name                     = "' . $name . '"; ' . $name. '.TargetDate               = "' . $targetTime . '"; ';       global $wgOut; $text .= $wgOut->parse(ereg_replace('<([DHMS])>', '<span id="' . $name . '_\1">\1 ', $input)). "\n"; $text .= '<script language="javascript"> ' . $name. '.Setup ';       return $text; } ?>

countdown.js
The javascript code is based on Robert Hashemian's/Mun Rashid's countdown.js. I have made some adaptations to better support the flexible embedding in a wiki page that I want. Here's the code: /*	Author:		Robert Hashemian (http://www.hashemian.com/) Modified by:	Munsifali Rashid (http://www.munit.co.uk/) Modified by:	Peter Strömberg (http://halowiki.net/wiki/User:PEZ) */

function countdown(obj) { this.obj		= obj; this.Name		= "clock"; this.TargetDate		= "12/31/2020 5:00 AM UTC+0100"; this.CountActive	= true; this.Calcage		= cd_Calcage; this.CountBack		= cd_CountBack; this.Setup		= cd_Setup; } function cd_Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString; if (s.length < 2) s = "0" + s; return (s); } function cd_CountBack(secs) { try { document.getElementById(this.Name + "_D").innerHTML = this.Calcage(secs,86400,100000); } catch(e) {}; try { document.getElementById(this.Name + "_H").innerHTML = this.Calcage(secs,3600,24); } catch(e) {}; try { document.getElementById(this.Name + "_M").innerHTML = this.Calcage(secs,60,60); } catch(e) {}; try { document.getElementById(this.Name + "_S").innerHTML = this.Calcage(secs,1,60); } catch(e) {}; if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990); } function cd_Setup { var ddiff	= new Date((new Date(this.TargetDate)) - (new Date)); this.CountBack(Math.floor(ddiff.valueOf / 1000)); }