Extension:Calendar (Shane)

The Calendar extension extension creates a calendar of the month and year in any MediaWiki page.

Install
Create a file called 'calendar_extension.php' in your  directory, and add the following code...

Works on Mediawiki 1.5.x and 1.6.x.

Code
 'Calendar',	'author' => 'Shane',	'description' => 'adds tag, for calender creation',	'url' => 'http://meta.wikimedia.org/wiki/Calendar_extension' );

/* DO NOT EDIT BEYOND THIS LINE */

function wfCalendarExtension { global $wgParser; $wgParser->setHook( "calendar", "createmwCalendar" ); }

function createmwCalendar($input) {	global $wgOut; $input = $wgOut->parse($input, false); $array = explode(' ', $input); $month = $array[0]; $year = $array[1]; $mwCalendar = new mwCalendar; $mwCalendar->dateNow($month, $year); return $mwCalendar->showThisMonth; }
 * 1) The callback function for converting the input text to HTML output

class mwCalendar {	var $cal = "CAL_GREGORIAN"; var $format = "%Y%m%d"; var $today; var $day; var $month; var $year; var $pmonth; var $pyear; var $nmonth; var $nyear; var $wday_names = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); var $wmonth_names = array("January","Febuary","March","April","May","June","July","August","September","October","November","December"); function mwCalendar {		$this->day = "1"; $today = ""; $month = ""; $year = ""; $pmonth = ""; $pyear = ""; $nmonth = ""; $nyear = ""; }

function dateNow($month,$year) {		$this->month = $month; $this->year = $year; $this->today = strftime("%d",time); $this->pmonth = $this->month - 1; $this->pyear = $this->year - 1; $this->nmonth = $this->month + 1; $this->nyear = $this->year + 1; }

function daysInMonth($month,$year) {		if (empty($year)) {			$year = mwCalendar::dateNow("%Y"); }		if (empty($month)) {			$month = mwCalendar::dateNow("%m"); }		if($month == "2") {			if(mwCalendar::isLeapYear($year)) {				return 29; }			else {				return 28; }		}		else if ($month == "4" || $month == "6" || $month == "9" || $month == "11") {			return 30; }		else {			return 31; }				}

function isLeapYear($year) {     return (($year % 4 == "0" && $year % 100 != "0") || $year % 400 == "0"); }

function dayOfWeek($month,$year) { 		if ($month > 2) { $month -= 2; }		else { 				$month += 10; $year--; } 		$day = ( floor((13 * $month - 1) / 5) + 						$this->day + ($year % 100) + 						floor(($year % 100) / 4) + 						floor(($year / 100) / 4) - 2 * 						floor($year / 100) + 77); $weekday_number = (($day - 7 * floor($day / 7))); return $weekday_number; }

function getWeekDay {		$week_day = mwCalendar::dayOfWeek($this->month,$this->year); //return $this->wday_names[$week_day]; return $week_Day; }

function showThisMonth {	 	$output = '';	//	reset var $output = ' '; return $output; } }

?>

Install
Then simply add the following line to the end of your  file:

include("extensions/calendar_extension.php");

and you are ready to go! Go to the sandbox and see if it works!

Usage
Basic syntax for adding the calendar is, as detailed in the code:

05 2006

Comments
At present this extension appears to do little more than draw you up a calendar. But it does. You can add events to this calendar like this:


 * 1) name=mycalendar
 * 2) view=threemonths
 * 3) format = mycalendar-%year-%m-%d