* @package MediaWiki
*/
+require_once( 'Revision.php' );
+
/**
*
*/
var $mMemcKey, $mKeys, $mParserOptions, $mParser;
var $mExtensionMessages;
var $mInitialised = false;
+ var $mDeferred = true;
function initialise( &$memCached, $useDB, $expiry, $memcPrefix) {
$fname = 'MessageCache::initialise';
$this->mParser = new Parser;
wfProfileOut( $fname.'-parser' );
- $this->load();
+ # When we first get asked for a message,
+ # then we'll fill up the cache. If we
+ # can return a cache hit, this saves
+ # some extra milliseconds
+ $this->mDeferred = true;
+
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();
}
if ( !is_array( $this->mCache ) ) {
- wfMsg( "MessageCache::load(): individual message mode\n" );
+ wfDebug( "MessageCache::load(): individual message mode\n" );
# If it is 'loading' or 'error', switch to individual message mode, otherwise disable
# Causing too much DB load, disabling -- TS
$this->mDisable = true;
}
}
wfProfileOut( $fname );
+ $this->mDeferred = false;
return $success;
}
/**
- * 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 );
- $res = $dbr->select( 'cur',
- array( 'cur_title', 'cur_text' ),
- array( 'cur_is_redirect' => 0, 'cur_namespace' => NS_MEDIAWIKI ),
+ $conditions = array( 'page_is_redirect' => 0,
+ 'page_namespace' => NS_MEDIAWIKI);
+ if ($wgPartialMessageCache) {
+ wfDebugDieBacktrace( "Confused about how this works." );
+ if (is_array($wgPartialMessageCache)) {
+ $conditions['page_title']=$wgPartialMessageCache;
+ } else {
+ require_once("MessageCacheHints.php");
+ $conditions['page_title']=MessageCacheHints::get();
+ }
+ }
+ $res = $dbr->select( array( 'page', 'text' ),
+ array( 'page_title', 'old_text', 'old_flags' ),
+ 'page_is_redirect=0 AND page_namespace = '.NS_MEDIAWIKI.' AND page_latest = old_id',
$fname
);
$this->mCache = array();
for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
- $this->mCache[$row->cur_title] = $row->cur_text;
+ $this->mCache[$row->page_title] = Revision::getRevisionText( $row );
}
$dbr->freeResult( $res );
if ( !$this->mKeys ) {
$this->mKeys = array();
foreach ( $wgAllMessagesEn as $key => $value ) {
- array_push( $this->mKeys, $wgContLang->ucfirst( $key ) );
+ $title = $wgContLang->ucfirst( $key );
+ array_push( $this->mKeys, $title );
}
}
return $this->mKeys;
*/
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 ) {
$this->mMemc->delete( $lockKey );
}
- function get( $key, $useDB ) {
- global $wgContLang, $wgContLanguageCode;
+ function get( $key, $useDB, $forcontent=true, $isfullkey = false ) {
+ 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>";
}
+ # If cache initialization was deferred, start it now.
+ if( $this->mDeferred ) {
+ $this->load();
+ }
$message = false;
- if ( !$this->mDisable && $useDB ) {
- $title = $wgContLang->ucfirst( $key );
-
+ if( !$this->mDisable && $useDB ) {
+ $title = $lang->ucfirst( $key );
+ if(!$isfullkey && ($langcode != $wgContLanguageCode) ) {
+ $title .= '/' . $langcode;
+ }
# Try the cache
- if ( $this->mUseCache && $this->mCache && array_key_exists( $title, $this->mCache ) ) {
+ if( $this->mUseCache && is_array( $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'),
- array( 'cur_namespace' => NS_MEDIAWIKI, 'cur_title' => $title ),
+ $result = $dbr->selectRow( array( 'page', 'text' ),
+ array( 'old_flags', 'old_text' ),
+ 'page_namespace=' . NS_MEDIAWIKI .
+ ' AND page_title=' . $dbr->addQuotes( $title ) .
+ ' AND page_latest=old_id',
'MessageCache::get' );
if ( $result ) {
- $message = $result->cur_text;
+ $message = Revision::getRevisionText( $result );
+ 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 = $wgContLang->getMessage( $key );
+ $message = $lang->getMessage( $key );
wfRestoreWarnings();
}
# Try the English array
- if ( !$message && $wgContLanguageCode != '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 );
}
}