2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'MSG_LOAD_TIMEOUT', 60);
|
|
|
|
|
define( 'MSG_LOCK_TIMEOUT', 10);
|
|
|
|
|
define( 'MSG_WAIT_TIMEOUT', 10);
|
2007-01-05 18:08:29 +00:00
|
|
|
define( 'MSG_CACHE_VERSION', 1 );
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Message cache
|
2007-01-05 18:08:29 +00:00
|
|
|
* Performs various MediaWiki namespace-related functions
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-12-04 18:27:59 +00:00
|
|
|
class MessageCache {
|
2006-05-11 22:40:38 +00:00
|
|
|
var $mCache, $mUseCache, $mDisable, $mExpiry;
|
|
|
|
|
var $mMemcKey, $mKeys, $mParserOptions, $mParser;
|
|
|
|
|
var $mExtensionMessages = array();
|
|
|
|
|
var $mInitialised = false;
|
2008-06-01 03:27:48 +00:00
|
|
|
var $mDeferred = true;
|
|
|
|
|
var $mAllMessagesLoaded;
|
2004-09-25 02:23:04 +00:00
|
|
|
|
2006-07-02 15:57:59 +00:00
|
|
|
function __construct( &$memCached, $useDB, $expiry, $memcPrefix) {
|
2006-07-03 11:08:02 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2004-09-25 02:23:04 +00:00
|
|
|
|
2004-05-09 05:12:55 +00:00
|
|
|
$this->mUseCache = !is_null( $memCached );
|
|
|
|
|
$this->mMemc = &$memCached;
|
2003-12-14 14:32:19 +00:00
|
|
|
$this->mDisable = !$useDB;
|
|
|
|
|
$this->mExpiry = $expiry;
|
2004-05-03 10:21:26 +00:00
|
|
|
$this->mDisableTransform = false;
|
2004-08-22 17:24:50 +00:00
|
|
|
$this->mMemcKey = $memcPrefix.':messages';
|
2003-12-14 14:32:19 +00:00
|
|
|
$this->mKeys = false; # initialised on demand
|
2004-01-07 13:05:27 +00:00
|
|
|
$this->mInitialised = true;
|
2006-07-03 11:17:27 +00:00
|
|
|
$this->mParser = null;
|
2004-09-24 13:10:38 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
# 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;
|
|
|
|
|
|
2006-07-03 11:08:02 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
2006-07-26 07:15:39 +00:00
|
|
|
function getParserOptions() {
|
|
|
|
|
if ( !$this->mParserOptions ) {
|
|
|
|
|
$this->mParserOptions = new ParserOptions;
|
|
|
|
|
}
|
|
|
|
|
return $this->mParserOptions;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-07 13:09:30 +00:00
|
|
|
/**
|
2008-06-01 03:27:48 +00:00
|
|
|
* Try to load the cache from a local file
|
2005-11-08 11:54:04 +00:00
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function loadFromLocal( $hash ) {
|
2008-02-02 18:15:57 +00:00
|
|
|
global $wgLocalMessageCache, $wgLocalMessageCacheSerialized;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-04 09:06:18 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2005-12-30 08:50:59 +00:00
|
|
|
wfSuppressWarnings();
|
2005-11-08 11:54:04 +00:00
|
|
|
$file = fopen( $filename, 'r' );
|
2005-12-30 08:50:59 +00:00
|
|
|
wfRestoreWarnings();
|
2005-11-08 11:54:04 +00:00
|
|
|
if ( !$file ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
return;
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-02-02 18:15:57 +00:00
|
|
|
if ( $wgLocalMessageCacheSerialized ) {
|
|
|
|
|
// Check to see if the file has the hash specified
|
|
|
|
|
$localHash = fread( $file, 32 );
|
|
|
|
|
if ( $hash === $localHash ) {
|
|
|
|
|
// All good, get the rest of it
|
2008-02-13 05:46:43 +00:00
|
|
|
$serialized = '';
|
|
|
|
|
while ( !feof( $file ) ) {
|
|
|
|
|
$serialized .= fread( $file, 100000 );
|
|
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->setCache( unserialize( $serialized ) );
|
2008-02-02 18:15:57 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
fclose( $file );
|
2008-02-10 14:29:17 +00:00
|
|
|
} else {
|
|
|
|
|
$localHash=substr(fread($file,40),8);
|
|
|
|
|
fclose($file);
|
|
|
|
|
if ($hash!=$localHash) {
|
2008-06-01 03:27:48 +00:00
|
|
|
return;
|
2008-02-10 14:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
require("$wgLocalMessageCache/messages-" . wfWikiID());
|
|
|
|
|
$this->setCache( $this->mCache);
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save the cache to a local file
|
|
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function saveToLocal( $serialized, $hash ) {
|
|
|
|
|
global $wgLocalMessageCache, $wgLocalMessageCacheSerialized;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-05-23 22:14:32 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
|
|
|
|
$oldUmask = umask( 0 );
|
|
|
|
|
wfMkdirParents( $wgLocalMessageCache, 0777 );
|
|
|
|
|
umask( $oldUmask );
|
2005-11-08 11:54:04 +00:00
|
|
|
|
|
|
|
|
$file = fopen( $filename, 'w' );
|
|
|
|
|
if ( !$file ) {
|
|
|
|
|
wfDebug( "Unable to open local cache file for writing\n" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fwrite( $file, $hash . $serialized );
|
|
|
|
|
fclose( $file );
|
2006-01-04 23:24:25 +00:00
|
|
|
@chmod( $filename, 0666 );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
function loadFromScript( $hash ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
$this->loadFromLocal( $hash );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveToScript($array, $hash) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2008-06-01 03:27:48 +00:00
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-05-28 18:29:42 +00:00
|
|
|
|
2006-10-04 09:06:18 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
2008-06-01 03:27:48 +00:00
|
|
|
$oldUmask = umask( 0 );
|
|
|
|
|
wfMkdirParents( $wgLocalMessageCache, 0777 );
|
|
|
|
|
umask( $oldUmask );
|
|
|
|
|
$file = fopen( $filename.'.tmp', 'w');
|
2006-05-28 18:29:42 +00:00
|
|
|
fwrite($file,"<?php\n//$hash\n\n \$this->mCache = array(");
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-05-28 18:29:42 +00:00
|
|
|
foreach ($array as $key => $message) {
|
2008-06-01 03:27:48 +00:00
|
|
|
fwrite($file, "'". $this->escapeForScript($key).
|
|
|
|
|
"' => '" . $this->escapeForScript($message).
|
|
|
|
|
"',\n");
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
|
|
|
|
fwrite($file,");\n?>");
|
|
|
|
|
fclose($file);
|
2008-06-01 03:27:48 +00:00
|
|
|
rename($filename.'.tmp',$filename);
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2006-05-29 05:49:03 +00:00
|
|
|
function escapeForScript($string) {
|
|
|
|
|
$string = str_replace( '\\', '\\\\', $string );
|
|
|
|
|
$string = str_replace( '\'', '\\\'', $string );
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
|
|
|
|
* Set the cache to $cache, if it is valid. Otherwise set the cache to false.
|
|
|
|
|
*/
|
|
|
|
|
function setCache( $cache ) {
|
|
|
|
|
if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache = $cache;
|
2007-01-05 18:08:29 +00:00
|
|
|
} else {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache = false;
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2008-06-01 03:27:48 +00:00
|
|
|
* Loads messages either from memcached or the database, if not disabled
|
|
|
|
|
* On error, quietly switches to a fallback mode
|
|
|
|
|
* Returns false for a reportable error, true otherwise
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function load() {
|
|
|
|
|
global $wgLocalMessageCache, $wgLocalMessageCacheSerialized;
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( $this->mDisable ) {
|
2005-05-28 11:07:55 +00:00
|
|
|
static $shownDisabled = false;
|
|
|
|
|
if ( !$shownDisabled ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
wfDebug( "MessageCache::load(): disabled\n" );
|
2005-05-28 11:07:55 +00:00
|
|
|
$shownDisabled = true;
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
$this->mDeferred = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
$fname = 'MessageCache::load';
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
$success = true;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache = false;
|
|
|
|
|
|
|
|
|
|
# Try local cache
|
2008-02-02 18:15:57 +00:00
|
|
|
if ( $wgLocalMessageCache !== false ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
wfProfileIn( $fname.'-fromlocal' );
|
|
|
|
|
$hash = $this->mMemc->get( "{$this->mMemcKey}-hash" );
|
2008-02-02 18:15:57 +00:00
|
|
|
if ( $hash ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->loadFromLocal( $hash );
|
|
|
|
|
if ( $this->mCache ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): got from local cache\n" );
|
|
|
|
|
}
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
wfProfileOut( $fname.'-fromlocal' );
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
# Try memcached
|
|
|
|
|
if ( !$this->mCache ) {
|
|
|
|
|
wfProfileIn( $fname.'-fromcache' );
|
|
|
|
|
$this->setCache( $this->mMemc->get( $this->mMemcKey ) );
|
|
|
|
|
if ( $this->mCache ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): got from global cache\n" );
|
|
|
|
|
# Save to local cache
|
|
|
|
|
if ( $wgLocalMessageCache !== false ) {
|
|
|
|
|
$serialized = serialize( $this->mCache );
|
|
|
|
|
if ( !$hash ) {
|
|
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
|
|
|
|
|
}
|
|
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->saveToLocal( $serialized,$hash );
|
|
|
|
|
} else {
|
|
|
|
|
$this->saveToScript( $this->mCache, $hash );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
wfProfileOut( $fname.'-fromcache' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If there's nothing in memcached, load all the messages from the database
|
|
|
|
|
if ( !$this->mCache ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): cache is empty\n" );
|
|
|
|
|
$this->lock();
|
|
|
|
|
# Other threads don't need to load the messages if another thread is doing it.
|
|
|
|
|
$success = $this->mMemc->add( $this->mMemcKey.'-status', "loading", MSG_LOAD_TIMEOUT );
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( $success ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
wfProfileIn( $fname.'-load' );
|
|
|
|
|
wfDebug( "MessageCache::load(): loading all messages from DB\n" );
|
|
|
|
|
$this->loadFromDB();
|
|
|
|
|
wfProfileOut( $fname.'-load' );
|
|
|
|
|
|
|
|
|
|
# Save in memcached
|
|
|
|
|
# Keep trying if it fails, this is kind of important
|
|
|
|
|
wfProfileIn( $fname.'-save' );
|
|
|
|
|
for ($i=0; $i<20 &&
|
|
|
|
|
!$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
|
|
|
|
|
$i++ ) {
|
|
|
|
|
usleep(mt_rand(500000,1500000));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Save to local cache
|
|
|
|
|
if ( $wgLocalMessageCache !== false ) {
|
|
|
|
|
$serialized = serialize( $this->mCache );
|
|
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
|
|
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->saveToLocal( $serialized,$hash );
|
|
|
|
|
} else {
|
|
|
|
|
$this->saveToScript( $this->mCache, $hash );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wfProfileOut( $fname.'-save' );
|
|
|
|
|
if ( $i == 20 ) {
|
|
|
|
|
$this->mMemc->set( $this->mMemcKey.'-status', 'error', 60*5 );
|
|
|
|
|
wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->mMemc->delete( $this->mMemcKey.'-status' );
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->unlock();
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
if ( !is_array( $this->mCache ) ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): unable to load cache, disabled\n" );
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mDisable = true;
|
|
|
|
|
$this->mCache = false;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
$this->mDeferred = false;
|
2003-12-14 14:32:19 +00:00
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2008-06-01 03:27:48 +00:00
|
|
|
* Loads all or main part of cacheable messages from the database
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function loadFromDB() {
|
|
|
|
|
global $wgMaxMsgCacheEntrySize;
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache = array();
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Load titles for all oversized pages in the MediaWiki namespace
|
2008-06-01 03:27:48 +00:00
|
|
|
$res = $dbr->select( 'page', 'page_title',
|
|
|
|
|
array(
|
|
|
|
|
'page_len > ' . intval( $wgMaxMsgCacheEntrySize ),
|
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
|
'page_namespace' => NS_MEDIAWIKI,
|
|
|
|
|
),
|
|
|
|
|
__METHOD__ );
|
2007-01-05 18:08:29 +00:00
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache[$row->page_title] = '!TOO BIG';
|
2005-03-19 10:40:41 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
$dbr->freeResult( $res );
|
2006-06-25 08:38:17 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
# Load text for the remaining pages
|
2007-01-05 18:08:29 +00:00
|
|
|
$res = $dbr->select( array( 'page', 'revision', 'text' ),
|
|
|
|
|
array( 'page_title', 'old_text', 'old_flags' ),
|
2008-06-01 03:27:48 +00:00
|
|
|
array(
|
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
|
'page_namespace' => NS_MEDIAWIKI,
|
|
|
|
|
'page_latest=rev_id',
|
|
|
|
|
'rev_text_id=old_id',
|
|
|
|
|
'page_len <= ' . intval( $wgMaxMsgCacheEntrySize ) ),
|
|
|
|
|
__METHOD__ );
|
2006-06-25 08:38:17 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
for ( $row = $dbr->fetchObject( $res ); $row; $row = $dbr->fetchObject( $res ) ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache[$row->page_title] = ' ' . Revision::getRevisionText( $row );
|
2006-01-07 13:31:29 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache['VERSION'] = MSG_CACHE_VERSION;
|
2005-09-11 14:50:47 +00:00
|
|
|
$dbr->freeResult( $res );
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
function replace( $title, $text ) {
|
|
|
|
|
global $wgLocalMessageCache, $wgLocalMessageCacheSerialized, $parserMemc;
|
|
|
|
|
global $wgMaxMsgCacheEntrySize;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->lock();
|
|
|
|
|
$this->load();
|
|
|
|
|
if ( is_array( $this->mCache ) ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( $text === false ) {
|
|
|
|
|
# Article was deleted
|
|
|
|
|
unset( $this->mCache[$title] );
|
|
|
|
|
$this->mMemc->delete( "$this->mMemcKey:{$title}" );
|
|
|
|
|
} elseif ( strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache[$title] = '!TOO BIG';
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mMemc->set( "$this->mMemcKey:{$title}", ' '.$text, $this->mExpiry );
|
|
|
|
|
} else {
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mCache[$title] = ' ' . $text;
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mMemc->delete( "$this->mMemcKey:{$title}" );
|
|
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
|
|
|
|
|
|
|
|
|
|
# Save to local cache
|
|
|
|
|
if ( $wgLocalMessageCache !== false ) {
|
|
|
|
|
$serialized = serialize( $this->mCache );
|
|
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
|
|
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->saveToLocal( $serialized,$hash );
|
|
|
|
|
} else {
|
|
|
|
|
$this->saveToScript( $this->mCache, $hash );
|
|
|
|
|
}
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$this->unlock();
|
|
|
|
|
$parserMemc->delete(wfMemcKey('sidebar'));
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Returns success
|
|
|
|
|
* Represents a write lock on the messages key
|
|
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function lock() {
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
$lockKey = $this->mMemcKey . 'lock';
|
2004-05-09 05:12:55 +00:00
|
|
|
for ($i=0; $i < MSG_WAIT_TIMEOUT && !$this->mMemc->add( $lockKey, 1, MSG_LOCK_TIMEOUT ); $i++ ) {
|
2003-12-14 14:32:19 +00:00
|
|
|
sleep(1);
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
return $i >= MSG_WAIT_TIMEOUT;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
function unlock() {
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
$lockKey = $this->mMemcKey . 'lock';
|
2004-05-09 05:12:55 +00:00
|
|
|
$this->mMemc->delete( $lockKey );
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get a message from either the content language or the user language.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key The message cache key
|
|
|
|
|
* @param bool $useDB Get the message from the DB, false to use only the localisation
|
2008-04-24 11:59:32 +00:00
|
|
|
* @param string $langcode Code of the language to get the message for, if
|
|
|
|
|
* it is a valid code create a language for that
|
|
|
|
|
* language, if it is a string but not a valid code
|
|
|
|
|
* then make a basic language object, if it is a
|
|
|
|
|
* false boolean then use the current users
|
|
|
|
|
* language (as a fallback for the old parameter
|
|
|
|
|
* functionality), or if it is a true boolean then
|
|
|
|
|
* use the wikis content language (also as a
|
|
|
|
|
* fallback).
|
2007-01-05 18:08:29 +00:00
|
|
|
* @param bool $isFullKey Specifies whether $key is a two part key "lang/msg".
|
|
|
|
|
*/
|
2008-04-27 14:50:55 +00:00
|
|
|
function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
|
2006-07-26 08:26:51 +00:00
|
|
|
global $wgContLanguageCode, $wgContLang, $wgLang;
|
2008-04-24 11:59:32 +00:00
|
|
|
|
|
|
|
|
# Identify which language to get or create a language object for.
|
2008-04-24 13:02:32 +00:00
|
|
|
if( $langcode === $wgContLang->getCode() || $langcode === true ) {
|
2008-04-24 11:59:32 +00:00
|
|
|
# $langcode is the language code of the wikis content language object.
|
2008-04-24 13:02:32 +00:00
|
|
|
# or it is a boolean and value is true
|
2004-11-21 13:56:04 +00:00
|
|
|
$lang =& $wgContLang;
|
2008-04-24 13:02:32 +00:00
|
|
|
} elseif( $langcode === $wgLang->getCode() || $langcode === false ) {
|
2008-04-24 11:59:32 +00:00
|
|
|
# $langcode is the language code of user language object.
|
2008-04-24 13:02:32 +00:00
|
|
|
# or it was a boolean and value is false
|
2004-11-21 13:56:04 +00:00
|
|
|
$lang =& $wgLang;
|
2008-04-24 11:59:32 +00:00
|
|
|
} else {
|
2008-04-24 13:02:32 +00:00
|
|
|
$validCodes = array_keys( Language::getLanguageNames() );
|
|
|
|
|
if( in_array( $langcode, $validCodes ) ) {
|
|
|
|
|
# $langcode corresponds to a valid language.
|
|
|
|
|
$lang = Language::factory( $langcode );
|
|
|
|
|
} else {
|
|
|
|
|
# $langcode is a string, but not a valid language code; use content language.
|
|
|
|
|
$lang =& $wgContLang;
|
|
|
|
|
wfDebug( 'Invalid language code passed to MessageCache::get, falling back to content language.' );
|
|
|
|
|
}
|
2004-09-25 04:15:47 +00:00
|
|
|
}
|
2008-04-24 11:59:32 +00:00
|
|
|
|
2006-07-26 08:26:51 +00:00
|
|
|
$langcode = $lang->getCode();
|
2008-04-24 11:59:32 +00:00
|
|
|
|
2004-01-07 13:05:27 +00:00
|
|
|
# If uninitialised, someone is trying to call this halfway through Setup.php
|
2004-11-21 13:56:04 +00:00
|
|
|
if( !$this->mInitialised ) {
|
2005-05-14 05:42:29 +00:00
|
|
|
return '<' . htmlspecialchars($key) . '>';
|
2004-01-07 13:05:27 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
# If cache initialization was deferred, start it now.
|
|
|
|
|
if( $this->mDeferred && !$this->mDisable && $useDB ) {
|
|
|
|
|
$this->load();
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
$message = false;
|
2007-01-05 18:08:29 +00:00
|
|
|
|
2007-01-07 14:22:32 +00:00
|
|
|
# Normalise title-case input
|
2007-01-07 15:43:23 +00:00
|
|
|
$lckey = $wgContLang->lcfirst( $key );
|
2007-01-09 00:00:56 +00:00
|
|
|
$lckey = str_replace( ' ', '_', $lckey );
|
2007-01-07 14:22:32 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Try the MediaWiki namespace
|
2004-11-21 13:56:04 +00:00
|
|
|
if( !$this->mDisable && $useDB ) {
|
2007-01-09 00:21:55 +00:00
|
|
|
$title = $wgContLang->ucfirst( $lckey );
|
2007-01-05 18:08:29 +00:00
|
|
|
if(!$isFullKey && ($langcode != $wgContLanguageCode) ) {
|
2004-11-21 13:56:04 +00:00
|
|
|
$title .= '/' . $langcode;
|
|
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
$message = $this->getMsgFromNamespace( $title );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
# Try the extension array
|
2008-06-01 03:27:48 +00:00
|
|
|
if( $message === false && isset( $this->mExtensionMessages[$langcode][$lckey] ) ) {
|
2007-01-07 15:43:23 +00:00
|
|
|
$message = $this->mExtensionMessages[$langcode][$lckey];
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
2007-01-07 15:43:23 +00:00
|
|
|
if ( $message === false && isset( $this->mExtensionMessages['en'][$lckey] ) ) {
|
|
|
|
|
$message = $this->mExtensionMessages['en'][$lckey];
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-24 00:09:42 +00:00
|
|
|
# Try the array in the language object
|
2008-06-01 03:27:48 +00:00
|
|
|
if( $message === false ) {
|
|
|
|
|
#wfDebug( "Trying language object for message $key\n" );
|
|
|
|
|
wfSuppressWarnings();
|
2007-01-07 15:43:23 +00:00
|
|
|
$message = $lang->getMessage( $lckey );
|
2008-06-01 03:27:48 +00:00
|
|
|
wfRestoreWarnings();
|
2005-10-22 20:52:30 +00:00
|
|
|
if ( is_null( $message ) ) {
|
|
|
|
|
$message = false;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
|
2006-08-07 12:21:06 +00:00
|
|
|
# Try the array of another language
|
2008-02-02 18:15:57 +00:00
|
|
|
$pos = strrpos( $lckey, '/' );
|
|
|
|
|
if( $message === false && $pos !== false) {
|
|
|
|
|
$mkey = substr( $lckey, 0, $pos );
|
|
|
|
|
$code = substr( $lckey, $pos+1 );
|
|
|
|
|
if ( $code ) {
|
|
|
|
|
$validCodes = array_keys( Language::getLanguageNames() );
|
|
|
|
|
if ( in_array( $code, $validCodes ) ) {
|
|
|
|
|
$message = Language::getMessageFor( $mkey, $code );
|
|
|
|
|
if ( is_null( $message ) ) {
|
|
|
|
|
$message = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . ": Invalid code $code for $mkey/$code, not trying messages array\n" );
|
2006-08-10 09:10:06 +00:00
|
|
|
}
|
2006-08-07 12:21:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
# Is this a custom message? Try the default language in the db...
|
2006-05-31 08:05:38 +00:00
|
|
|
if( ($message === false || $message === '-' ) &&
|
2005-03-13 11:50:54 +00:00
|
|
|
!$this->mDisable && $useDB &&
|
2007-01-05 18:08:29 +00:00
|
|
|
!$isFullKey && ($langcode != $wgContLanguageCode) ) {
|
2008-06-01 03:27:48 +00:00
|
|
|
$message = $this->getMsgFromNamespace( $wgContLang->ucfirst( $lckey ) );
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
# Final fallback
|
2005-09-11 14:50:47 +00:00
|
|
|
if( $message === false ) {
|
2005-05-14 05:42:29 +00:00
|
|
|
return '<' . htmlspecialchars($key) . '>';
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Get a message from the MediaWiki namespace, with caching. The key must
|
2007-01-05 18:08:29 +00:00
|
|
|
* first be converted to two-part lang/msg form if necessary.
|
|
|
|
|
*
|
2008-06-01 03:27:48 +00:00
|
|
|
* @param string $title Message cache key with initial uppercase letter
|
2007-01-05 18:08:29 +00:00
|
|
|
*/
|
2008-06-01 03:27:48 +00:00
|
|
|
function getMsgFromNamespace( $title ) {
|
2005-03-13 11:50:54 +00:00
|
|
|
$message = false;
|
2007-01-05 18:08:29 +00:00
|
|
|
$type = false;
|
2005-07-07 03:08:58 +00:00
|
|
|
|
2008-06-01 03:27:48 +00:00
|
|
|
# Try the cache
|
|
|
|
|
if( $this->mUseCache && isset( $this->mCache[$title] ) ) {
|
|
|
|
|
$entry = $this->mCache[$title];
|
|
|
|
|
$type = substr( $entry, 0, 1 );
|
|
|
|
|
if ( $type == ' ' ) {
|
|
|
|
|
return substr( $entry, 1 );
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Call message hooks, in case they are defined
|
|
|
|
|
wfRunHooks('MessagesPreLoad', array( $title, &$message ) );
|
|
|
|
|
if ( $message !== false ) {
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If there is no cache entry and no placeholder, it doesn't exist
|
|
|
|
|
if ( $type != '!' && $message === false ) {
|
|
|
|
|
return false;
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
$memcKey = $this->mMemcKey . ':' . $title;
|
|
|
|
|
|
|
|
|
|
# Try the individual message cache
|
2005-09-11 14:50:47 +00:00
|
|
|
if ( $this->mUseCache ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
$entry = $this->mMemc->get( $memcKey );
|
|
|
|
|
if ( $entry ) {
|
|
|
|
|
$type = substr( $entry, 0, 1 );
|
|
|
|
|
|
|
|
|
|
if ( $type == ' ' ) {
|
2007-04-27 16:39:21 +00:00
|
|
|
$message = substr( $entry, 1 );
|
2007-04-27 16:36:34 +00:00
|
|
|
$this->mCache[$title] = $entry;
|
2007-01-05 18:08:29 +00:00
|
|
|
return $message;
|
|
|
|
|
} elseif ( $entry == '!NONEXISTENT' ) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
# Corrupt/obsolete entry, delete it
|
|
|
|
|
$this->mMemc->delete( $memcKey );
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Try loading it from the DB
|
2005-09-11 14:50:47 +00:00
|
|
|
$revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
|
|
|
|
|
if( $revision ) {
|
|
|
|
|
$message = $revision->getText();
|
|
|
|
|
if ($this->mUseCache) {
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mCache[$title] = ' ' . $message;
|
|
|
|
|
$this->mMemc->set( $memcKey, $message, $this->mExpiry );
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
2005-09-11 14:50:47 +00:00
|
|
|
} else {
|
|
|
|
|
# Negative caching
|
2005-09-11 17:33:25 +00:00
|
|
|
# Use some special text instead of false, because false gets converted to '' somewhere
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mMemc->set( $memcKey, '!NONEXISTENT', $this->mExpiry );
|
2006-08-05 14:12:34 +00:00
|
|
|
$this->mCache[$title] = false;
|
2005-03-13 11:50:54 +00:00
|
|
|
}
|
2008-06-01 03:27:48 +00:00
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
return $message;
|
|
|
|
|
}
|
2004-03-01 05:51:55 +00:00
|
|
|
|
2007-10-22 19:33:46 +00:00
|
|
|
function transform( $message, $interface = false ) {
|
2006-07-03 11:08:02 +00:00
|
|
|
global $wgParser;
|
2006-07-03 11:17:27 +00:00
|
|
|
if ( !$this->mParser && isset( $wgParser ) ) {
|
2006-07-04 09:13:10 +00:00
|
|
|
# Do some initialisation so that we don't have to do it twice
|
|
|
|
|
$wgParser->firstCallInit();
|
|
|
|
|
# Clone it and store it
|
2006-07-03 11:17:27 +00:00
|
|
|
$this->mParser = clone $wgParser;
|
|
|
|
|
}
|
2008-01-19 09:03:45 +00:00
|
|
|
if ( $this->mParser ) {
|
2004-11-21 13:56:04 +00:00
|
|
|
if( strpos( $message, '{{' ) !== false ) {
|
2007-10-22 19:33:46 +00:00
|
|
|
$popts = $this->getParserOptions();
|
2008-01-19 09:03:45 +00:00
|
|
|
$popts->setInterfaceMessage( $interface );
|
2007-10-22 19:33:46 +00:00
|
|
|
$message = $this->mParser->transformMsg( $message, $popts );
|
2004-05-03 10:21:26 +00:00
|
|
|
}
|
2004-04-05 10:38:40 +00:00
|
|
|
}
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2004-03-01 05:51:55 +00:00
|
|
|
function disable() { $this->mDisable = true; }
|
|
|
|
|
function enable() { $this->mDisable = false; }
|
2008-06-01 03:27:48 +00:00
|
|
|
|
2008-01-19 09:03:45 +00:00
|
|
|
/** @deprecated */
|
2008-04-02 11:49:55 +00:00
|
|
|
function disableTransform(){
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function enableTransform() {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function setTransform( $x ) {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
function getTransform() {
|
|
|
|
|
wfDeprecated( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-03-01 05:51:55 +00:00
|
|
|
|
2005-06-26 15:30:50 +00:00
|
|
|
/**
|
|
|
|
|
* Add a message to the cache
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $key
|
|
|
|
|
* @param mixed $value
|
2006-06-30 20:46:54 +00:00
|
|
|
* @param string $lang The messages language, English by default
|
2005-06-26 15:30:50 +00:00
|
|
|
*/
|
2006-06-30 20:46:54 +00:00
|
|
|
function addMessage( $key, $value, $lang = 'en' ) {
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mExtensionMessages[$lang][$key] = $value;
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
2005-06-26 15:30:50 +00:00
|
|
|
/**
|
|
|
|
|
* Add an associative array of message to the cache
|
|
|
|
|
*
|
|
|
|
|
* @param array $messages An associative array of key => values to be added
|
2006-06-30 20:46:54 +00:00
|
|
|
* @param string $lang The messages language, English by default
|
2005-06-26 15:30:50 +00:00
|
|
|
*/
|
2006-06-30 20:46:54 +00:00
|
|
|
function addMessages( $messages, $lang = 'en' ) {
|
2006-07-02 15:57:59 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-01-29 01:04:29 +00:00
|
|
|
if ( !is_array( $messages ) ) {
|
|
|
|
|
throw new MWException( __METHOD__.': Invalid message array' );
|
|
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( isset( $this->mExtensionMessages[$lang] ) ) {
|
|
|
|
|
$this->mExtensionMessages[$lang] = $messages + $this->mExtensionMessages[$lang];
|
|
|
|
|
} else {
|
|
|
|
|
$this->mExtensionMessages[$lang] = $messages;
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2006-07-02 15:57:59 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2007-01-06 18:29:53 +00:00
|
|
|
/**
|
|
|
|
|
* Add a 2-D array of messages by lang. Useful for extensions.
|
|
|
|
|
*
|
|
|
|
|
* @param array $messages The array to be added
|
|
|
|
|
*/
|
|
|
|
|
function addMessagesByLang( $messages ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
foreach ( $messages as $key => $value ) {
|
|
|
|
|
$this->addMessages( $value, $key );
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 16:31:28 +00:00
|
|
|
/**
|
2008-02-02 20:33:25 +00:00
|
|
|
* Get the extension messages for a specific language. Only English, interface
|
|
|
|
|
* and content language are guaranteed to be loaded.
|
2006-09-03 16:31:28 +00:00
|
|
|
*
|
|
|
|
|
* @param string $lang The messages language, English by default
|
|
|
|
|
*/
|
|
|
|
|
function getExtensionMessagesFor( $lang = 'en' ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$messages = array();
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( isset( $this->mExtensionMessages[$lang] ) ) {
|
|
|
|
|
$messages = $this->mExtensionMessages[$lang];
|
|
|
|
|
}
|
|
|
|
|
if ( $lang != 'en' ) {
|
|
|
|
|
$messages = $messages + $this->mExtensionMessages['en'];
|
2006-09-03 16:31:28 +00:00
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $messages;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Clear all stored messages. Mainly used after a mass rebuild.
|
|
|
|
|
*/
|
2004-08-11 02:31:47 +00:00
|
|
|
function clear() {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2004-08-11 02:31:47 +00:00
|
|
|
if( $this->mUseCache ) {
|
2006-07-26 07:15:39 +00:00
|
|
|
# Global cache
|
2004-08-11 02:31:47 +00:00
|
|
|
$this->mMemc->delete( $this->mMemcKey );
|
2006-07-26 07:15:39 +00:00
|
|
|
# Invalidate all local caches
|
|
|
|
|
$this->mMemc->delete( "{$this->mMemcKey}-hash" );
|
2004-08-11 02:31:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-08-24 16:58:44 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
function loadAllMessages() {
|
|
|
|
|
global $wgExtensionMessagesFiles;
|
|
|
|
|
if ( $this->mAllMessagesLoaded ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->mAllMessagesLoaded = true;
|
|
|
|
|
|
2006-08-24 16:58:44 +00:00
|
|
|
# Some extensions will load their messages when you load their class file
|
|
|
|
|
wfLoadAllExtensions();
|
|
|
|
|
# Others will respond to this hook
|
|
|
|
|
wfRunHooks( 'LoadAllMessages' );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
# Some register their messages in $wgExtensionMessagesFiles
|
|
|
|
|
foreach ( $wgExtensionMessagesFiles as $name => $file ) {
|
2008-05-05 15:03:42 +00:00
|
|
|
wfLoadExtensionMessages( $name );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
2006-08-24 16:58:44 +00:00
|
|
|
# Still others will respond to neither, they are EVIL. We sometimes need to know!
|
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load messages from a given file
|
2008-04-24 11:59:32 +00:00
|
|
|
*
|
|
|
|
|
* @param string $filename Filename of file to load.
|
2008-05-05 13:29:51 +00:00
|
|
|
* @param string $langcode Language to load messages for, or false for
|
|
|
|
|
* default behvaiour (en, content language and user
|
|
|
|
|
* language).
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
*/
|
2008-05-05 13:29:51 +00:00
|
|
|
function loadMessagesFile( $filename, $langcode = false ) {
|
2008-02-02 20:33:25 +00:00
|
|
|
global $wgLang, $wgContLang;
|
2007-09-10 22:53:17 +00:00
|
|
|
$messages = $magicWords = false;
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
require( $filename );
|
2007-09-10 22:53:17 +00:00
|
|
|
|
2008-05-05 13:29:51 +00:00
|
|
|
$validCodes = Language::getLanguageNames();
|
|
|
|
|
if( is_string( $langcode ) && array_key_exists( $langcode, $validCodes ) ) {
|
|
|
|
|
# Load messages for given language code.
|
|
|
|
|
$this->processMessagesArray( $messages, $langcode );
|
|
|
|
|
} elseif( is_string( $langcode ) && !array_key_exists( $langcode, $validCodes ) ) {
|
|
|
|
|
wfDebug( "Invalid language '$langcode' code passed to MessageCache::loadMessagesFile()" );
|
2008-04-24 11:59:32 +00:00
|
|
|
} else {
|
|
|
|
|
# Load only languages that are usually used, and merge all
|
|
|
|
|
# fallbacks, except English.
|
|
|
|
|
$langs = array_unique( array( 'en', $wgContLang->getCode(), $wgLang->getCode() ) );
|
|
|
|
|
foreach( $langs as $code ) {
|
|
|
|
|
$this->processMessagesArray( $messages, $code );
|
|
|
|
|
}
|
2007-09-10 22:53:17 +00:00
|
|
|
}
|
2007-09-04 02:48:34 +00:00
|
|
|
|
|
|
|
|
if ( $magicWords !== false ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$wgContLang->addMagicWordsByLang( $magicWords );
|
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
2008-04-24 11:59:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process an array of messages, loading it into the message cache.
|
|
|
|
|
*
|
|
|
|
|
* @param array $messages Messages array.
|
2008-05-05 13:29:51 +00:00
|
|
|
* @param string $langcode Language code to process.
|
2008-04-24 11:59:32 +00:00
|
|
|
*/
|
2008-05-05 13:29:51 +00:00
|
|
|
function processMessagesArray( $messages, $langcode ) {
|
|
|
|
|
$fallbackCode = $langcode;
|
2008-04-24 11:59:32 +00:00
|
|
|
$mergedMessages = array();
|
|
|
|
|
do {
|
|
|
|
|
if ( isset($messages[$fallbackCode]) ) {
|
|
|
|
|
$mergedMessages += $messages[$fallbackCode];
|
|
|
|
|
}
|
|
|
|
|
$fallbackCode = Language::getFallbackfor( $fallbackCode );
|
|
|
|
|
} while( $fallbackCode && $fallbackCode !== 'en' );
|
|
|
|
|
|
|
|
|
|
if ( !empty($mergedMessages) )
|
2008-05-05 13:29:51 +00:00
|
|
|
$this->addMessages( $mergedMessages, $langcode );
|
2008-04-24 11:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|