mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
Merge "Exclude from max-width via query string patterns"
This commit is contained in:
commit
f94c86c3e0
|
@ -651,9 +651,7 @@ class Hooks implements
|
|||
* Max width is disabled if:
|
||||
* 1) The current namespace is listed in array $options['exclude']['namespaces']
|
||||
* OR
|
||||
* 2) The query string matches one of the name and value pairs $exclusions['querystring'].
|
||||
* Note the wildcard "*" for a value, will match all query string values for the given
|
||||
* query string parameter.
|
||||
* 2) A query string parameter matches one of the regex patterns in $exclusions['querystring'].
|
||||
*
|
||||
* @internal only for use inside tests.
|
||||
* @param array $options
|
||||
|
@ -698,16 +696,14 @@ class Hooks implements
|
|||
}
|
||||
$excludeQueryString = $exclusions['querystring'] ?? [];
|
||||
|
||||
foreach ( $excludeQueryString as $param => $excludedParamValue ) {
|
||||
foreach ( $excludeQueryString as $param => $excludedParamPattern ) {
|
||||
$paramValue = $requestValues[$param] ?? false;
|
||||
if ( $paramValue ) {
|
||||
if ( $excludedParamValue === '*' ) {
|
||||
// check wildcard
|
||||
return true;
|
||||
} elseif ( $paramValue === $excludedParamValue ) {
|
||||
// Check if the excluded param value matches
|
||||
return true;
|
||||
if ( $excludedParamPattern === '*' ) {
|
||||
// Backwards compatibility for the '*' wildcard.
|
||||
$excludedParamPattern = '.+';
|
||||
}
|
||||
return (bool)preg_match( "/$excludedParamPattern/", $paramValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -403,8 +403,8 @@
|
|||
"exclude": {
|
||||
"mainpage": false,
|
||||
"querystring": {
|
||||
"action": "history",
|
||||
"diff": "*"
|
||||
"action": "(history|edit)",
|
||||
"diff": ".+"
|
||||
},
|
||||
"namespaces": [
|
||||
-1,
|
||||
|
|
|
@ -231,6 +231,38 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
[ 'action' => 'history' ],
|
||||
true
|
||||
],
|
||||
[
|
||||
'Can be disabled with a regex match.',
|
||||
self::makeMaxWidthConfig(
|
||||
false,
|
||||
[
|
||||
/* no namespaces excluded */
|
||||
],
|
||||
[
|
||||
/* no includes */
|
||||
],
|
||||
[ 'foo' => '[0-9]+' ]
|
||||
),
|
||||
Title::makeTitle( NS_MAIN, 'Test' ),
|
||||
[ 'foo' => '1234' ],
|
||||
true
|
||||
],
|
||||
[
|
||||
'Can be disabled with a non-regex wildcard (for backwards compatibility).',
|
||||
self::makeMaxWidthConfig(
|
||||
false,
|
||||
[
|
||||
/* no namespaces excluded */
|
||||
],
|
||||
[
|
||||
/* no includes */
|
||||
],
|
||||
[ 'foo' => '*' ]
|
||||
),
|
||||
Title::makeTitle( NS_MAIN, 'Test' ),
|
||||
[ 'foo' => 'bar' ],
|
||||
true
|
||||
],
|
||||
[
|
||||
'Include can override exclusions',
|
||||
self::makeMaxWidthConfig(
|
||||
|
|
Loading…
Reference in a new issue