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
This commit is contained in:
Umherirrender 2023-12-04 21:42:13 +01:00
parent 372cd72d13
commit b67f2800d3

View file

@ -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' );
}
}
}