From: jenkins-bot Date: Sat, 28 Sep 2019 20:02:18 +0000 (+0000) Subject: Merge "resourceloader: Simplify makeLoaderStateScript and makeLoaderSourcesScript" X-Git-Tag: 1.34.0-rc.0~56 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=e1724b7a10be582ea6d53e94fa2a6e8339d0df9f;hp=9d2d6089938254118b2e5eb16e377fda0979bb41;p=lhc%2Fweb%2Fwiklou.git Merge "resourceloader: Simplify makeLoaderStateScript and makeLoaderSourcesScript" --- diff --git a/includes/libs/StringUtils.php b/includes/libs/StringUtils.php index 19dd8fe4d3..7303d9beb7 100644 --- a/includes/libs/StringUtils.php +++ b/includes/libs/StringUtils.php @@ -316,6 +316,23 @@ class StringUtils { return $text; } + /** + * Utility function to check if the given string is a valid PCRE regex. Avoids + * manually calling suppressWarnings and restoreWarnings, and provides a + * one-line solution without the need to use @. + * + * @since 1.34 + * @param string $string The string you want to check being a valid regex + * @return bool + */ + public static function isValidPCRERegex( $string ) { + AtEase::suppressWarnings(); + // @phan-suppress-next-line PhanParamSuspiciousOrder False positive + $isValid = preg_match( $string, '' ); + AtEase::restoreWarnings(); + return $isValid !== false; + } + /** * Escape a string to make it suitable for inclusion in a preg_replace() * replacement parameter. @@ -343,21 +360,4 @@ class StringUtils { return new ArrayIterator( explode( $separator, $subject ) ); } } - - /** - * Utility function to check if the given string is a valid regex. Avoids - * manually calling suppressWarnings and restoreWarnings, and provides a - * one-line solution without the need to use @. - * - * @since 1.34 - * @param string $string The string you want to check being a valid regex - * @return bool - */ - public static function isValidRegex( $string ) { - AtEase::suppressWarnings(); - // @phan-suppress-next-line PhanParamSuspiciousOrder False positive - $isValid = preg_match( $string, '' ); - AtEase::restoreWarnings(); - return $isValid !== false; - } } diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index 37501d4f7a..237cea46c3 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -165,11 +165,11 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { /** * @param string $titleText - * @param ResourceLoaderContext|null $context (but passing null is deprecated) + * @param ResourceLoaderContext $context * @return null|string * @since 1.32 added the $context parameter */ - protected function getContent( $titleText, ResourceLoaderContext $context = null ) { + protected function getContent( $titleText, ResourceLoaderContext $context ) { $title = Title::newFromText( $titleText ); if ( !$title ) { return null; // Bad title @@ -194,20 +194,16 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { /** * @param Title $title - * @param ResourceLoaderContext|null $context (but passing null is deprecated) + * @param ResourceLoaderContext $context * @param int|null $maxRedirects Maximum number of redirects to follow. If * null, uses $wgMaxRedirects * @return Content|null * @since 1.32 added the $context and $maxRedirects parameters */ protected function getContentObj( - Title $title, ResourceLoaderContext $context = null, $maxRedirects = null + Title $title, ResourceLoaderContext $context, $maxRedirects = null ) { - if ( $context === null ) { - wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.32' ); - } - - $overrideCallback = $context ? $context->getContentOverrideCallback() : null; + $overrideCallback = $context->getContentOverrideCallback(); $content = $overrideCallback ? call_user_func( $overrideCallback, $title ) : null; if ( $content ) { if ( !$content instanceof Content ) { diff --git a/tests/phpunit/includes/libs/StringUtilsTest.php b/tests/phpunit/includes/libs/StringUtilsTest.php index 79d5788fa2..66b04adacb 100644 --- a/tests/phpunit/includes/libs/StringUtilsTest.php +++ b/tests/phpunit/includes/libs/StringUtilsTest.php @@ -130,14 +130,15 @@ class StringUtilsTest extends PHPUnit\Framework\TestCase { * @param strin $input * @param bool $expected * @dataProvider provideRegexps - * @covers StringUtils::isValidRegex + * @covers StringUtils::isValidPCRERegex */ - public function testIsValidRegex( $input, $expected ) { - $this->assertSame( $expected, StringUtils::isValidRegex( $input ) ); + public function testIsValidPCRERegex( $input, $expected ) { + $this->assertSame( $expected, StringUtils::isValidPCRERegex( $input ) ); } /** - * Data provider for testValidRegex + * Data provider for testIsValidPCRERegex + * @return array */ public static function provideRegexps() { return [