Add soft dependency on Minerva to Vector

Bug: T359607
Change-Id: If293689999a54f067792d172441c7c47d0992ed9
This commit is contained in:
Jon Robson 2024-03-19 15:28:41 -07:00 committed by Jdlrobson
parent 02d5f9970e
commit c2623ed44f
3 changed files with 36 additions and 55 deletions

View file

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

View file

@ -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.

View file

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