Thread:Project:Support desk/Passing Javascript variables to a custom MediaWiki 1.16 Extension

<?php

// to install, upload this file as /extensions/myEditbarButton/myEditbarButton.php // then, copy this button image as /extensions/myEditbarButton/myButtonCard.png // // then add the following line to end of LocalSettings.php // //      require_once("$IP/extensions/myEditbarButton/myEditbarButton.php"); // // This is a modification of // https://en.wikibooks.org/wiki/MediaWiki_Developer%27s_Handbook/Add_Button // // Sorry that extension can only add a new button before the other buttons // of the edit bar, instead of after them. I am also not sure if this will work // on other installations of mediawiki ( mine is MediaWiki: 1.16.5, PHP: 5.2.17 // MySQL: 5.1.69 )

if( !defined( 'MEDIAWIKI' ) ) { die( "This file is part of MediaWiki and is not a valid entry point\n" ); } $myButtonPng = "extensions/myEditbarButton/myButtonCard.png";

$wgHooks['EditPage::showEditForm:initial'][] = 'myEditbarButton';

// for $wgExtensionsCredits[$type][] //      $type must be api, media, parserhook, skin //                    specialpage, variable, other

$wgExtensionCredits['other'][] = array(	'name'        => 'my Editbar Button', 	'version'      => '1.0.0', 	'author'       => 'Your Name', 	'url'          => 'http://www.your.com/myredirectbutton/', 	'description'  => 'Adds a new button to the old edit bar that calls a custom javascript function.'	);

// Add a button to the internal editor function myEditbarButton ($editPage) { global $wgOut, $wgScriptPath, $myButtonPng; // Insert javascript script that hooks up to create button. $wgOut->addScript("\n".		"function myAddButton{ \n".			"var toolbar = document.getElementById( 'toolbar' ); \n".			"var image = document.createElement( 'img' ); \n".			"image.className = 'mw-toolbar-editbutton'; \n".			"image.src = '$myButtonPng'; \n".			"image.border = 0; \n".			"image.alt = 'speedTip'; \n".			"image.title = 'speedTip'; \n".			"image.style.cursor = 'pointer'; \n".			"image.onclick = function { \n".				"window.alert('HelloWorld'); \n".			"} \n".			"toolbar.appendChild( image ); \n".		"} \n".

"addOnloadHook(myAddButton); \n". " ");	return true; }

?>