The test for OutputPage::makeResourceLoaderLink was triggering database
queries through MessageBlobStore even though it doesn't use any
messages.
In
bb03d1a8e08 I had made MessageBlobStore a singleton instead of static
functions, however there's no need for it to be one since the class is
stateless. Callers can just create a new MessageBlobStore instance and
call functions upon it. Using getInstance() is now deprecated.
ResourceLoader now has a setMessageBlobStore setter to allow overriding
which MessageBlobStore instance will be used. OutputPageTest uses this
to set a NullMessageBlobStore, which makes no database queries.
Change-Id: Ica7436fb6f1ea59bd445b02527829ab0742c0842
* Get the singleton instance
*
* @since 1.24
+ * @deprecated since 1.25
* @return MessageBlobStore
*/
public static function getInstance() {
- static $instance = null;
- if ( $instance === null ) {
- $instance = new self;
- }
-
- return $instance;
+ wfDeprecated( __METHOD__, '1.25' );
+ return new self;
}
/**
# HACK: If using a null (i.e. disabled) storage backend, we
# can't write to the MessageBlobStore either
if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
- MessageBlobStore::getInstance()->clear();
+ $blobStore = new MessageBlobStore();
+ $blobStore->clear();
}
}
// Update the message in the message blob store
global $wgContLang;
- MessageBlobStore::getInstance()->updateMessage( $wgContLang->lcfirst( $msg ) );
+ $blobStore = new MessageBlobStore();
+ $blobStore->updateMessage( $wgContLang->lcfirst( $msg ) );
Hooks::run( 'MessageCacheReplace', array( $title, $text ) );
if ( $wgLocalisationCacheConf['manualRecache'] ) {
$this->rebuildLocalisationCache();
}
- MessageBlobStore::getInstance()->clear();
+ $blobStore = new MessageBlobStore();
+ $blobStore->clear();
$this->output( "done.\n" );
}
*/
protected $errors = array();
+ /**
+ * @var MessageBlobStore
+ */
+ protected $blobStore;
+
/**
* Load information stored in the database about modules.
*
$this->registerTestModules();
}
+ $this->setMessageBlobStore( new MessageBlobStore() );
}
/**
return $this->config;
}
+ /**
+ * @param MessageBlobStore $blobStore
+ * @since 1.25
+ */
+ public function setMessageBlobStore( MessageBlobStore $blobStore ) {
+ $this->blobStore = $blobStore;
+ }
+
/**
* Register a module with the ResourceLoader system.
*
// Pre-fetch blobs
if ( $context->shouldIncludeMessages() ) {
try {
- $blobs = MessageBlobStore::getInstance()->get( $this, $modules, $context->getLanguage() );
+ $blobs = $this->blobStore->get( $this, $modules, $context->getLanguage() );
} catch ( Exception $e ) {
MWExceptionHandler::logException( $e );
wfDebugLog(
$ctx->setLanguage( 'en' );
$out = new OutputPage( $ctx );
$rl = $out->getResourceLoader();
+ $rl->setMessageBlobStore( new NullMessageBlobStore() );
$rl->register( array(
'test.foo' => new ResourceLoaderTestModule( array(
'script' => 'mw.test.foo( { a: true } );',
$this->assertEquals( $expectedHtml, $actualHtml );
}
}
+
+/**
+ * MessageBlobStore that doesn't do anything
+ */
+class NullMessageBlobStore extends MessageBlobStore {
+ public function get ( ResourceLoader $resourceLoader, $modules, $lang ) {
+ return array();
+ }
+
+ public function insertMessageBlob ( $name, ResourceLoaderModule $module, $lang ) {
+ return false;
+ }
+
+ public function updateModule ( $name, ResourceLoaderModule $module, $lang ) {
+ return;
+ }
+
+ public function updateMessage ( $key ) {
+ }
+ public function clear() {
+ }
+}
+