Merge "Exclude from max-width via query string patterns"

This commit is contained in:
jenkins-bot 2022-06-01 16:15:01 +00:00 committed by Gerrit Code Review
commit f94c86c3e0
3 changed files with 40 additions and 12 deletions

View File

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

View File

@ -403,8 +403,8 @@
"exclude": {
"mainpage": false,
"querystring": {
"action": "history",
"diff": "*"
"action": "(history|edit)",
"diff": ".+"
},
"namespaces": [
-1,

View File

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