MediaWiki Developer's Handbook/Add Button
From Wikibooks, the open-content textbooks collection
if( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of MediaWiki and is not a valid entry point\n" );
}
$myRedirectPng = "/extensions/myRedirectButton/myRedirect.png";
$wgHooks['EditPage::showEditForm:initial'][] = 'myRedirectButton';
$wgExtensionCredits['myRedirectButton'][]= array(
'name' => 'my Redirect Button Extension',
'version' => '1.0.0',
'author' => 'Your Name',
'url' => 'http://www.your.com/myredirectbutton/',
'description' => 'This extension is for demonstration only.');
// Add a button to the internal editor
function myRedirectButton ($editPage) {
global $wgOut, $wgScriptPath, $myRedirectPng;
// Insert javascript script that hooks up to create button.
$wgOut->addScript("<script type=\"text/javascript\">\n".
"function myAddButton(){\n".
" addButton('$myRedirectPng','Redirect','#REDIRECT [[',']]','Insert text');".
" }\n".
"addOnloadHook(myAddButton);\n".
"</script>");
return true;
}
To install
- Create a directory mediawiki/extensions/myRedirect
- Save above script as myRedirect.php
- Save the following picture to the directory as myRedirect.png.
. - Append the following line to LocalSettings.php
require_once("$IP/extensions/myRedirect/myRedirect.php");
[edit] Links
http://commons.wikimedia.org/wiki/Category:Button_link
Chapters in MediaWiki Developer's Handbook