-<?
+<?php
# Message cache
# Performs various useful MediaWiki namespace-related functions
class MessageCache
{
var $mCache, $mUseCache, $mDisable, $mExpiry;
- var $mMemcKey, $mKeys;
+ var $mMemcKey, $mKeys, $mParserOptions, $mParser;
var $mInitialised = false;
$this->mMemcKey = "$memcPrefix:messages";
$this->mKeys = false; # initialised on demand
$this->mInitialised = true;
-
+ $this->mParserOptions = ParserOptions::newFromUser( $u=NULL );
+ $this->mParser = new Parser;
+
$this->load();
}
{
$fname = "MessageCache::loadFromDB";
$sql = "SELECT cur_title,cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI;
- $sql .= " AND cur_title IN ('";
- $sql .= implode( "','", $this->getKeys() ) . "')";
- wfDebug( "$sql\n" );
-
$res = wfQuery( $sql, DB_READ, $fname );
$this->mCache = array();
$this->mCache[$row->cur_title] = $row->cur_text;
}
- wfDebug( var_export( $this->mCache, true ) );
-
wfFreeResult( $res );
}
+ # Not really needed anymore
function getKeys() {
global $wgAllMessagesEn, $wgLang;
if ( !$this->mKeys ) {
return $this->mKeys;
}
+ # Obsolete
function isCacheable( $key ) {
+ return true;
+ /*
global $wgAllMessagesEn, $wgLang;
return array_key_exists( $wgLang->lcfirst( $key ), $wgAllMessagesEn ) ||
array_key_exists( $key, $wgAllMessagesEn );
+ */
}
function replace( $title, $text ) {
global $wgMemc;
- if ( $this->isCacheable( $title ) ) {
- $this->lock();
- $this->load();
- if ( is_array( $this->mCache ) ) {
- $this->mCache[$title] = $text;
- $wgMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
- }
- $this->unlock();
+ $this->lock();
+ $this->load();
+ if ( is_array( $this->mCache ) ) {
+ $this->mCache[$title] = $text;
+ $wgMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
}
+ $this->unlock();
}
# Returns success
}
if ( $this->mDisable ) {
- return $wgLang->getMessage( $key );
+ return $this->transform( $wgLang->getMessage( $key ) );
}
$title = $wgLang->ucfirst( $key );
$message = false;
# Try the cache
- if ( $this->mUseCache && $this->mCache ) {
+ if ( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) {
$message = $this->mCache[$title];
}
# If it wasn't in the cache, load each message from the DB individually
if ( !$message && $useDB) {
- $sql = "SELECT cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI .
- " AND cur_title='$title'";
- $res = wfQuery( $sql, DB_READ, $fname );
-
- if ( wfNumRows( $res ) ) {
- $obj = wfFetchObject( $res );
- $message = $obj->cur_text;
- wfFreeResult( $res );
+ $result = wfGetArray( "cur", array("cur_text"),
+ array( "cur_namespace" => NS_MEDIAWIKI, "cur_title" => $title ),
+ "MessageCache::get" );
+ if ( $result ) {
+ $message = $result->cur_text;
}
}
if ( !$message ) {
$message = "<$key>";
}
+
+ # Replace brace tags
+ $message = $this->transform( $message );
+
+ return $message;
+ }
+
+ function transform( $message ) {
+ if ( strstr( $message, "{{" ) !== false ) {
+ $message = $this->mParser->transformMsg( $message, $this->mParserOptions );
+ }
return $message;
}
+
+ function disable() { $this->mDisable = true; }
+ function enable() { $this->mDisable = false; }
+
}
?>