diff --git a/includes/Hooks.php b/includes/Hooks.php index 222dcdfe0..149e5e0f9 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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 ); } } diff --git a/skin.json b/skin.json index 7eb4a711d..5dd3ff1af 100644 --- a/skin.json +++ b/skin.json @@ -403,8 +403,8 @@ "exclude": { "mainpage": false, "querystring": { - "action": "history", - "diff": "*" + "action": "(history|edit)", + "diff": ".+" }, "namespaces": [ -1, diff --git a/tests/phpunit/integration/VectorHooksTest.php b/tests/phpunit/integration/VectorHooksTest.php index fc1b3a0c6..ce66d617b 100644 --- a/tests/phpunit/integration/VectorHooksTest.php +++ b/tests/phpunit/integration/VectorHooksTest.php @@ -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(