From: Timo Tijhof Date: Sat, 16 Feb 2019 23:46:30 +0000 (+0000) Subject: resourceloader: Make $rl parameter mandatory for MessageBlobStore X-Git-Tag: 1.34.0-rc.0~2785^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=3edaa0b37c1e268473999b7775d8b5ff49fad79c;p=lhc%2Fweb%2Fwiklou.git resourceloader: Make $rl parameter mandatory for MessageBlobStore Change-Id: I851b2417b7e495a1d0c7ee1aa8be2b2e970840bb --- diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index 52807586d1..957384b395 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -255,6 +255,7 @@ because of Phabricator reports. parameter. * The ChangeList::insertArticleLink() method, that was deprecated in 1.27, has been removed. +* MessageBlobStore::__construct() now requires its $rl parameter. === Deprecations in 1.33 === * The configuration option $wgUseESI has been deprecated, and is expected diff --git a/includes/cache/MessageBlobStore.php b/includes/cache/MessageBlobStore.php index 19c49972f7..ceb51f2d3f 100644 --- a/includes/cache/MessageBlobStore.php +++ b/includes/cache/MessageBlobStore.php @@ -37,7 +37,7 @@ use Wikimedia\Rdbms\Database; */ class MessageBlobStore implements LoggerAwareInterface { - /* @var ResourceLoader|null */ + /* @var ResourceLoader */ private $resourceloader; /** @@ -51,13 +51,13 @@ class MessageBlobStore implements LoggerAwareInterface { protected $wanCache; /** - * @param ResourceLoader|null $rl + * @param ResourceLoader $rl * @param LoggerInterface|null $logger */ - public function __construct( ResourceLoader $rl = null, LoggerInterface $logger = null ) { + public function __construct( ResourceLoader $rl, LoggerInterface $logger = null ) { $this->resourceloader = $rl; $this->logger = $logger ?: new NullLogger(); - $this->wanCache = ObjectCache::getMainWANInstance(); + $this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); } /** @@ -191,12 +191,6 @@ class MessageBlobStore implements LoggerAwareInterface { * @return ResourceLoader */ protected function getResourceLoader() { - // Back-compat: This class supports instantiation without a ResourceLoader object. - // Lazy-initialise this property because most callers don't need it. - if ( $this->resourceloader === null ) { - $this->logger->warning( __CLASS__ . ' created without a ResourceLoader instance' ); - $this->resourceloader = MediaWikiServices::getInstance()->getResourceLoader(); - } return $this->resourceloader; } diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index 21b262a6dd..1d00d19a51 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -1034,7 +1034,9 @@ class LocalisationCache { # HACK: If using a null (i.e. disabled) storage backend, we # can't write to the MessageBlobStore either if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) { - $blobStore = new MessageBlobStore(); + $blobStore = new MessageBlobStore( + MediaWikiServices::getInstance()->getResourceLoader() + ); $blobStore->clear(); } } diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index d64e2d7b69..7a92807e0c 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -1074,7 +1074,9 @@ abstract class DatabaseUpdater { } // ResourceLoader: Message cache - $blobStore = new MessageBlobStore(); + $blobStore = new MessageBlobStore( + MediaWikiServices::getInstance()->getResourceLoader() + ); $blobStore->clear(); // ResourceLoader: File-dependency cache diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 7d40d8c873..7bb5c38fa9 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -2531,7 +2531,7 @@ class OutputPageTest extends MediaWikiTestCase { $nonce->setAccessible( true ); $nonce->setValue( $out, 'secret' ); $rl = $out->getResourceLoader(); - $rl->setMessageBlobStore( new NullMessageBlobStore() ); + $rl->setMessageBlobStore( $this->createMock( MessageBlobStore::class ) ); $rl->register( [ 'test.foo' => new ResourceLoaderTestModule( [ 'script' => 'mw.test.foo( { a: true } );', @@ -2647,7 +2647,7 @@ class OutputPageTest extends MediaWikiTestCase { ->method( 'buildCssLinksArray' ) ->willReturn( [] ); $rl = $op->getResourceLoader(); - $rl->setMessageBlobStore( new NullMessageBlobStore() ); + $rl->setMessageBlobStore( $this->createMock( MessageBlobStore::class ) ); // Register custom modules $rl->register( [ @@ -3051,21 +3051,3 @@ class OutputPageTest extends MediaWikiTestCase { return new OutputPage( $context ); } } - -/** - * MessageBlobStore that doesn't do anything - */ -class NullMessageBlobStore extends MessageBlobStore { - public function get( ResourceLoader $resourceLoader, $modules, $lang ) { - return []; - } - - public function updateModule( $name, ResourceLoaderModule $module, $lang ) { - } - - public function updateMessage( $key ) { - } - - public function clear() { - } -} diff --git a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php index 58e6d7d345..70bf39f75d 100644 --- a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php +++ b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php @@ -9,6 +9,7 @@ use Wikimedia\TestingAccessWrapper; class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { use MediaWikiCoversValidator; + use PHPUnit4And6Compat; protected function setUp() { parent::setUp(); @@ -37,7 +38,7 @@ class MessageBlobStoreTest extends PHPUnit\Framework\TestCase { protected function makeBlobStore( $methods = null, $rl = null ) { $blobStore = $this->getMockBuilder( MessageBlobStore::class ) - ->setConstructorArgs( [ $rl ] ) + ->setConstructorArgs( [ $rl ?? $this->createMock( ResourceLoader::class ) ] ) ->setMethods( $methods ) ->getMock();