Extension:Calendar (Shane) extended

With this script I added functionality to the calendar similar to the phpwiki calendar:
 * every day is a link to a page. When you click that link, you automatically start editing that page. (current day is marked in bold, days that have an event are underlined)
 * on bottom of the calendar, all events (days that are edited) are summed up + their content is shown
 * the calendar defaults to the "current month"
 * You can follow links to next or previous months

Warning: I disabled caching for this to work. Since this is used on a 'private' wiki this is no problem. You probably should try disabling caching only for the page where you put the calendar.

I changed first day of the week from sunday -> monday, this is easily changed:
 * change order in $wday_names
 * add/change this code in function dayOfWeek($month,$year) :

No doubt this is code is quite ugly, and not very portable(language,html,css..?) but it works mighty fine here, maybe someone can use it too...

I use this script on a MediaWiki 1.6.5 this script doesn't work out of the box for mediawiki 1.9.3

Install
Create a file called 'calendar_extension.php' in your  directory, and add code below. 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!

calendar_extension.php
<?php
 * 1) Calendar Extension
 * 2) Creates a calendar of the month and year.
 * 3) Example Code
 * 4) this defaults to "current month"
 * 5) (I guess you can still use 2005-05 as well, in that case you won't be able to jump to next mont)
 * 6) (extended by petervanmechelen at gmail dot com)
 * 1) this defaults to "current month"
 * 2) (I guess you can still use 2005-05 as well, in that case you won't be able to jump to next mont)
 * 3) (extended by petervanmechelen at gmail dot com)
 * 1) (extended by petervanmechelen at gmail dot com)
 * 1) (extended by petervanmechelen at gmail dot com)

$wgExtensionFunctions[] = "wfCalendarExtension"; $wgExtensionCredits['parserhook'][] = array(       'name' => '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) {   /**    * check if date in $_GET-parameter * fallback on default this month **/       if($input=="") {           if(isset($_GET['month'])&&(isset($_GET['year']))) {               $input = ($_GET['month']<10?"0":"").date($_GET['month']." ".$_GET['year']); }           else {               $input = date("m Y"); }       }        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("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); 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)))-1; // remove -1 to make sunday first day of the week return $weekday_number; }

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

function showThisMonth {               $lastyear = ($this->month==1?$this->year - 1:$this->year); $nextyear = ($this->month==12?$this->year + 1:$this->year); $lastmonth = ($this->month==1? 12 : $this->month - 1); $nextmonth = ($this->month==12? 1 : $this->month + 1); $currentpage = "http://".$_SERVER['SERVER_NAME'].(strpos($_SERVER['REQUEST_URI'],"?")?substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],"?")+1):$_SERVER['REQUEST_URI']."?"); $params = explode("&",$_SERVER['QUERY_STRING']); for($i=0;$i