/**
*
* @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" );
}
}
}
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;
* Loads all or main part of cacheable messages from the database
*/
function 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' ), $conditions, $fname);
+ $conditions = array( 'page_is_redirect' => 0,
+ 'page_namespace' => NS_MEDIAWIKI);
+ $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=rev_id AND rev_text_id=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 );
+ /*
+ # 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 ( !$this->mKeys ) {
$this->mKeys = array();
foreach ( $wgAllMessagesEn as $key => $value ) {
- global $wgCapitalLinks;
- $title = $wgCapitalLinks ? $wgContLang->ucfirst( $key ) : $key;
+ $title = $wgContLang->ucfirst( $key );
array_push( $this->mKeys, $title );
}
}
*/
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, $forcontent=true ) {
+ function get( $key, $useDB, $forcontent=true, $isfullkey = false ) {
global $wgContLanguageCode;
if( $forcontent ) {
global $wgContLang;
}
# If uninitialised, someone is trying to call this halfway through Setup.php
if( !$this->mInitialised ) {
- return "<$key>";
+ return '<' . htmlspecialchars($key) . '>';
}
# If cache initialization was deferred, start it now.
if( $this->mDeferred ) {
$message = false;
if( !$this->mDisable && $useDB ) {
- global $wgCapitalLinks;
- $title = $wgCapitalLinks ? $lang->ucfirst( $key ) : $key;
- if( $langcode != $wgContLanguageCode ) {
+ $title = $lang->ucfirst( $key );
+ 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( '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 );
- }
- }
- }
+ $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>";
+ return '<' . htmlspecialchars($key) . '>';
}
# Replace brace tags
$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 ) {