From b67f2800d378129748b134a22039d23931d264a8 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Mon, 4 Dec 2023 21:42:13 +0100 Subject: [PATCH] Swap conditions in onSpecialPageBeforeExecute Avoid use of the context when not needed as this is also called for special page transclusion, avoid initialize of the skin in that newly created context. Change-Id: I56573491262a194f44bccb7fd6170eb7bf21c6ed --- includes/Hooks.php | 54 ++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index e8c7ebfba..5e10eb1d1 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -141,35 +141,33 @@ class Hooks implements */ public function onSpecialPageBeforeExecute( $special, $subpage ) { $name = $special->getName(); - $out = $special->getOutput(); - $skin = $out->getSkin(); + if ( !in_array( $name, [ 'Recentchanges', 'Userlogin', 'CreateAccount' ] ) ) { + return; + } + $skin = $special->getSkin(); + if ( !$skin instanceof SkinMinerva ) { + return; + } $request = $special->getRequest(); - - if ( $skin instanceof SkinMinerva ) { - switch ( $name ) { - case 'Recentchanges': - $isEnhancedDefaultForUser = MediaWikiServices::getInstance() - ->getUserOptionsLookup() - ->getBoolOption( $special->getUser(), 'usenewrc' ); - $enhanced = $request->getBool( 'enhanced', $isEnhancedDefaultForUser ); - if ( $enhanced ) { - $out->addHTML( Html::warningBox( - $special->msg( 'skin-minerva-recentchanges-warning-enhanced-not-supported' )->parse() - ) ); - } - break; - case 'Userlogin': - case 'CreateAccount': - // Add default warning message to Special:UserLogin and Special:UserCreate - // if no warning message set. - if ( - !$request->getVal( 'warning' ) && - !$special->getUser()->isRegistered() && - !$request->wasPosted() - ) { - $request->setVal( 'warning', 'mobile-frontend-generic-login-new' ); - } - break; + if ( $name === 'Recentchanges' ) { + $isEnhancedDefaultForUser = MediaWikiServices::getInstance() + ->getUserOptionsLookup() + ->getBoolOption( $special->getUser(), 'usenewrc' ); + $enhanced = $request->getBool( 'enhanced', $isEnhancedDefaultForUser ); + if ( $enhanced ) { + $special->getOutput()->addHTML( Html::warningBox( + $special->msg( 'skin-minerva-recentchanges-warning-enhanced-not-supported' )->parse() + ) ); + } + } else { + // Add default warning message to Special:UserLogin and Special:UserCreate + // if no warning message set. + if ( + !$request->getVal( 'warning' ) && + !$special->getUser()->isRegistered() && + !$request->wasPosted() + ) { + $request->setVal( 'warning', 'mobile-frontend-generic-login-new' ); } } }