mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-23 13:56:51 +00:00
Add soft dependency on Minerva to Vector
Bug: T359607 Change-Id: If293689999a54f067792d172441c7c47d0992ed9
This commit is contained in:
parent
02d5f9970e
commit
c2623ed44f
|
@ -5,6 +5,7 @@ $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.
|
||||||
$cfg['directory_list'] = array_merge(
|
$cfg['directory_list'] = array_merge(
|
||||||
$cfg['directory_list'],
|
$cfg['directory_list'],
|
||||||
[
|
[
|
||||||
|
'../../skins/Vector',
|
||||||
'../../extensions/MobileFrontend',
|
'../../extensions/MobileFrontend',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -12,6 +13,7 @@ $cfg['directory_list'] = array_merge(
|
||||||
$cfg['exclude_analysis_directory_list'] = array_merge(
|
$cfg['exclude_analysis_directory_list'] = array_merge(
|
||||||
$cfg['exclude_analysis_directory_list'],
|
$cfg['exclude_analysis_directory_list'],
|
||||||
[
|
[
|
||||||
|
'../../skins/Vector',
|
||||||
'../../extensions/MobileFrontend',
|
'../../extensions/MobileFrontend',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
30
README.md
30
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
|
And since session ID is an input in calculating the group, reassignment occurs
|
||||||
when clearing it: `mw.storage.session.remove('mwuser-sessionId')`.
|
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.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace MediaWiki\Minerva\Skins;
|
namespace MediaWiki\Minerva\Skins;
|
||||||
|
|
||||||
use MediaWiki\MediaWikiServices;
|
|
||||||
use MediaWiki\Request\WebRequest;
|
use MediaWiki\Request\WebRequest;
|
||||||
use MediaWiki\Title\Title;
|
use MediaWiki\Title\Title;
|
||||||
|
|
||||||
|
@ -18,6 +17,7 @@ class FeaturesHelper {
|
||||||
* 2) A query string parameter matches one of the regex patterns in $exclusions['querystring'].
|
* 2) A query string parameter matches one of the regex patterns in $exclusions['querystring'].
|
||||||
* OR
|
* OR
|
||||||
* 3) The canonical title matches one of the titles in $options['exclude']['pagetitles']
|
* 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 array $options
|
||||||
* @param WebRequest $request
|
* @param WebRequest $request
|
||||||
|
@ -27,59 +27,8 @@ class FeaturesHelper {
|
||||||
* @internal only for use inside tests.
|
* @internal only for use inside tests.
|
||||||
*/
|
*/
|
||||||
public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) {
|
public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) {
|
||||||
$canonicalTitle = $title != null ? $title->getRootTitle() : null;
|
return class_exists( 'MediaWiki\Skins\Vector\ConfigHelper' ) ?
|
||||||
|
\MediaWiki\Skins\Vector\ConfigHelper::shouldDisable(
|
||||||
$exclusions = $options[ 'exclude' ] ?? [];
|
$options, $request, $title ) : false;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue