Merge "JavaScriptMinifier: Fix bad state after '{}' in property value"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 11 Aug 2018 15:40:43 +0000 (15:40 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 11 Aug 2018 15:40:43 +0000 (15:40 +0000)
17 files changed:
autoload.php
includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/media/SVGMetadataExtractor.php
includes/parser/CoreParserFunctions.php
includes/parser/LinkHolderArray.php
includes/parser/Parser.php
includes/parser/ParserFactory.php [new file with mode: 0644]
maintenance/parse.php
tests/phpunit/data/media/comma_separated_viewbox.svg [new file with mode: 0644]
tests/phpunit/includes/MediaWikiVersionFetcherTest.php
tests/phpunit/includes/MessageTest.php
tests/phpunit/includes/auth/AuthManagerTest.php
tests/phpunit/includes/media/SVGMetadataExtractorTest.php
tests/phpunit/includes/parser/ParserFactoryTest.php [new file with mode: 0644]
tests/phpunit/includes/parser/TagHooksTest.php
tests/phpunit/includes/preferences/DefaultPreferencesFactoryTest.php

index e02a743..feddcdd 100644 (file)
@@ -1078,6 +1078,7 @@ $wgAutoloadLocalClasses = [
        'Parser' => __DIR__ . '/includes/parser/Parser.php',
        'ParserCache' => __DIR__ . '/includes/parser/ParserCache.php',
        'ParserDiffTest' => __DIR__ . '/includes/parser/ParserDiffTest.php',
+       'ParserFactory' => __DIR__ . '/includes/parser/ParserFactory.php',
        'ParserOptions' => __DIR__ . '/includes/parser/ParserOptions.php',
        'ParserOutput' => __DIR__ . '/includes/parser/ParserOutput.php',
        'ParsoidVirtualRESTService' => __DIR__ . '/includes/libs/virtualrest/ParsoidVirtualRESTService.php',
index 080a7f9..79e55f8 100644 (file)
@@ -39,6 +39,7 @@ use MimeAnalyzer;
 use ObjectCache;
 use Parser;
 use ParserCache;
+use ParserFactory;
 use PasswordFactory;
 use ProxyLookup;
 use SearchEngine;
@@ -682,6 +683,14 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'ParserCache' );
        }
 
+       /**
+        * @since 1.32
+        * @return ParserFactory
+        */
+       public function getParserFactory() {
+               return $this->getService( 'ParserFactory' );
+       }
+
        /**
         * @since 1.32
         * @return PasswordFactory
index 08f7d66..e5ebe2d 100644 (file)
@@ -56,7 +56,6 @@ use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\RevisionStoreFactory;
 use MediaWiki\Storage\SqlBlobStore;
-use Wikimedia\ObjectFactory;
 
 return [
        'ActorMigration' => function ( MediaWikiServices $services ) : ActorMigration {
@@ -367,9 +366,7 @@ return [
        },
 
        'Parser' => function ( MediaWikiServices $services ) : Parser {
-               $conf = $services->getMainConfig()->get( 'ParserConf' );
-               return ObjectFactory::constructClassInstance( $conf['class'],
-                       [ $conf, $services->getMagicWordFactory() ] );
+               return $services->getParserFactory()->create();
        },
 
        'ParserCache' => function ( MediaWikiServices $services ) : ParserCache {
@@ -383,6 +380,15 @@ return [
                );
        },
 
+       'ParserFactory' => function ( MediaWikiServices $services ) : ParserFactory {
+               return new ParserFactory(
+                       $services->getMainConfig()->get( 'ParserConf' ),
+                       $services->getMagicWordFactory(),
+                       $services->getContentLanguage(),
+                       wfUrlProtocols()
+               );
+       },
+
        'PasswordFactory' => function ( MediaWikiServices $services ) : PasswordFactory {
                $config = $services->getMainConfig();
                return new PasswordFactory(
index ee467b0..e52bf0b 100644 (file)
@@ -325,7 +325,7 @@ class SVGReader {
 
                if ( $this->reader->getAttribute( 'viewBox' ) ) {
                        // min-x min-y width height
-                       $viewBox = preg_split( '/\s+/', trim( $this->reader->getAttribute( 'viewBox' ) ) );
+                       $viewBox = preg_split( '/\s*[\s,]\s*/', trim( $this->reader->getAttribute( 'viewBox' ) ) );
                        if ( count( $viewBox ) == 4 ) {
                                $viewWidth = $this->scaleSVGUnit( $viewBox[2] );
                                $viewHeight = $this->scaleSVGUnit( $viewBox[3] );
index 3c47de3..ae7ca6d 100644 (file)
@@ -135,14 +135,13 @@ class CoreParserFunctions {
        }
 
        public static function ns( $parser, $part1 = '' ) {
-               global $wgContLang;
                if ( intval( $part1 ) || $part1 == "0" ) {
                        $index = intval( $part1 );
                } else {
-                       $index = $wgContLang->getNsIndex( str_replace( ' ', '_', $part1 ) );
+                       $index = $parser->getContentLanguage()->getNsIndex( str_replace( ' ', '_', $part1 ) );
                }
                if ( $index !== false ) {
-                       return $wgContLang->getFormattedNsText( $index );
+                       return $parser->getContentLanguage()->getFormattedNsText( $index );
                } else {
                        return [ 'found' => false ];
                }
@@ -197,13 +196,11 @@ class CoreParserFunctions {
        }
 
        public static function lcfirst( $parser, $s = '' ) {
-               global $wgContLang;
-               return $wgContLang->lcfirst( $s );
+               return $parser->getContentLanguage()->lcfirst( $s );
        }
 
        public static function ucfirst( $parser, $s = '' ) {
-               global $wgContLang;
-               return $wgContLang->ucfirst( $s );
+               return $parser->getContentLanguage()->ucfirst( $s );
        }
 
        /**
@@ -212,8 +209,7 @@ class CoreParserFunctions {
         * @return string
         */
        public static function lc( $parser, $s = '' ) {
-               global $wgContLang;
-               return $parser->markerSkipCallback( $s, [ $wgContLang, 'lc' ] );
+               return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'lc' ] );
        }
 
        /**
@@ -222,8 +218,7 @@ class CoreParserFunctions {
         * @return string
         */
        public static function uc( $parser, $s = '' ) {
-               global $wgContLang;
-               return $parser->markerSkipCallback( $s, [ $wgContLang, 'uc' ] );
+               return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'uc' ] );
        }
 
        public static function localurl( $parser, $s = '', $arg = null ) {
@@ -742,7 +737,6 @@ class CoreParserFunctions {
         * @return string
         */
        public static function pagesincategory( $parser, $name = '', $arg1 = null, $arg2 = null ) {
-               global $wgContLang;
                static $magicWords = null;
                if ( is_null( $magicWords ) ) {
                        $magicWords = $parser->getMagicWordFactory()->newArray( [
@@ -772,7 +766,7 @@ class CoreParserFunctions {
                if ( !$title ) { # invalid title
                        return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
                }
-               $wgContLang->findVariantLink( $name, $title, true );
+               $parser->getContentLanguage()->findVariantLink( $name, $title, true );
 
                // Normalize name for cache
                $name = $title->getDBkey();
index 66fd723..f4856be 100644 (file)
@@ -282,8 +282,6 @@ class LinkHolderArray {
                        return;
                }
 
-               global $wgContLang;
-
                $colours = [];
                $linkCache = MediaWikiServices::getInstance()->getLinkCache();
                $output = $this->parent->getOutput();
@@ -364,7 +362,7 @@ class LinkHolderArray {
                }
 
                # Do a second query for different language variants of links and categories
-               if ( $wgContLang->hasVariants() ) {
+               if ( $this->parent->getContentLanguage()->hasVariants() ) {
                        $this->doVariants( $colours );
                }
 
@@ -452,7 +450,6 @@ class LinkHolderArray {
         * @param array &$colours
         */
        protected function doVariants( &$colours ) {
-               global $wgContLang;
                $linkBatch = new LinkBatch();
                $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
                $output = $this->parent->getOutput();
@@ -480,7 +477,8 @@ class LinkHolderArray {
                }
 
                // Now do the conversion and explode string to text of titles
-               $titlesAllVariants = $wgContLang->autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
+               $titlesAllVariants = $this->parent->getContentLanguage()->
+                       autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
                $allVariantsName = array_keys( $titlesAllVariants );
                foreach ( $titlesAllVariants as &$titlesVariant ) {
                        $titlesVariant = explode( "\0", $titlesVariant );
@@ -521,7 +519,7 @@ class LinkHolderArray {
                foreach ( $output->getCategoryLinks() as $category ) {
                        $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category );
                        $linkBatch->addObj( $categoryTitle );
-                       $variants = $wgContLang->autoConvertToAllVariants( $category );
+                       $variants = $this->parent->getContentLanguage()->autoConvertToAllVariants( $category );
                        foreach ( $variants as $variant ) {
                                if ( $variant !== $category ) {
                                        $variantTitle = Title::makeTitleSafe( NS_CATEGORY, $variant );
index 4073864..7599a1f 100644 (file)
@@ -263,13 +263,25 @@ class Parser {
        /** @var MagicWordFactory */
        private $magicWordFactory;
 
+       /** @var Language */
+       private $contLang;
+
+       /** @var ParserFactory */
+       private $factory;
+
        /**
-        * @param array $conf
+        * @param array $conf See $wgParserConf documentation
         * @param MagicWordFactory|null $magicWordFactory
+        * @param Language|null $contLang Content language
+        * @param ParserFactory|null $factory
+        * @param string|null $urlProtocols As returned from wfUrlProtocols()
         */
-       public function __construct( $conf = [], MagicWordFactory $magicWordFactory = null ) {
+       public function __construct(
+               array $conf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null,
+               ParserFactory $factory = null, $urlProtocols = null
+       ) {
                $this->mConf = $conf;
-               $this->mUrlProtocols = wfUrlProtocols();
+               $this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols();
                $this->mExtLinkBracketedRegex = '/\[(((?i)' . $this->mUrlProtocols . ')' .
                        self::EXT_LINK_ADDR .
                        self::EXT_LINK_URL_CLASS . '*)\p{Zs}*([^\]\\x00-\\x08\\x0a-\\x1F\\x{FFFD}]*?)\]/Su';
@@ -289,10 +301,12 @@ class Parser {
                }
                wfDebug( __CLASS__ . ": using preprocessor: {$this->mPreprocessorClass}\n" );
 
-               $this->magicWordFactory = $magicWordFactory;
-               if ( !$magicWordFactory ) {
-                       $this->magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
-               }
+               $this->magicWordFactory = $magicWordFactory ??
+                       MediaWikiServices::getInstance()->getMagicWordFactory();
+
+               $this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
+
+               $this->factory = $factory ?? MediaWikiServices::getInstance()->getParserFactory();
        }
 
        /**
@@ -972,7 +986,7 @@ class Parser {
         * @return Language
         */
        public function getContentLanguage() {
-               return $this->magicWordFactory->getContentLanguage();
+               return $this->contLang;
        }
 
        /**
@@ -2154,7 +2168,7 @@ class Parser {
                if ( $useLinkPrefixExtension ) {
                        # Match the end of a line for a word that's not followed by whitespace,
                        # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
-                       $charset = $this->getContentLanguage()->linkPrefixCharset();
+                       $charset = $this->contLang->linkPrefixCharset();
                        $e2 = "/^((?>.*[^$charset]|))(.+)$/sDu";
                }
 
@@ -2710,11 +2724,10 @@ class Parser {
                                break;
                        case 'namespace':
                                $value = str_replace( '_', ' ',
-                                       $this->getContentLanguage()->getNsText( $this->mTitle->getNamespace() ) );
+                                       $this->contLang->getNsText( $this->mTitle->getNamespace() ) );
                                break;
                        case 'namespacee':
-                               $value = wfUrlencode( $this->getContentLanguage()->
-                                       getNsText( $this->mTitle->getNamespace() ) );
+                               $value = wfUrlencode( $this->contLang->getNsText( $this->mTitle->getNamespace() ) );
                                break;
                        case 'namespacenumber':
                                $value = $this->mTitle->getNamespace();
@@ -2863,7 +2876,7 @@ class Parser {
                if ( !$this->getRevisionObject() ) {
                        # Get the timezone-adjusted timestamp $mtts seconds in the future
                        $resThen = substr(
-                               $this->getContentLanguage()->userAdjust( wfTimestamp( TS_MW, time() + $mtts ), '' ),
+                               $this->contLang->userAdjust( wfTimestamp( TS_MW, time() + $mtts ), '' ),
                                $start,
                                $len
                        );
@@ -3415,7 +3428,7 @@ class Parser {
                        $function = $this->mFunctionSynonyms[1][$function];
                } else {
                        # Case insensitive functions
-                       $function = $this->getContentLanguage()->lc( $function );
+                       $function = $this->contLang->lc( $function );
                        if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
                                $function = $this->mFunctionSynonyms[0][$function];
                        } else {
@@ -4519,14 +4532,14 @@ class Parser {
         */
        private function pstPass2( $text, $user ) {
                # Note: This is the timestamp saved as hardcoded wikitext to the database, we use
-               # $this->getContentLanguage() here in order to give everyone the same signature and use the
-               # default one rather than the one selected in each user's preferences.  (see also T14815)
+               # $this->contLang here in order to give everyone the same signature and use the default one
+               # rather than the one selected in each user's preferences.  (see also T14815)
                $ts = $this->mOptions->getTimestamp();
                $timestamp = MWTimestamp::getLocalInstance( $ts );
                $ts = $timestamp->format( 'YmdHis' );
                $tzMsg = $timestamp->getTimezoneMessage()->inContentLanguage()->text();
 
-               $d = $this->getContentLanguage()->timeanddate( $ts, false, false ) . " ($tzMsg)";
+               $d = $this->contLang->timeanddate( $ts, false, false ) . " ($tzMsg)";
 
                # Variable replacement
                # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
@@ -4892,7 +4905,7 @@ class Parser {
                foreach ( $synonyms as $syn ) {
                        # Case
                        if ( !$sensitive ) {
-                               $syn = $this->getContentLanguage()->lc( $syn );
+                               $syn = $this->contLang->lc( $syn );
                        }
                        # Add leading hash
                        if ( !( $flags & self::SFH_NO_HASH ) ) {
@@ -5736,7 +5749,7 @@ class Parser {
                        # Since this value will be saved into the parser cache, served
                        # to other users, and potentially even used inside links and such,
                        # it needs to be consistent for all visitors.
-                       $this->mRevisionTimestamp = $this->getContentLanguage()->userAdjust( $timestamp, '' );
+                       $this->mRevisionTimestamp = $this->contLang->userAdjust( $timestamp, '' );
 
                }
                return $this->mRevisionTimestamp;
@@ -6192,9 +6205,8 @@ class Parser {
         * @return Parser A parser object that is not parsing anything
         */
        public function getFreshParser() {
-               global $wgParserConf;
                if ( $this->mInParse ) {
-                       return new $wgParserConf['class']( $wgParserConf );
+                       return $this->factory->create();
                } else {
                        return $this;
                }
diff --git a/includes/parser/ParserFactory.php b/includes/parser/ParserFactory.php
new file mode 100644 (file)
index 0000000..646f855
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Parser
+ */
+
+/**
+ * @since 1.32
+ */
+class ParserFactory {
+       /** @var array */
+       private $conf;
+
+       /** @var MagicWordFactory */
+       private $magicWordFactory;
+
+       /** @var Language */
+       private $contLang;
+
+       /** @var string */
+       private $urlProtocols;
+
+       /**
+        * @param array $conf See $wgParserConf documentation
+        * @param MagicWordFactory $magicWordFactory
+        * @param Language $contLang Content language
+        * @param string $urlProtocols As returned from wfUrlProtocols()
+        * @since 1.32
+        */
+       public function __construct(
+               array $conf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols
+       ) {
+               $this->conf = $conf;
+               $this->magicWordFactory = $magicWordFactory;
+               $this->contLang = $contLang;
+               $this->urlProtocols = $urlProtocols;
+       }
+
+       /**
+        * @return Parser
+        * @since 1.32
+        */
+       public function create() : Parser {
+               return new Parser( $this->conf, $this->magicWordFactory, $this->contLang, $this,
+                       $this->urlProtocols );
+       }
+}
index cf2fe54..d9a247c 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Parse some wikitext.
  *
@@ -103,9 +106,7 @@ class CLIParser extends Maintenance {
        }
 
        protected function initParser() {
-               global $wgParserConf;
-               $parserClass = $wgParserConf['class'];
-               $this->parser = new $parserClass();
+               $this->parser = MediaWikiServices::getInstance()->getParserFactory()->create();
        }
 
        /**
diff --git a/tests/phpunit/data/media/comma_separated_viewbox.svg b/tests/phpunit/data/media/comma_separated_viewbox.svg
new file mode 100644 (file)
index 0000000..9e7329d
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="100%" width="100%" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox=" 0, 0 ,349.46883 , 405.12272 ">
+</svg>
index 87a7dff..cb234b2 100644 (file)
  *
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  */
-class MediaWikiVersionFetcherTest extends PHPUnit\Framework\TestCase {
+class MediaWikiVersionFetcherTest extends MediaWikiTestCase {
 
        use MediaWikiCoversValidator;
 
        public function testReturnsResult() {
+               global $wgVersion;
                $versionFetcher = new MediaWikiVersionFetcher();
-               $this->assertInternalType( 'string', $versionFetcher->fetchVersion() );
+               $this->assertSame( $wgVersion, $versionFetcher->fetchVersion() );
        }
 
 }
index 3e3d04a..d75c0e5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-use Wikimedia\ObjectFactory;
+use MediaWiki\MediaWikiServices;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -401,14 +401,12 @@ class MessageTest extends MediaWikiLangTestCase {
        }
 
        public function testRawHtmlInMsg() {
-               global $wgParserConf;
                $this->setMwGlobals( 'wgRawHtml', true );
                // We have to reset the core hook registration.
                // to register the html hook
                MessageCache::destroyInstance();
                $this->setMwGlobals( 'wgParser',
-                       ObjectFactory::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
-               );
+                       MediaWikiServices::getInstance()->getParserFactory()->create() );
 
                $msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
                $txt = '<span class="error">&lt;html&gt; tags cannot be' .
index 7170e55..0c5d026 100644 (file)
@@ -38,7 +38,6 @@ class AuthManagerTest extends \MediaWikiTestCase {
                parent::setUp();
 
                $this->setMwGlobals( [ 'wgAuth' => null ] );
-               $this->stashMwGlobals( [ 'wgHooks' ] );
        }
 
        /**
@@ -48,11 +47,10 @@ class AuthManagerTest extends \MediaWikiTestCase {
         * @return object $mock->expects( $expect )->method( ... ).
         */
        protected function hook( $hook, $expect ) {
-               global $wgHooks;
                $mock = $this->getMockBuilder( __CLASS__ )
                        ->setMethods( [ "on$hook" ] )
                        ->getMock();
-               $wgHooks[$hook] = [ $mock ];
+               $this->setTemporaryHook( $hook, $mock );
                return $mock->expects( $expect )->method( "on$hook" );
        }
 
@@ -613,42 +611,35 @@ class AuthManagerTest extends \MediaWikiTestCase {
                );
        }
 
-       public function testSetDefaultUserOptions() {
+       /**
+        * @dataProvider provideSetDefaultUserOptions
+        */
+       public function testSetDefaultUserOptions(
+               $contLang, $useContextLang, $expectedLang, $expectedVariant
+       ) {
                $this->initializeManager();
 
+               $this->setContentLang( $contLang );
                $context = \RequestContext::getMain();
                $reset = new ScopedCallback( [ $context, 'setLanguage' ], [ $context->getLanguage() ] );
                $context->setLanguage( 'de' );
-               $this->setContentLang( 'zh' );
-
-               $user = \User::newFromName( self::usernameForCreation() );
-               $user->addToDatabase();
-               $oldToken = $user->getToken();
-               $this->managerPriv->setDefaultUserOptions( $user, false );
-               $user->saveSettings();
-               $this->assertNotEquals( $oldToken, $user->getToken() );
-               $this->assertSame( 'zh', $user->getOption( 'language' ) );
-               $this->assertSame( 'zh', $user->getOption( 'variant' ) );
 
                $user = \User::newFromName( self::usernameForCreation() );
                $user->addToDatabase();
                $oldToken = $user->getToken();
-               $this->managerPriv->setDefaultUserOptions( $user, true );
+               $this->managerPriv->setDefaultUserOptions( $user, $useContextLang );
                $user->saveSettings();
                $this->assertNotEquals( $oldToken, $user->getToken() );
-               $this->assertSame( 'de', $user->getOption( 'language' ) );
-               $this->assertSame( 'zh', $user->getOption( 'variant' ) );
-
-               $this->setContentLang( 'fr' );
+               $this->assertSame( $expectedLang, $user->getOption( 'language' ) );
+               $this->assertSame( $expectedVariant, $user->getOption( 'variant' ) );
+       }
 
-               $user = \User::newFromName( self::usernameForCreation() );
-               $user->addToDatabase();
-               $oldToken = $user->getToken();
-               $this->managerPriv->setDefaultUserOptions( $user, true );
-               $user->saveSettings();
-               $this->assertNotEquals( $oldToken, $user->getToken() );
-               $this->assertSame( 'de', $user->getOption( 'language' ) );
-               $this->assertSame( null, $user->getOption( 'variant' ) );
+       public function provideSetDefaultUserOptions() {
+               return [
+                       [ 'zh', false, 'zh', 'zh' ],
+                       [ 'zh', true, 'de', 'zh' ],
+                       [ 'fr', true, 'de', null ],
+               ];
        }
 
        public function testForcePrimaryAuthenticationProviders() {
@@ -2380,7 +2371,8 @@ class AuthManagerTest extends \MediaWikiTestCase {
                $wgGroupPermissions['*']['createaccount'] = true;
                $wgGroupPermissions['*']['autocreateaccount'] = false;
 
-               \ObjectCache::$instances[__METHOD__] = new \HashBagOStuff();
+               $this->mergeMwGlobalArrayValue( 'wgObjectCaches',
+                       [ __METHOD__ => [ 'class' => 'HashBagOStuff' ] ] );
                $this->setMwGlobals( [ 'wgMainCacheType' => __METHOD__ ] );
 
                // Set up lots of mocks...
index c258b6a..7aef246 100644 (file)
@@ -134,6 +134,16 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                        'translations' => []
                                ],
                        ],
+                       [
+                               "$base/comma_separated_viewbox.svg",
+                               [
+                                       'width' => 512,
+                                       'height' => 594,
+                                       'originalWidth' => '100%',
+                                       'originalHeight' => '100%',
+                                       'translations' => []
+                               ],
+                       ],
                ];
        }
 
diff --git a/tests/phpunit/includes/parser/ParserFactoryTest.php b/tests/phpunit/includes/parser/ParserFactoryTest.php
new file mode 100644 (file)
index 0000000..f37bdfc
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * @covers ParserFactory
+ */
+class ParserFactoryTest extends MediaWikiTestCase {
+       /**
+        * For backwards compatibility, all parameters to the parser constructor are optional and
+        * default to the appropriate global service, so it's easy to forget to update ParserFactory to
+        * actually pass the parameters it's supposed to.
+        */
+       public function testConstructorArgNum() {
+               $factoryConstructor = new ReflectionMethod( 'ParserFactory', '__construct' );
+               $instanceConstructor = new ReflectionMethod( 'Parser', '__construct' );
+               // Subtract one for the ParserFactory itself
+               $this->assertSame( $instanceConstructor->getNumberOfParameters() - 1,
+                       $factoryConstructor->getNumberOfParameters(),
+                       'Parser and ParserFactory constructors have an inconsistent number of parameters. ' .
+                       'Did you add a parameter to one and not the other?' );
+       }
+
+       public function testAllArgumentsWerePassed() {
+               $factoryConstructor = new ReflectionMethod( 'ParserFactory', '__construct' );
+               $mocks = [];
+               foreach ( $factoryConstructor->getParameters() as $param ) {
+                       $type = (string)$param->getType();
+                       if ( $type === 'array' ) {
+                               $val = [ 'porcupines will tell me your secrets' . count( $mocks ) ];
+                       } elseif ( class_exists( $type ) || interface_exists( $type ) ) {
+                               $val = $this->createMock( $type );
+                       } elseif ( $type === '' ) {
+                               // Optimistically assume a string is okay
+                               $val = 'I will de-quill them first' . count( $mocks );
+                       } else {
+                               $this->fail( "Unrecognized parameter type $type in ParserFactory constructor" );
+                       }
+                       $mocks[] = $val;
+               }
+
+               $factory = new ParserFactory( ...$mocks );
+               $parser = $factory->create();
+
+               foreach ( ( new ReflectionObject( $parser ) )->getProperties() as $prop ) {
+                       $prop->setAccessible( true );
+                       foreach ( $mocks as $idx => $mock ) {
+                               if ( $prop->getValue( $parser ) === $mock ) {
+                                       unset( $mocks[$idx] );
+                               }
+                       }
+               }
+
+               $this->assertCount( 0, $mocks, 'Not all arguments to the ParserFactory constructor were ' .
+                       'found in Parser member variables' );
+       }
+}
index bc09adc..48312d9 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @group Database
  * @group Parser
@@ -54,8 +56,7 @@ class TagHooksTest extends MediaWikiTestCase {
         * @dataProvider provideValidNames
         */
        public function testTagHooks( $tag ) {
-               global $wgParserConf;
-               $parser = new Parser( $wgParserConf );
+               $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
 
                $parser->setHook( $tag, [ $this, 'tagCallback' ] );
                $parserOutput = $parser->parse(
@@ -73,8 +74,7 @@ class TagHooksTest extends MediaWikiTestCase {
         * @expectedException MWException
         */
        public function testBadTagHooks( $tag ) {
-               global $wgParserConf;
-               $parser = new Parser( $wgParserConf );
+               $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
 
                $parser->setHook( $tag, [ $this, 'tagCallback' ] );
                $parser->parse(
@@ -89,8 +89,7 @@ class TagHooksTest extends MediaWikiTestCase {
         * @dataProvider provideValidNames
         */
        public function testFunctionTagHooks( $tag ) {
-               global $wgParserConf;
-               $parser = new Parser( $wgParserConf );
+               $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
 
                $parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
                $parserOutput = $parser->parse(
@@ -108,8 +107,7 @@ class TagHooksTest extends MediaWikiTestCase {
         * @expectedException MWException
         */
        public function testBadFunctionTagHooks( $tag ) {
-               global $wgParserConf;
-               $parser = new Parser( $wgParserConf );
+               $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
 
                $parser->setFunctionTagHook(
                        $tag,
index 296691d..43c678e 100644 (file)
@@ -3,7 +3,6 @@
 use MediaWiki\Auth\AuthManager;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Preferences\DefaultPreferencesFactory;
-use Wikimedia\ObjectFactory;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -38,13 +37,13 @@ class DefaultPreferencesFactoryTest extends MediaWikiTestCase {
 
        public function setUp() {
                parent::setUp();
-               global $wgParserConf;
                $this->context = new RequestContext();
                $this->context->setTitle( Title::newFromText( self::class ) );
-               $this->setMwGlobals( 'wgParser',
-                       ObjectFactory::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
-               );
-               $this->config = MediaWikiServices::getInstance()->getMainConfig();
+
+               $services = MediaWikiServices::getInstance();
+
+               $this->setMwGlobals( 'wgParser', $services->getParserFactory()->create() );
+               $this->config = $services->getMainConfig();
        }
 
        /**