From c2623ed44f2d097d331bb7230b23f6a1480bc7db Mon Sep 17 00:00:00 2001 From: Jon Robson Date: Tue, 19 Mar 2024 15:28:41 -0700 Subject: [PATCH] Add soft dependency on Minerva to Vector Bug: T359607 Change-Id: If293689999a54f067792d172441c7c47d0992ed9 --- .phan/config.php | 2 ++ README.md | 30 ++++++++++++++++ includes/Skins/FeaturesHelper.php | 59 +++---------------------------- 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index ab2ce04c6..ea27c585f 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -5,6 +5,7 @@ $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config. $cfg['directory_list'] = array_merge( $cfg['directory_list'], [ + '../../skins/Vector', '../../extensions/MobileFrontend', ] ); @@ -12,6 +13,7 @@ $cfg['directory_list'] = array_merge( $cfg['exclude_analysis_directory_list'] = array_merge( $cfg['exclude_analysis_directory_list'], [ + '../../skins/Vector', '../../extensions/MobileFrontend', ] ); diff --git a/README.md b/README.md index b8137c502..dc3fbc5e5 100644 --- a/README.md +++ b/README.md @@ -187,3 +187,33 @@ Group membership can be debugged from the console via: And since session ID is an input in calculating the group, reassignment occurs when clearing it: `mw.storage.session.remove('mwuser-sessionId')`. +#### $wgMinervaNightMode + +* Type: `array` +* Default: +```php + [ + 'base' => false, + ] +``` + +Temporary feature flag for enabling the night mode feature. + + +#### $wgMinervaNightModeOptions + +* Type: `array` +* Default: +```php + [ + "exclude" => [ + "mainpage" => false, + "querystring" => [], + "namespaces" => [], + "pagetitles" => [] + ] + ] +``` + +Allows the disabling of the night theme on certain pages. +NOTE: Vector skin must be enabled to use this functionality. diff --git a/includes/Skins/FeaturesHelper.php b/includes/Skins/FeaturesHelper.php index aafa159ae..a147097be 100644 --- a/includes/Skins/FeaturesHelper.php +++ b/includes/Skins/FeaturesHelper.php @@ -2,7 +2,6 @@ namespace MediaWiki\Minerva\Skins; -use MediaWiki\MediaWikiServices; use MediaWiki\Request\WebRequest; use MediaWiki\Title\Title; @@ -18,6 +17,7 @@ class FeaturesHelper { * 2) A query string parameter matches one of the regex patterns in $exclusions['querystring']. * OR * 3) The canonical title matches one of the titles in $options['exclude']['pagetitles'] + * For this functionality to work the Vector skin MUST be installed. * * @param array $options * @param WebRequest $request @@ -27,59 +27,8 @@ class FeaturesHelper { * @internal only for use inside tests. */ public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) { - $canonicalTitle = $title != null ? $title->getRootTitle() : null; - - $exclusions = $options[ 'exclude' ] ?? []; - - if ( $title != null && $title->isMainPage() ) { - // only one check to make - return $exclusions[ 'mainpage' ] ?? false; - } elseif ( $title != null && $canonicalTitle != null && $canonicalTitle->isSpecialPage() ) { - $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); - [ $canonicalName, $par ] = $spFactory->resolveAlias( $canonicalTitle->getDBKey() ); - if ( $canonicalName ) { - $canonicalTitle = Title::makeTitle( NS_SPECIAL, $canonicalName ); - } - } - - // - // Check the excluded page titles based on the canonical title - // - // 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 ) ) { - return true; - } - } - - // - // Check the exclusions - // If nothing matches the exclusions to determine what should happen - // - $excludeNamespaces = $exclusions[ 'namespaces' ] ?? []; - // Night Mode is disabled on certain namespaces - if ( $title != null && $title->inNamespaces( $excludeNamespaces ) ) { - return true; - } - $excludeQueryString = $exclusions[ 'querystring' ] ?? []; - - foreach ( $excludeQueryString as $param => $excludedParamPattern ) { - $paramValue = $request->getRawVal( $param ); - if ( $paramValue !== null ) { - if ( $excludedParamPattern === '*' ) { - // Backwards compatibility for the '*' wildcard. - $excludedParamPattern = '.+'; - } - return (bool)preg_match( "/$excludedParamPattern/", $paramValue ); - } - } - - return false; + return class_exists( 'MediaWiki\Skins\Vector\ConfigHelper' ) ? + \MediaWiki\Skins\Vector\ConfigHelper::shouldDisable( + $options, $request, $title ) : false; } }