X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FMessageCache.php;h=64336585a28df574220c73a48a58242769ec5bd4;hb=eb1cf2c5b3aed2a7f84bee462b321f3d4eab13c7;hp=365a857c36beb466966fd7305b5f80cd841601f6;hpb=412eda051740b525169ffca2666ab18600c56501;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 365a857c36..64336585a2 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -2,8 +2,12 @@ /** * * @package MediaWiki + * @subpackage Cache */ +/** */ +require_once( 'Revision.php' ); + /** * */ @@ -23,6 +27,7 @@ class MessageCache var $mMemcKey, $mKeys, $mParserOptions, $mParser; var $mExtensionMessages; var $mInitialised = false; + var $mDeferred = true; function initialise( &$memCached, $useDB, $expiry, $memcPrefix) { $fname = 'MessageCache::initialise'; @@ -44,7 +49,12 @@ class MessageCache $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 ); } @@ -87,7 +97,7 @@ class MessageCache } 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" ); } } @@ -95,7 +105,7 @@ class MessageCache } 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; @@ -113,6 +123,7 @@ class MessageCache } } wfProfileOut( $fname ); + $this->mDeferred = false; return $success; } @@ -123,25 +134,43 @@ class MessageCache global $wgPartialMessageCache; $fname = 'MessageCache::loadFromDB'; $dbr =& wfGetDB( DB_SLAVE ); - $conditions = 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['cur_title']=$wgPartialMessageCache; + $conditions['page_title']=$wgPartialMessageCache; } else { require_once("MessageCacheHints.php"); - $conditions['cur_title']=MessageCacheHints::get(); + $conditions['page_title']=MessageCacheHints::get(); } } - $res = $dbr->select( 'cur', - array( 'cur_title', 'cur_text' ), $conditions, $fname); + $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(); + */ } /** @@ -152,7 +181,8 @@ class MessageCache 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; @@ -163,11 +193,6 @@ class MessageCache */ 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 ) { @@ -206,80 +231,62 @@ class MessageCache $this->mMemc->delete( $lockKey ); } - function get( $key, $useDB, $forcontent=true ) { + function get( $key, $useDB, $forcontent=true, $isfullkey = false ) { global $wgContLanguageCode; - if($forcontent) { + if( $forcontent ) { global $wgContLang; - $lang = $wgContLang; + $lang =& $wgContLang; $langcode = $wgContLanguageCode; - } - else { + } else { global $wgLang, $wgLanguageCode; - $lang = $wgLang; + $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 ) { + 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 ) ) { - $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); - } - } + if(!$isfullkey && ($langcode != $wgContLanguageCode) ) { + $title .= '/' . $langcode; } + $message = $this->getFromCache( $title ); } # 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 = $lang->getMessage( $key ); wfRestoreWarnings(); } # Try the English array - if ( !$message && $langcode != 'en' ) { + if( !$message && $langcode != 'en' ) { wfSuppressWarnings(); $message = Language::getMessage( $key ); 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 ) { + if( !$message ) { $message = "<$key>"; } @@ -287,10 +294,43 @@ class MessageCache $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 ) { - if ( strstr( $message, '{{' ) !== false ) { + if( strpos( $message, '{{' ) !== false ) { $message = $this->mParser->transformMsg( $message, $this->mParserOptions ); } }