Extension:SimpleCalendar

Introduction
This is a very simple calendar extension which renders a table of all the months in the year with each day being a wiki article (see Calendar for example). Days which have nothing in them show up as a red link, clicking on it will create a new article as usual. It installs as a parser function, so the following syntax is used:
 *  

When used like this with no parameters, a calendar of all twelve months will be rendered with each day pointing to an article using the date as its title.

Parameters
There are a number of parameters which allow calendars for different specific purposes. title: The name of the article which each day in a calendar table links to is by default the date, eg 27 Jan 2008. If you want to have different calendars for different purposes, then the title parameter will preceed the names with a separating slash character, for example, setting title to "Harry" will cause the dates to format as Harry/27 Jan 2008.

year: This changes the year of the calendar table, the default if no year is specified is the current year.

month: If a month is supplied, then only a single month will be rendered instead of a table containing all twelve months.

query: This allows extra query-string information to be appended to the links for days which don't exist. The main use for this would be to allow some preloaded content in the newly created calendar articles. See examples below - the syntax looks a little strange because it has two equals characters in it.

format: The default date format for date-articles linked to from the days in the calendar tables is, eg. 2 February 1972, but can be adjusted by supplying a PHP date format in the format parameter. See PHP-Manual/strftime for details about how to specify a date format.

Examples
Note: the examples above use the CURRENTUSER variable which is not installed by default. See Extension:Variables if you're interested in adding variables.


 *  


 *  


 *  

this example renders the May table for the current year
 *  

this example uses the new query parameter to pre-load the NewDay'' template article into newly created dates. It looks a little confusing, but what it's saying is: add "preload=template" to the link''
 *  </tt>

CSS Styles
The generated calendar table uses CSS to allow customization of the look. Here's the CSS we use which you can use and adjust: table.calendar         { margin: 0; padding: 10px; } table.calendar td      { margin: 0; padding: 2px; vertical-align: top; } table.month .heading td { padding:2px; background-color:#d4d4d4; color:#aaa; text-align:center; font-size:120%; font-weight:bold; } table.month .dow td    { color:#aaa; text-align:center; font-size:110%; } table.month td.today   { background-color:#ddd; } table.month td { border: none; margin: 0; padding: 1pt 1.5pt; font-weight: bold; font-size: 8pt; text-align: right; background-color: #eee; } .day-active { color:#0000cc } .day-empty { color:#cc0000 }
 * 1) bodyContent table.month a { background:none; padding:0 }

Installation
Save the following code as a file in your extensions directory and include it from your LocalSettings.php file as usual. You might want to check OrganicDesign:Extension:SimpleCalendar.php to see if a later version is available. <?php $wgExtensionFunctions[]       = 'wfSetupSimpleCalendar'; $wgHooks['LanguageGetMagic'][] = 'wfCalendarLanguageGetMagic'; function wfCalendarLanguageGetMagic(&$magicWords,$langCode = 0) { $magicWords['calendar'] = array(0,'calendar'); return true; }

function wfSetupSimpleCalendar { global $wgParser; $wgParser->setFunctionHook('calendar','wfRenderCalendar'); return true; }

function wfRenderCalendar(&$parser) { $argv = array; foreach (func_get_args as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]]=$match[2]; }       if (isset($argv['format'])) $f = $argv['format']; else $f = '%e %B %Y'; if (isset($argv['title'])) $p = $argv['title'].'/'; else $p = ''; if (isset($argv['query'])) $q = $argv['query'].'&action=edit'; else $q = 'action=edit'; if (isset($argv['year']))  $y = $argv['year']; else $y = date('Y'); if (isset($argv['month'])) { $m = $argv['month']; return wfRenderMonth(strftime('%m',strtotime("$y-$m-01")),$y,$p,$q,$f); } else $m = 1; $table = "{| class=\"calendar\"\n"; for ($rows = 3; $rows--; $table .= "|-\n") for ($cols = 0; $cols < 4; $cols++) $table .= '|'.wfRenderMonth($m++,$y,$p,$q,$f)."\n"; return "$table\n|}\n"; }
 * 1) Renders a table of all the individual month tables

function wfRenderMonth($m,$y,$prefix = ,$query = ,$format = '%e %B %Y') { $thisDay  = date('d'); $thisMonth = date('n'); $thisYear = date('Y'); if (!$d = date('w',$ts = mktime(0,0,0,$m,1,$y))) $d = 7; $month = strftime('%B',$ts); $table = "\n{| class=\"month\"\n|- class=\"heading\"\n|colspan=\"7\"|$month\n|- class=\"dow\"\n"; $table .= "|M||T||W||T||F||S||S\n"; if ($d > 1) $table .= "|-".str_repeat("\n| \n",$d-1); for ($i = $day = $d; $day < 32; $i++) { $day = $i - $d + 1; if ($day < 29 or checkdate($m,$day,$y)) { if ($i%7 == 1) $table .= "\n|-\n"; $t = ($day == $thisDay and $m == $thisMonth and $y == $thisYear) ? ' class="today"' : ''; $ttext = $prefix.strftime($format,mktime(0,0,0,$m,$day,$y)); $title = Title::newFromText($ttext); $class = $title->exists ? 'day-active' : 'day-empty'; $url = $title->getFullURL($title->exists ? '' : $query); $table .= "|$t|[$url <span class='$class'>$day ]\n"; }               }        return "$table\n|}"; } ?>
 * 1) Return a calendar table of the passed month and year

Version 1.2 (2007-05-03)

 * Added format parameter.

Version 1.1 (2007-05-02)

 * Changed to named parameters and added the query parameter. The style of the day-links are now handled by two new CSS classes, day-active and day-empty.