Last modified on 16 August 2010, at 21:24

MediaWiki Developer's Handbook/Special Pages

This will show you how to create a special page.

MySpecialPage.phpEdit

<?php
 
if (!defined("MEDIAWIKI")) {
 die("not a valid entry point!");
}
 
$wgExtensionCredits['specialpage'][] = array (
 'name' => 'My Special Page!',
 'author' => 'Me',
 'url' => 'http://en.wikibooks.org/',
 'description' => 'A cool special page',
 'version' => '1.2.3',
);
 
$wgAutoloadClasses['MySpecialPage'] = $dir . "MySpecialPage_body.php";
$wgSpecialPages['MySpecialPage'] = 'MySpecialPage.php';

This file registers the special page.

MySpecialPage_body.phpEdit

<?php
 
class MySpecialPage extends SpecialPage {
 function __construct() {
  parent::__construct();
 }
 
 function execute($par) {
  global $wgOut;
  mt_srand(time());
  $d = str(mt_rand(1, 10));
  $output = "Hello! Your lucky number is '''$d'''!";
  $wgOut->addWikiText($output);
 }
}

This is the special page itself. It should say something like Hello! "Your lucky number is 3"!