MediaWiki Developer's Handbook/Add Button

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. Button redirect.png.
  • Append the following line to LocalSettings.php
require_once("$IP/extensions/myRedirect/myRedirect.php");

Links

http://commons.wikimedia.org/wiki/Category:Button_link

Introduction |Software Architecture |Programming Extensions |Parser Extensions |Adding new tags |Special Pages |Query Pages |HTML Form Pages |Editor Extensions |Add Button |References |Class Reference |Globals Reference |Hooks Reference |Literature

Last modified on 20 June 2012, at 21:16