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

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...

This script now works on MediaWiki 1.9.x and should work on all previous versions from 1.6 upwards. Micrology 19:37, 6 May 2007 (UTC)

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

 * 8) 2006-07-12
 * 9) patched to show "today" marked only in current month and current year
 * 10) patched to work with mw 1.7.0
 * 11) patched to let links to previous and next month work
 * 12) 2007-05-12
 * 13) patched to call the Parser in a way that works on 1.9.2+ by Nigel Gilbert 
 * 14) also a number of minor changes and corrections
 * 1) 2006-07-12
 * 2) patched to show "today" marked only in current month and current year
 * 3) patched to work with mw 1.7.0
 * 4) patched to let links to previous and next month work
 * 5) 2007-05-12
 * 6) patched to call the Parser in a way that works on 1.9.2+ by Nigel Gilbert 
 * 7) also a number of minor changes and corrections
 * 1) also a number of minor changes and corrections

$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, $argv, &$parser) {		$parser->disableCache; /**   * 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"); }       }
 * 1) The callback function for converting the input text to HTML output

$ret = $parser->parse($input, $parser->getTitle, $parser->getOptions, false, false); $array = explode(' ', $ret->getText);

$month = $array[0]; $year = $array[1];

$mwCalendar = new mwCalendar;

$mwCalendar->dateNow($month, $year); return $mwCalendar->showThisMonth($parser); }

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; // German weekday names //       var $wday_names = array("Mo","Di","Mi","Do","Fr","Sa","So"); // put sunday first to change order of the days // English weekday names var $wday_names = array("Mo","Tu","We","Th","Fr","Sa","So"); // put sunday first to change order of the days // German month names //       var $wmonth_names = array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni","Juli", "August","September", "Oktober", "November", "Dezember"); //English month names var $wmonth_names = array("January", "February", "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) {        $weekday_no = date("w", strtotime("1 ".$this->wmonth_names[$month - 1]." $year")); if ($weekday_no == 0) return 6; else return $weekday_no - 1; }

function showThisMonth(&$parser) {               global $wgScript; $viewEvents = ""; $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<count($params);$i++) {                   if((substr($params[$i],0,5)!="month") && (substr($params[$i],0,4)!="year")) {                       $currentpage .= $params[$i]."&"; }               }                if (strpos($currentpage,'action=purge')) { $purge=""; } else { $purge="action=purge&"; }               $a_lastmonth = $currentpage.$purge."month=".$lastmonth."&year=".$lastyear; $a_nextmonth = $currentpage.$purge."month=".$nextmonth."&year=".$nextyear;

$output = ' ';

/**               * Show events for this month **/               $output .= $viewEvents;

return $output; } } ?>