Extension:Wikical.pl

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Wikical.pl

Release status: beta

Description Perl script written to generate a MediaWiki-format table showing a calendar month, with links for each day to a subpage from the displayed page.
License No license specified
Download Script

Check usage (experimental)

Wikical.pl is a Perl script written to generate a MediaWiki-format table showing a calendar month, with links for each day to a subpage from the displayed page.

It was written specifically to make up for the lack of PhpWiki's CalendarPlugin. The format of the links matches that of CalendarPlugin, allowing for minimal migration issues.

To use: Run this script (with optional -m and -y options to provide month and year, respectively) and capture or select the output, then paste the output into the target MediaWiki page. Alternately, use this wikical CGI wrapper to generate wikical code via the web.

[edit] Script

#!perl
 
use Getopt::Std;
 
getopt('my');
@nowdate=localtime(time());
 
$month=$opt_m?$opt_m:$nowdate[4]+1;
$year=$opt_y?$opt_y:$nowdate[5]+1900;
 
open CAL, "cal $month $year|";
 
print "{| border cellspacing=0 cellpadding=2\n";
 
while (<CAL>) {
  if (/^\s+[A-Z]/) {  # month and year
    print "|+$_";
    next;
  }
 
  if (/^Su/) {  # days of week
    @dow=split;
    print "|-\n|".join("||",@dow)."\n";
    next;
  }
 
  print "|-\n";
 
  @days=split;
  if ($days[0]==1) {
    $paddays=7-scalar(@days);
    while ($paddays--) { print "| |"; }
  }
 
  foreach $day (@days) {
    printf ("|'''[[{{PAGENAME}}/%4d-%02d-%02d|$day]]'''\n",$year,$month,$day);
  }
 
}  #end while
 
print "|}\n";


[edit] Example of output

March 2006
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox