/**
*
* @package MediaWiki
+ * @subpackage Cache
*/
+/** */
require_once( 'Revision.php' );
/**
}
wfProfileOut( $fname.'-save' );
if ( $i == 20 ) {
- $this->mMemc->set( $this->mMemcKey, 'error', 86400 );
+ $this->mMemc->set( $this->mMemcKey, 'error', 60*5 );
wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
}
}
$conditions['page_title']=MessageCacheHints::get();
}
}
- $res = $dbr->select( array( 'page', 'text' ),
+ $res = $dbr->select( array( 'page', 'revision', 'text' ),
array( 'page_title', 'old_text', 'old_flags' ),
- 'page_is_redirect=0 AND page_namespace = '.NS_MEDIAWIKI.' AND page_latest = old_id',
+ 'page_is_redirect=0 AND page_namespace='.NS_MEDIAWIKI.' AND page_latest=rev_id AND rev_text_id=old_id',
$fname
);
}
$dbr->freeResult( $res );
+ /*
+ # FIXME: This is too slow currently.
+ # We need to bulk-fetch revisions, but in a portable way...
+ $resultSet = Revision::fetchFromConds( $dbr, array(
+ 'page_namespace' => NS_MEDIAWIKI,
+ 'page_is_redirect' => 0,
+ 'page_id=rev_page' ) );
+ while( $row = $resultSet->fetchObject() ) {
+ $revision = new Revision( $row );
+ $title = $revision->getTitle();
+ $this->mCache[$title->getDBkey()] = $revision->getText();
+ }
+ $resultSet->free();
+ */
}
/**
if(!$isfullkey && ($langcode != $wgContLanguageCode) ) {
$title .= '/' . $langcode;
}
-
- # Try the cache
- 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->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 = 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 );
- }
- }
- }
+ $message = $this->getFromCache( $title );
}
# Try the extension array
if( !$message ) {
wfRestoreWarnings();
}
+ # Is this a custom message? Try the default language in the db...
+ if( !$message &&
+ !$this->mDisable && $useDB &&
+ !$isfullkey && ($langcode != $wgContLanguageCode) ) {
+ $message = $this->getFromCache( $lang->ucfirst( $key ) );
+ }
+
# Final fallback
if( !$message ) {
$message = "<$key>";
$message = $this->transform( $message );
return $message;
}
+
+ function getFromCache( $title ) {
+ $message = false;
+
+ # Try the cache
+ 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 ) {
+ $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
+ if( $revision ) {
+ $message = $revision->getText();
+ 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 );
+ }
+ }
+ }
+
+ return $message;
+ }
function transform( $message ) {
if( !$this->mDisableTransform ) {