Jump to: navigation, search


Mediawiki Special Page Tutorial

If you want to add more advanced features to Bootstrapskin you will need to either create an extension or a Special Page. Examples of what a Special Page can be used for are adding forms, multi-functional image galleries and embedding a community forum, the list is endless, but suffice to say that "anything" you want to include in your wiki can be included through a special page.

Use a special page for a feature that you only intend to use once, if you want to reuse a feature, such as a gallery that displays different pictures on different pages, you should create an extension. (see here for a turorial on creating extensions)

The following is a short guide on how to add advanced features to your wiki using a Special:Page. This is a fully working script that can be used straight away with minimal modification.

IMPORTANT: If you intend to add a feature such as a form, take care to test for security issues with a relevant penetration test! Ask at the forums if you need help.

Special Folders and Files

You can skip the tutorial and view the demo and download the files at the bottom of the page.

Create the following folders and files in the Mediawiki extensions folder as below;

  • extensions
    • BootStrapSkinCustomExtension
      • BootStrapSkinCustomExtension.alias.php
      • BootStrapSkinCustomExtension.i18n.php
      • BootStrapSkinCustomExtension.php
      • SpecialCustom.php
      • modules
        • ext.yourjavascript.js
        • ext.yourstylesheet.css
SpecialCustom.php
<?php

class SpecialCustom extends SpecialPage {
	function __construct() {
		parent::__construct( 'SpecialCustom' );
	}
 
		function execute( $par ) {
		$request = $this->getRequest();
		$output = $this->getOutput();
		$this->setHeaders();
		$output->setPageTitle("Hello World Title");

		$param = $request->getText( 'param' );
		
		$output = $this->getOutput();
        $output->addModuleScripts( 'ext.BootStrapSkinCustomExtension' );
		$output->addModuleStyles( 'ext.BootStrapSkinCustomExtension' ); 
 
		$wikitext = '';
		$output->addWikiText( $wikitext );
		$output->addHTML('		
            
			<div class="col-md-12"> //Take great care to retain everything before this line
			<p>Hello World</p> //This section is where you include your html/php/Javascript
			</div>//Take great care to retain everything after this line
			
			');
	}
};
BootStrapSkinCustomExtension.php
<?php
if ( !defined( 'MEDIAWIKI' ) ) die();

$wgExtensionCredits['other'][] = array(
	'path' => __FILE__,
	'name' => 'BootStrapSkinCustomExtension',
	'author' => array(
		'[http://url.com Your Name]',
	),
	'descriptionmsg' => 'custom-desc',
	'url' => 'http://url.com',
);

$wgExtensionMessagesFiles['BootStrapSkinCustomExtension'] = __DIR__ . '/BootStrapSkinCustomExtension.i18n.php';

$wgResourceModules['ext.BootStrapSkinCustomExtension'] = array(
	'scripts' => array('modules/ext.yourjavascript.js'),
	'styles' => array('modules/ext.yourstylesheet.css'),
 
	'localBasePath' => __DIR__,
	'remoteExtPath' => 'BootStrapSKinCustomExtension',
	
);

$wgAutoloadClasses[ 'SpecialCustom' ] = __DIR__ . '/SpecialCustom.php';
$wgSpecialPages[ 'SpecialCustom' ] = 'SpecialCustom';
$wgExtensionMessagesFiles[ 'SpecialCustom' ] = __DIR__ . '/BootStrapSkinCustomExtension.alias.php';

BootStrapSkinCustomExtension.i18n.php
<?php
/**
 *
 *
 * @file
 * @ingroup Extensions
 */

$messages = array();

$messages['en'] = array(
        'custom'   => 'Custom',
	    'custom-desc'           => 'a phrase about your extension',
);
LocalSettings.php
require_once "$IP/extensions/BootStrapSkinCustomExtension/BootStrapSkinCustomExtension.php";

And finally the url to reach your new special page is;

/index.php?title=Special:SpecialCustom