var $mMemcKey, $mKeys, $mParserOptions, $mParser;
var $mExtensionMessages;
var $mInitialised = false;
- var $mLang, $mLangCode;
- function initialise( &$memCached, $useDB, $expiry, $memcPrefix, $langobj, $langcode) {
+
+ function initialise( &$memCached, $useDB, $expiry, $memcPrefix) {
$fname = 'MessageCache::initialise';
wfProfileIn( $fname );
- $this->mLang = $langobj;
- $this->mLangCode = $langcode;
+
$this->mUseCache = !is_null( $memCached );
$this->mMemc = &$memCached;
$this->mDisable = !$useDB;
$this->mMemcKey = $memcPrefix.':messages';
$this->mKeys = false; # initialised on demand
$this->mInitialised = true;
- $this->mIsForContent = $forContent;
+
wfProfileIn( $fname.'-parseropt' );
$this->mParserOptions = ParserOptions::newFromUser( $u=NULL );
wfProfileOut( $fname.'-parseropt' );
wfProfileIn( $fname.'-parser' );
$this->mParser = new Parser;
wfProfileOut( $fname.'-parser' );
-
+
$this->load();
wfProfileOut( $fname );
}
wfDebug( "MessageCache::load(): loading all messages\n" );
$this->lock();
# Other threads don't need to load the messages if another thread is doing it.
- $success = $this->mMemc->set( $this->mMemcKey, "loading", MSG_LOAD_TIMEOUT );
+ $success = $this->mMemc->add( $this->mMemcKey, "loading", MSG_LOAD_TIMEOUT );
if ( $success ) {
wfProfileIn( $fname.'-load' );
$this->loadFromDB();
}
/**
- * Loads all cacheable messages from the database
+ * Loads all or main part of cacheable messages from the database
*/
function loadFromDB() {
- $fname = 'MessageCache::loadFromDB';
+ global $wgPartialMessageCache;
+ $fname = 'MessageCache::loadFromDB';
$dbr =& wfGetDB( DB_SLAVE );
+ $conditions = array( 'cur_is_redirect' => 0,
+ 'cur_namespace' => NS_MEDIAWIKI);
+ if ($wgPartialMessageCache) {
+ if (is_array($wgPartialMessageCache)) {
+ $conditions['cur_title']=$wgPartialMessageCache;
+ } else {
+ require_once("MessageCacheHints.php");
+ $conditions['cur_title']=MessageCacheHints::get();
+ }
+ }
$res = $dbr->select( 'cur',
- array( 'cur_title', 'cur_text' ),
- array( 'cur_is_redirect' => 0, 'cur_namespace' => NS_MEDIAWIKI ),
- $fname
- );
+ array( 'cur_title', 'cur_text' ), $conditions, $fname);
$this->mCache = array();
for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
* Not really needed anymore
*/
function getKeys() {
- global $wgAllMessagesEn;
+ global $wgAllMessagesEn, $wgContLang;
if ( !$this->mKeys ) {
$this->mKeys = array();
foreach ( $wgAllMessagesEn as $key => $value ) {
- array_push( $this->mKeys, $this->mLang->ucfirst( $key ) );
+ array_push( $this->mKeys, $wgContLang->ucfirst( $key ) );
}
}
return $this->mKeys;
$this->mMemc->delete( $lockKey );
}
- function get( $key, $useDB ) {
-
+ function get( $key, $useDB, $forcontent=true ) {
+ global $wgContLanguageCode;
+ if( $forcontent ) {
+ global $wgContLang;
+ $lang =& $wgContLang;
+ $langcode = $wgContLanguageCode;
+ } else {
+ global $wgLang, $wgLanguageCode;
+ $lang =& $wgLang;
+ $langcode = $wgLanguageCode;
+ }
# If uninitialised, someone is trying to call this halfway through Setup.php
- if ( !$this->mInitialised ) {
+ if( !$this->mInitialised ) {
return "<$key>";
}
$message = false;
- if ( !$this->mDisable && $useDB ) {
- $title = $this->mLang->ucfirst( $key );
-
+ if( !$this->mDisable && $useDB ) {
+ $title = $lang->ucfirst( $key );
+ if( $langcode != $wgContLanguageCode ) {
+ $title .= '/' . $langcode;
+ }
# Try the cache
- if ( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) {
+ if( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) {
$message = $this->mCache[$title];
}
+ if ( !$message && $this->mUseCache ) {
+ $message = $this->mMemc->get( $this->mMemcKey . ':' . $title );
+ if( $message ) {
+ $this->mCache[$title] = $message;
+ }
+ }
+
# If it wasn't in the cache, load each message from the DB individually
if ( !$message ) {
$dbr =& wfGetDB( DB_SLAVE );
- $result = $dbr->getArray( 'cur', array('cur_text'),
+ $result = $dbr->selectRow( 'cur', array('cur_text'),
array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ),
'MessageCache::get' );
if ( $result ) {
$message = $result->cur_text;
+ if( $this->mUseCache ) {
+ $this->mCache[$title] = $message;
+ /* individual messages may be often
+ recached until proper purge code exists
+ */
+ $this->mMemc->set( $this->mMemcKey . ':' . $title, $message, 300 );
+ }
}
}
}
# Try the extension array
- if ( !$message ) {
+ if( !$message ) {
$message = @$this->mExtensionMessages[$key];
}
# Try the array in the language object
- if ( !$message ) {
+ if( !$message ) {
wfSuppressWarnings();
- $message = $this->mLang->getMessage( $key );
+ $message = $lang->getMessage( $key );
wfRestoreWarnings();
}
# Try the English array
- if ( !$message && $this->mLangCode != 'en' ) {
+ if( !$message && $langcode != 'en' ) {
wfSuppressWarnings();
$message = Language::getMessage( $key );
wfRestoreWarnings();
}
# Final fallback
- if ( !$message ) {
+ if( !$message ) {
$message = "<$key>";
}
function transform( $message ) {
if( !$this->mDisableTransform ) {
- if ( strstr( $message, '{{' ) !== false ) {
+ if( strpos( $message, '{{' ) !== false ) {
$message = $this->mParser->transformMsg( $message, $this->mParserOptions );
}
}