Sidebar: Unterschied zwischen den Versionen
Aus Gemeinwohlwiki Braunschweig
Zeile 1: | Zeile 1: | ||
− | + | $wgHooks['BaseTemplateToolbox'][] = 'modifyToolbox'; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | function modifyToolbox( BaseTemplate $baseTemplate, array &$toolbox ) { | |
− | + | ||
− | + | static $keywords = array( 'WHATLINKSHERE', 'RECENTCHANGESLINKED', 'FEEDS', 'CONTRIBUTIONS', 'LOG', 'BLOCKIP', 'EMAILUSER', 'USERRIGHTS', 'UPLOAD', 'SPECIALPAGES', 'PRINT', 'PERMALINK', 'INFO' ); | |
− | + | ||
− | + | $modifiedToolbox = array(); | |
− | + | ||
− | + | // Walk in the MediaWiki:Sidebar message, section toolbox | |
− | + | foreach ( $baseTemplate->data['sidebar']['TOOLBOX'] as $value ) { | |
− | + | $specialLink = false; | |
+ | |||
+ | // Search if the keyword exists | ||
+ | foreach ( $keywords as $key ) { | ||
+ | if ( $value['href'] == Title::newFromText($key)->fixSpecialName()->getLinkURL() ) { | ||
+ | $specialLink = true; | ||
+ | |||
+ | // This is a keyword, hence add this special link | ||
+ | if ( array_key_exists( strtolower($key), $toolbox ) ) { | ||
+ | $modifiedToolbox[strtolower($key)] = $toolbox[strtolower($key)]; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // This is a normal link | ||
+ | if ( !$specialLink ) { | ||
+ | $modifiedToolbox[] = $value; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $toolbox = $modifiedToolbox; | ||
+ | |||
+ | return true; | ||
+ | } |
Version vom 12. Januar 2021, 07:42 Uhr
$wgHooks['BaseTemplateToolbox'][] = 'modifyToolbox';
function modifyToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
static $keywords = array( 'WHATLINKSHERE', 'RECENTCHANGESLINKED', 'FEEDS', 'CONTRIBUTIONS', 'LOG', 'BLOCKIP', 'EMAILUSER', 'USERRIGHTS', 'UPLOAD', 'SPECIALPAGES', 'PRINT', 'PERMALINK', 'INFO' );
$modifiedToolbox = array();
// Walk in the MediaWiki:Sidebar message, section toolbox foreach ( $baseTemplate->data['sidebar']['TOOLBOX'] as $value ) { $specialLink = false;
// Search if the keyword exists foreach ( $keywords as $key ) { if ( $value['href'] == Title::newFromText($key)->fixSpecialName()->getLinkURL() ) { $specialLink = true;
// This is a keyword, hence add this special link if ( array_key_exists( strtolower($key), $toolbox ) ) { $modifiedToolbox[strtolower($key)] = $toolbox[strtolower($key)]; break; } } }
// This is a normal link if ( !$specialLink ) { $modifiedToolbox[] = $value; } }
$toolbox = $modifiedToolbox;
return true; }