mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
Correct behaviour of ConfigHelper, add tests
- Cherry-picked to be back-ported Bug: T365084 Change-Id: I220990554d0a07642dd03a0c7bd53f9bd7ff55ec
This commit is contained in:
parent
0052becb34
commit
b19fba79a9
|
@ -38,6 +38,18 @@ class ConfigHelper {
|
|||
$exclusions = $options[ 'exclude' ] ?? [];
|
||||
$inclusions = $options['include'] ?? [];
|
||||
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $title != null && $title->isMainPage() ) {
|
||||
// only one check to make
|
||||
return $exclusions[ 'mainpage' ] ?? false;
|
||||
|
@ -70,7 +82,6 @@ class ConfigHelper {
|
|||
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 ) ) {
|
||||
|
@ -87,18 +98,6 @@ class ConfigHelper {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Skins\Vector\Tests\Integration;
|
||||
|
||||
use MediaWiki\Request\FauxRequest;
|
||||
use MediaWiki\Skins\Vector\ConfigHelper;
|
||||
use RequestContext;
|
||||
use Title;
|
||||
|
@ -37,6 +38,39 @@ class ConfigHelperTest extends \MediaWikiIntegrationTestCase {
|
|||
$this->assertSame( ConfigHelper::shouldDisable( $config, $request, $title ), $disable );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::shouldDisable for the main page
|
||||
*/
|
||||
public function testShouldDisableMainPageWithQueryString() {
|
||||
$config = [
|
||||
'exclude' => [
|
||||
'mainpage' => false,
|
||||
'querystring' => [
|
||||
'diff' => '*',
|
||||
]
|
||||
],
|
||||
];
|
||||
$request = new FauxRequest( [
|
||||
'title' => 'Main_Page',
|
||||
'diff' => '1223300368',
|
||||
'oldid' => '1212457119',
|
||||
] );
|
||||
$title = Title::makeTitle( NS_MAIN, 'Main_Page' );
|
||||
|
||||
$this->assertSame( true, ConfigHelper::shouldDisable( $config, $request, $title ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::shouldDisable page title exclusion
|
||||
*/
|
||||
public function testShouldDisablePageTitlesRespectCase() {
|
||||
$config = [ 'exclude' => [ 'pagetitles' => [ 'Special:AbuseLog' ] ] ];
|
||||
$request = RequestContext::getMain()->getRequest();
|
||||
$title = Title::makeTitle( NS_MAIN, 'Special:AbuseLog' );
|
||||
|
||||
$this->assertTrue( ConfigHelper::shouldDisable( $config, $request, $title ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::shouldDisable for the main page when mainpage is not present in the config
|
||||
*/
|
||||
|
|
|
@ -283,7 +283,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
),
|
||||
Title::makeTitle( NS_SPECIAL, 'Specialpages' ),
|
||||
[ 'action' => 'history' ],
|
||||
false
|
||||
true
|
||||
],
|
||||
[
|
||||
'Max width can be disabled on talk pages',
|
||||
|
|
Loading…
Reference in a new issue