diff --git a/README b/README index 8276b8e..514cf38 100644 --- a/README +++ b/README @@ -1,42 +1,42 @@ Admin Links extension Version 0.5 Yaron Koren This is free software licensed under the GNU General Public License. Please see https://www.gnu.org/copyleft/gpl.html for further details, including the full text and terms of the license. == Overview == Admin Links is an extension to MediaWiki that provides a special page meant to hold links that are useful to an administrator; it attempts to function as a "control panel" for the actions that a wiki administrator typically has to perform. Any user can access this page, but for administrators a new link to this page is placed within their "personal URLs" (between "Talk" and "Preferences"). Admin Links provides an API that other extensions can call in order to add their own sections and links to the page; links can be to both special pages and outside documentation URLs, among others. For more information, see the extension homepage at: https://www.mediawiki.org/wiki/Extension:Admin_Links == Requirements == -This version of the Admin Links extension requires MediaWiki 1.32 or higher. +This version of the Admin Links extension requires MediaWiki 1.35 or higher. == Installation == To install the extension, place the entire 'AdminLinks' directory within your MediaWiki 'extensions' directory, then add the following line to your LocalSettings.php file: wfLoadExtension( 'AdminLinks' ); == Contact == Comments, questions, suggestions and bug reports are welcome, and can be placed on the Talk page for the extension, or sent to Yaron at yaron57@gmail.com. diff --git a/extension.json b/extension.json index 7ea6c74..28a096e 100644 --- a/extension.json +++ b/extension.json @@ -1,44 +1,44 @@ { "name": "Admin Links", "version": "0.5", "author": [ "Yaron Koren" ], "url": "https://www.mediawiki.org/wiki/Extension:Admin_Links", "descriptionmsg": "adminlinks-desc", "license-name": "GPL-2.0-or-later", "type": "specialpage", "requires": { - "MediaWiki": ">= 1.32.0" + "MediaWiki": ">= 1.35.0" }, "GroupPermissions": { "sysop": { "adminlinks": true } }, "AvailableRights": [ "adminlinks" ], "SpecialPages": { "AdminLinks": "AdminLinks" }, "MessagesDirs": { "AdminLinks": [ "i18n" ] }, "ExtensionMessagesFiles": { "AdminLinksAlias": "AdminLinks.alias.php" }, "AutoloadClasses": { "AdminLinks": "includes/AdminLinks.php", "ALTree": "includes/ALTree.php", "ALSection": "includes/ALSection.php", "ALRow": "includes/ALRow.php", "ALItem": "includes/ALItem.php" }, "Hooks": { - "PersonalUrls": "AdminLinks::addURLToUserLinks" + "SkinTemplateNavigation::Universal": "AdminLinks::addURLToUserLinks" }, "manifest_version": 1 } diff --git a/includes/AdminLinks.php b/includes/AdminLinks.php index f59ab2e..1ec74a5 100644 --- a/includes/AdminLinks.php +++ b/includes/AdminLinks.php @@ -1,156 +1,152 @@ msg( 'adminlinks_general' )->text() ); $main_row = new ALRow( 'main' ); $main_row->addItem( ALItem::newFromSpecialPage( 'Statistics' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Version' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Specialpages' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Log' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Allmessages' ) ); $main_row->addItem( ALItem::newFromEditLink( 'Sidebar', $this->msg( 'adminlinks_editsidebar' )->text() ) ); $main_row->addItem( ALItem::newFromEditLink( 'Common.css', $this->msg( 'adminlinks_editcss' )->text() ) ); $main_row->addItem( ALItem::newFromEditLink( 'Mainpage', $this->msg( 'adminlinks_editmainpagename' )->text() ) ); $general_section->addRow( $main_row ); $tree->addSection( $general_section ); // 'users' section $users_section = new ALSection( $this->msg( 'adminlinks_users' )->text() ); $main_row = new ALRow( 'main' ); $main_row->addItem( ALItem::newFromSpecialPage( 'Listusers' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'CreateAccount' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Userrights' ) ); $users_section->addRow( $main_row ); $tree->addSection( $users_section ); // 'browsing and searching' section $browse_search_section = new ALSection( $this->msg( 'adminlinks_browsesearch' )->text() ); $main_row = new ALRow( 'main' ); $main_row->addItem( ALItem::newFromSpecialPage( 'Allpages' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Listfiles' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Search' ) ); $browse_search_section->addRow( $main_row ); $tree->addSection( $browse_search_section ); // 'importing and exporting' section $import_export_section = new ALSection( $this->msg( 'adminlinks_importexport' )->text() ); $main_row = new ALRow( 'main' ); $main_row->addItem( ALItem::newFromSpecialPage( 'Export' ) ); $main_row->addItem( ALItem::newFromSpecialPage( 'Import' ) ); $import_export_section->addRow( $main_row ); $tree->addSection( $import_export_section ); return $tree; } function execute( $query ) { $out = $this->getOutput(); $this->setHeaders(); $out->addModuleStyles( 'mediawiki.special' ); $admin_links_tree = $this->createInitialTree(); Hooks::run( 'AdminLinks', [ &$admin_links_tree ] ); $out->addHTML( $admin_links_tree->toString() ); } /** * For administrators, add a link to the special 'AdminLinks' page * among the user's "personal URLs" at the top, if they have * the 'adminlinks' permission. * - * @param array &$personal_urls - * @param Title &$title * @param SkinTemplate $skinTemplate - * - * @return bool true + * @param array &$links + * @return void This hook must not abort, it must return no value */ public static function addURLToUserLinks( - array &$personal_urls, - Title &$title, - SkinTemplate $skinTemplate - ) { + $skinTemplate, + &$links + ): void { // if user is a sysop, add link if ( $skinTemplate->getUser()->isAllowed( 'adminlinks' ) ) { $al = SpecialPage::getTitleFor( 'AdminLinks' ); $href = $al->getLocalURL(); $admin_links_vals = [ 'text' => $skinTemplate->msg( 'adminlinks' )->text(), 'href' => $href, - 'active' => ( $href == $title->getLocalURL() ) + 'active' => ( $href == $skinTemplate->getTitle()->getLocalURL() ) ]; // find the location of the 'my preferences' link, and // add the link to 'AdminLinks' right before it. // this is a "key-safe" splice - it preserves both the // keys and the values of the array, by editing them // separately and then rebuilding the array. // based on the example at http://us2.php.net/manual/en/function.array-splice.php#31234 - $tab_keys = array_keys( $personal_urls ); - $tab_values = array_values( $personal_urls ); + $tab_keys = array_keys( $links['user-menu'] ); + $tab_values = array_values( $links['user-menu'] ); $prefs_location = array_search( 'preferences', $tab_keys ); array_splice( $tab_keys, $prefs_location, 0, 'adminlinks' ); array_splice( $tab_values, $prefs_location, 0, [ $admin_links_vals ] ); - $personal_urls = []; + $links['user-menu'] = []; $tabKeysCount = count( $tab_keys ); for ( $i = 0; $i < $tabKeysCount; $i++ ) { - $personal_urls[$tab_keys[$i]] = $tab_values[$i]; + $links['user-menu'][$tab_keys[$i]] = $tab_values[$i]; } } - return true; } /** * Helper function for backward compatibility. * * @param LinkTarget|Title $title * @param string|null $msg Must be HTML escaped already * @param array $attrs * @param array $params Query parameters * @return string */ public static function makeLink( $title, $msg = null, $attrs = [], $params = [] ) { $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); if ( $msg !== null ) { $html = new HtmlArmor( $msg ); } else { // null $html = $msg; } return $linkRenderer->makeKnownLink( $title, $html, $attrs, $params ); } /** @inheritDoc */ protected function getGroupName() { return 'users'; } }