From 62e96a46a898700ce3064337a99422d40d539d8f Mon Sep 17 00:00:00 2001 From: Jon Robson Date: Wed, 17 Aug 2022 21:07:25 +0100 Subject: [PATCH] Register AbuseFilter menu as standard tabs Core now supports special pages registering sub menus natively in skins. The menu is rendered when the skin supports it, so at current time of writing this will only work in Vector 2022 and MinervaNeue. The existing menu that appears under the abuse filter page title is converted into the new format. For other skins no difference. Bug: T315553 Change-Id: Ief51a9c60125c11e3b735fabee2a4544b7955f64 --- includes/Special/AbuseFilterSpecialPage.php | 55 +++++++++++++++++++-- includes/Special/SpecialAbuseLog.php | 7 +++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/includes/Special/AbuseFilterSpecialPage.php b/includes/Special/AbuseFilterSpecialPage.php index ee3bb8107..6caa17ad3 100644 --- a/includes/Special/AbuseFilterSpecialPage.php +++ b/includes/Special/AbuseFilterSpecialPage.php @@ -31,11 +31,31 @@ abstract class AbuseFilterSpecialPage extends SpecialPage { } /** - * Add topbar navigation links - * - * @param string $pageType + * @inheritDoc */ - protected function addNavigationLinks( $pageType ) { + public function getShortDescription( string $path = '' ): string { + switch ( $path ) { + case 'AbuseFilter': + return $this->msg( 'abusefilter-topnav-home' )->text(); + case 'AbuseFilter/history': + return $this->msg( 'abusefilter-topnav-recentchanges' )->text(); + case 'AbuseFilter/examine': + return $this->msg( 'abusefilter-topnav-examine' )->text(); + case 'AbuseFilter/test': + return $this->msg( 'abusefilter-topnav-test' )->text(); + case 'AbuseFilter/tools': + return $this->msg( 'abusefilter-topnav-tools' )->text(); + default: + return parent::getShortDescription( $path ); + } + } + + /** + * Get topbar navigation links definitions + * + * @return array + */ + private function getNavigationLinksInternal(): array { $performer = $this->getAuthority(); $linkDefs = [ @@ -57,8 +77,33 @@ abstract class AbuseFilterSpecialPage extends SpecialPage { ]; } - $links = []; + return $linkDefs; + } + /** + * Return an array of strings representing page titles that are discoverable to end users via UI. + * + * @inheritDoc + */ + public function getAssociatedNavigationLinks(): array { + $links = $this->getNavigationLinksInternal(); + return array_map( static function ( $name ) { + return 'Special:' . $name; + }, array_values( $links ) ); + } + + /** + * Add topbar navigation links + * + * @param string $pageType + */ + protected function addNavigationLinks( $pageType ) { + // If the current skin supports sub menus nothing to do here. + if ( $this->getSkin()->supportsMenu( 'associated-pages' ) ) { + return; + } + $linkDefs = $this->getNavigationLinksInternal(); + $links = []; foreach ( $linkDefs as $name => $page ) { // Give grep a chance to find the usages: // abusefilter-topnav-home, abusefilter-topnav-recentchanges, abusefilter-topnav-test, diff --git a/includes/Special/SpecialAbuseLog.php b/includes/Special/SpecialAbuseLog.php index 85eabe159..3273ac32e 100644 --- a/includes/Special/SpecialAbuseLog.php +++ b/includes/Special/SpecialAbuseLog.php @@ -232,6 +232,13 @@ class SpecialAbuseLog extends AbuseFilterSpecialPage { } } + /** + * @inheritDoc + */ + public function getShortDescription( string $path = '' ): string { + return $this->msg( 'abusefilter-topnav-log' )->text(); + } + /** * Loads parameters from request */