Fix Issue with localization of special page titles in exclusion logic

The fixSpecialName function does the opposite of what we want - it takes
a special page and converts it to the local name using getLocalNameFor
Instead of doing that map canonicalTitle to a Title created using the canonical
name.

This requires less computation than localizing every title in the pagetitles array.

Bug: T359958
Change-Id: Ied3ed927202dd9356ebeb7e404230f571a1d910d
This commit is contained in:
Jon Robson 2024-03-12 15:19:58 -07:00 committed by Moh'd Khier Abualruz
parent 6d50ae266b
commit 06463592b4

View file

@ -2,6 +2,7 @@
namespace MediaWiki\Minerva\Skins;
use MediaWiki\MediaWikiServices;
use MediaWiki\Request\WebRequest;
use MediaWiki\Title\Title;
@ -34,7 +35,11 @@ class FeaturesHelper {
// only one check to make
return $exclusions[ 'mainpage' ] ?? false;
} elseif ( $title != null && $canonicalTitle != null && $canonicalTitle->isSpecialPage() ) {
$canonicalTitle->fixSpecialName();
$spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
[ $canonicalName, $par ] = $spFactory->resolveAlias( $canonicalTitle->getDBKey() );
if ( $canonicalName ) {
$canonicalTitle = Title::makeTitle( NS_SPECIAL, $canonicalName );
}
}
//
@ -43,6 +48,9 @@ class FeaturesHelper {
// Now we have the canonical title and the exclusions link we look for any matches.
$pageTitles = $exclusions[ 'pagetitles' ] ?? [];
foreach ( $pageTitles as $titleText ) {
// use strtolower to make sure the config passed for special pages
// is case insensitive, so it does not generate a wrong special page title
$titleText = $canonicalTitle->isSpecialPage() ? strtolower( $titleText ) : $titleText;
$excludedTitle = Title::newFromText( $titleText );
if ( $canonicalTitle != null && $canonicalTitle->equals( $excludedTitle ) ) {