MediaWiki 開發人員手冊/新增按鈕
外觀
if( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of MediaWiki and is not a valid entry point\n" );
}
$myRedirectPng = "extensions/myRedirect/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;
}
安裝
- 建立一個目錄 mediawiki/extensions/myRedirect
- 將上面的指令碼儲存為 myRedirect.php
- 將以下圖片儲存到目錄中作為 myRedirect.png。
. - 將以下行附加到 LocalSettings.php
require_once("$IP/extensions/myRedirect/myRedirect.php");
<?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://wikibook.tw/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("<script type=\"text/javascript\">\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".
"</script>");
return true;
}
?>