* constituent messages or the resource itself is changed.
*/
class MessageBlobStore {
+ /**
+ * Get the singleton instance
+ *
+ * @since 1.24
+ * @return MessageBlobStore
+ */
+ public static function getInstance() {
+ static $instance = null;
+ if ( $instance === null ) {
+ $instance = new self;
+ }
+
+ return $instance;
+ }
+
/**
* Get the message blobs for a set of modules
*
* @param string $lang Language code
* @return array An array mapping module names to message blobs
*/
- public static function get( ResourceLoader $resourceLoader, $modules, $lang ) {
+ public function get( ResourceLoader $resourceLoader, $modules, $lang ) {
wfProfileIn( __METHOD__ );
if ( !count( $modules ) ) {
wfProfileOut( __METHOD__ );
return array();
}
// Try getting from the DB first
- $blobs = self::getFromDB( $resourceLoader, array_keys( $modules ), $lang );
+ $blobs = $this->getFromDB( $resourceLoader, array_keys( $modules ), $lang );
// Generate blobs for any missing modules and store them in the DB
$missing = array_diff( array_keys( $modules ), array_keys( $blobs ) );
foreach ( $missing as $name ) {
- $blob = self::insertMessageBlob( $name, $modules[$name], $lang );
+ $blob = $this->insertMessageBlob( $name, $modules[$name], $lang );
if ( $blob ) {
$blobs[$name] = $blob;
}
* @param string $lang Language code
* @return mixed Message blob or false if the module has no messages
*/
- public static function insertMessageBlob( $name, ResourceLoaderModule $module, $lang ) {
- $blob = self::generateMessageBlob( $module, $lang );
+ public function insertMessageBlob( $name, ResourceLoaderModule $module, $lang ) {
+ $blob = $this->generateMessageBlob( $module, $lang );
if ( !$blob ) {
return false;
* @return string Regenerated message blob, or null if there was no blob for
* the given module/language pair.
*/
- public static function updateModule( $name, ResourceLoaderModule $module, $lang ) {
+ public function updateModule( $name, ResourceLoaderModule $module, $lang ) {
$dbw = wfGetDB( DB_MASTER );
$row = $dbw->selectRow( 'msg_resource', 'mr_blob',
array( 'mr_resource' => $name, 'mr_lang' => $lang ),
// Save the old and new blobs for later
$oldBlob = $row->mr_blob;
- $newBlob = self::generateMessageBlob( $module, $lang );
+ $newBlob = $this->generateMessageBlob( $module, $lang );
try {
$newRow = array(
*
* @param string $key Message key
*/
- public static function updateMessage( $key ) {
+ public function updateMessage( $key ) {
try {
$dbw = wfGetDB( DB_MASTER );
// in one iteration.
$updates = null;
do {
- $updates = self::getUpdatesForMessage( $key, $updates );
+ $updates = $this->getUpdatesForMessage( $key, $updates );
foreach ( $updates as $k => $update ) {
// Update the row on the condition that it
}
}
- public static function clear() {
+ public function clear() {
// TODO: Give this some more thought
try {
// Not using TRUNCATE, because that needs extra permissions,
* @param array $prevUpdates Updates queue to refresh or null to build a fresh update queue
* @return array Updates queue
*/
- private static function getUpdatesForMessage( $key, $prevUpdates = null ) {
+ private function getUpdatesForMessage( $key, $prevUpdates = null ) {
$dbw = wfGetDB( DB_MASTER );
if ( is_null( $prevUpdates ) ) {
'resource' => $row->mr_resource,
'lang' => $row->mr_lang,
'timestamp' => $row->mr_timestamp,
- 'newBlob' => self::reencodeBlob( $row->mr_blob, $key, $row->mr_lang )
+ 'newBlob' => $this->reencodeBlob( $row->mr_blob, $key, $row->mr_lang )
);
}
* @param string $lang Language code
* @return string Message blob with $key replaced with its new value
*/
- private static function reencodeBlob( $blob, $key, $lang ) {
+ private function reencodeBlob( $blob, $key, $lang ) {
$decoded = FormatJson::decode( $blob, true );
$decoded[$key] = wfMessage( $key )->inLanguage( $lang )->plain();
* @throws MWException
* @return array Array mapping module names to blobs
*/
- private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {
+ private function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {
global $wgCacheEpoch;
$retval = array();
if ( $keys !== $values
|| wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch
) {
- $retval[$row->mr_resource] = self::updateModule( $row->mr_resource, $module, $lang );
+ $retval[$row->mr_resource] = $this->updateModule( $row->mr_resource, $module, $lang );
} else {
$retval[$row->mr_resource] = $row->mr_blob;
}
* @param string $lang Language code
* @return string JSON object
*/
- private static function generateMessageBlob( ResourceLoaderModule $module, $lang ) {
+ private function generateMessageBlob( ResourceLoaderModule $module, $lang ) {
$messages = array();
foreach ( $module->getMessages() as $key ) {