Create MediaWiki Extension

Today i am going to deliver simple tutorial on mediawiki extension.

How to create Mediawiki  Extension .

There process are divided into four files according to mediawik Rules.

Example files

Hi.php (Main file)

Hi.i18n.php (Extension loading/description file)

Hi.alias.php (Extension Title for extension file)

SpecialHi.php (Class file)

Let’s start form Hi.php file

In this file you access the all other files(Hi.i18n.php,Hi.alias.php,SpecialHi.php)

Code:-

<?php
/**
* MediaWiki Hi extension
* http://www.mediawiki.org/wiki/Extension:HelloWorld
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* This program is distributed WITHOUT ANY WARRANTY.
*/

/**
* This file loads everything needed for the Hi extension to function.
*
* @file
* @ingroup Extensions
* @author Ryan Kaldari
*/

// Alert the user that this is not a valid entry point to MediaWiki if they try to access the file directly.
// Extension credits that will show up on Special:Version

$dir=dirname(__FILE__).DIRECTORY_SEPARATOR; //get directory path
$wgAutoloadClasses[‘SpecialHi’]=$dir.’SpecialHi.php’; //get special.php file(Class file)
$wgExtensionMessagesFiles[‘Hi’] = $dir .’Hi.i18n.php’; // get loading/description  file
$wgExtensionMessagesFiles[‘HiAlias’] = $dir .’Hi.alias.php’; //get title file
$wgSpecialPages[‘Hi’]=’SpecialHi’; // get classname
$wgSpecialPageGroups[‘Hi’]=’other’; //add extension in other menu.
?>

Now for H1.alias.php

This file store the all messages.

<?php
/**
* Aliases for Special:Hi
*
* @file
* @ingroup Extensions
*/

$specialPageAliases=array();
$specialPageAliases[‘en’]=array(
‘Hi’=>array(‘Hi’),
);

Now for Hi.i18n.php file

<?php
/**
* Internationalisation for Hi extension
*
* @file
* @ingroup Extensions
*/
$messages=array();
$messages[‘en’]=array(
‘hi-desc’=>’Rockstar’,
‘hi’=>’Hi’,
‘hi-hello’=>’Hello Hitesh!’,
);

Now for SpecialHi.php file

<?php
class SpecialHi extends SpecialPage{
public function __construct(){
parent::__construct(‘Hi’);
}
public function execute($sub){
global $wgOut;
$wgOut->setPageTitle( wfMessage(‘hi’) );//(hi)get the reference from Hi.i18.php 
$wgOut->addWikiMsg(‘hi-hello’);//(hi-hello)get the reference from Hi.i18.php 
}
}
?>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s