2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2007-01-20 15:09:52 +00:00
|
|
|
* @addtogroup 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
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
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;
|
|
|
|
|
var $mDeferred = true;
|
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
|
|
|
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
|
|
|
|
2004-12-09 05:51:20 +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;
|
2005-07-07 03:08:58 +00:00
|
|
|
|
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
|
|
|
/**
|
2005-11-08 11:54:04 +00:00
|
|
|
* Try to load the cache from a local file
|
|
|
|
|
*/
|
|
|
|
|
function loadFromLocal( $hash ) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
|
|
|
|
$this->mCache = false;
|
|
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
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 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check to see if the file has the hash specified
|
|
|
|
|
$localHash = fread( $file, 32 );
|
|
|
|
|
if ( $hash == $localHash ) {
|
|
|
|
|
// All good, get the rest of it
|
2006-10-08 23:24:43 +00:00
|
|
|
$serialized = fread( $file, 10000000 );
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->setCache( unserialize( $serialized ) );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
|
|
|
|
fclose( $file );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save the cache to a local file
|
|
|
|
|
*/
|
|
|
|
|
function saveToLocal( $serialized, $hash ) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
|
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-10-04 09:06:18 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
2006-01-04 23:24:25 +00:00
|
|
|
$oldUmask = umask( 0 );
|
2005-11-08 11:54:04 +00:00
|
|
|
wfMkdirParents( $wgLocalMessageCache, 0777 );
|
2006-01-04 23:24:25 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2006-05-28 18:29:42 +00:00
|
|
|
function loadFromScript( $hash ) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2006-05-28 18:29:42 +00:00
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-04 09:06:18 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
2006-05-28 18:29:42 +00:00
|
|
|
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
$file = fopen( $filename, 'r' );
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
if ( !$file ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$localHash=substr(fread($file,40),8);
|
|
|
|
|
fclose($file);
|
|
|
|
|
if ($hash!=$localHash) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-10-04 09:06:18 +00:00
|
|
|
require("$wgLocalMessageCache/messages-" . wfWikiID());
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->setCache( $this->mCache);
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveToScript($array, $hash) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache;
|
2006-05-28 18:29:42 +00:00
|
|
|
if ( $wgLocalMessageCache === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-04 09:06:18 +00:00
|
|
|
$filename = "$wgLocalMessageCache/messages-" . wfWikiID();
|
2006-05-28 18:29:42 +00:00
|
|
|
$oldUmask = umask( 0 );
|
|
|
|
|
wfMkdirParents( $wgLocalMessageCache, 0777 );
|
|
|
|
|
umask( $oldUmask );
|
|
|
|
|
$file = fopen( $filename.'.tmp', 'w');
|
|
|
|
|
fwrite($file,"<?php\n//$hash\n\n \$this->mCache = array(");
|
|
|
|
|
|
|
|
|
|
foreach ($array as $key => $message) {
|
2006-05-29 05:49:03 +00:00
|
|
|
fwrite($file, "'". $this->escapeForScript($key).
|
|
|
|
|
"' => '" . $this->escapeForScript($message).
|
|
|
|
|
"',\n");
|
2006-05-28 18:29:42 +00:00
|
|
|
}
|
|
|
|
|
fwrite($file,");\n?>");
|
|
|
|
|
fclose($file);
|
|
|
|
|
rename($filename.'.tmp',$filename);
|
|
|
|
|
}
|
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 ) {
|
|
|
|
|
$this->mCache = $cache;
|
|
|
|
|
} else {
|
|
|
|
|
$this->mCache = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +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
|
|
|
|
|
*/
|
2003-12-14 14:32:19 +00:00
|
|
|
function load() {
|
2006-05-28 18:29:42 +00:00
|
|
|
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 ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): disabled\n" );
|
|
|
|
|
$shownDisabled = true;
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
$this->mDeferred = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'MessageCache::load';
|
2004-08-19 08:44:13 +00:00
|
|
|
wfProfileIn( $fname );
|
2003-12-14 14:32:19 +00:00
|
|
|
$success = true;
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mCache = false;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Try local cache
|
|
|
|
|
wfProfileIn( $fname.'-fromlocal' );
|
|
|
|
|
$hash = $this->mMemc->get( "{$this->mMemcKey}-hash" );
|
|
|
|
|
if ( $hash ) {
|
|
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->loadFromLocal( $hash );
|
|
|
|
|
} else {
|
|
|
|
|
$this->loadFromScript( $hash );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
if ( $this->mCache ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): got from local cache\n" );
|
2005-11-08 11:54:04 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
}
|
|
|
|
|
wfProfileOut( $fname.'-fromlocal' );
|
|
|
|
|
|
|
|
|
|
# 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 ) {
|
2005-11-08 11:54:04 +00:00
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
|
|
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
if ($wgLocalMessageCacheSerialized) {
|
|
|
|
|
$this->saveToLocal( $serialized,$hash );
|
|
|
|
|
} else {
|
|
|
|
|
$this->saveToScript( $this->mCache, $hash );
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-01-05 18:08:29 +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 );
|
|
|
|
|
if ( $success ) {
|
|
|
|
|
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));
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# 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" );
|
2003-12-14 14:32:19 +00:00
|
|
|
} else {
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->mMemc->delete( $this->mMemcKey.'-status' );
|
|
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
$this->unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_array( $this->mCache ) ) {
|
|
|
|
|
wfDebug( "MessageCache::load(): unable to load cache, disabled\n" );
|
|
|
|
|
$this->mDisable = true;
|
|
|
|
|
$this->mCache = false;
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
2004-08-19 08:44:13 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-12-09 05:51:20 +00:00
|
|
|
$this->mDeferred = false;
|
2003-12-14 14:32:19 +00:00
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-10-04 20:36:11 +00:00
|
|
|
* Loads all or main part of cacheable messages from the database
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
|
|
|
|
function loadFromDB() {
|
2007-01-12 10:03:51 +00:00
|
|
|
global $wgMaxMsgCacheEntrySize;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2003-12-14 14:32:19 +00:00
|
|
|
$this->mCache = array();
|
|
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Load titles for all oversized pages in the MediaWiki namespace
|
|
|
|
|
$res = $dbr->select( 'page', 'page_title',
|
|
|
|
|
array(
|
|
|
|
|
'page_len > ' . intval( $wgMaxMsgCacheEntrySize ),
|
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
|
'page_namespace' => NS_MEDIAWIKI,
|
|
|
|
|
),
|
|
|
|
|
__METHOD__ );
|
|
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
$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
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
# Load text for the remaining pages
|
|
|
|
|
$res = $dbr->select( array( 'page', 'revision', 'text' ),
|
|
|
|
|
array( 'page_title', 'old_text', 'old_flags' ),
|
|
|
|
|
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 ) ) {
|
|
|
|
|
$this->mCache[$row->page_title] = ' ' . Revision::getRevisionText( $row );
|
2006-01-07 13:31:29 +00:00
|
|
|
}
|
2007-01-05 18:08:29 +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
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Not really needed anymore
|
|
|
|
|
*/
|
2003-12-14 14:32:19 +00:00
|
|
|
function getKeys() {
|
2006-07-26 07:15:39 +00:00
|
|
|
global $wgContLang;
|
2003-12-14 14:32:19 +00:00
|
|
|
if ( !$this->mKeys ) {
|
2004-01-25 08:49:45 +00:00
|
|
|
$this->mKeys = array();
|
2006-07-26 07:15:39 +00:00
|
|
|
$allMessages = Language::getMessagesFor( 'en' );
|
2006-11-25 17:11:58 +00:00
|
|
|
foreach ( $allMessages as $key => $unused ) {
|
2004-12-22 07:28:11 +00:00
|
|
|
$title = $wgContLang->ucfirst( $key );
|
2004-12-18 08:11:32 +00:00
|
|
|
array_push( $this->mKeys, $title );
|
2004-01-25 08:49:45 +00:00
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
return $this->mKeys;
|
|
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
function replace( $title, $text ) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $wgLocalMessageCache, $wgLocalMessageCacheSerialized, $parserMemc;
|
2007-01-05 18:08:29 +00:00
|
|
|
global $wgMaxMsgCacheEntrySize;
|
2005-11-08 11:54:04 +00:00
|
|
|
|
2007-01-05 18:08:29 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2004-03-20 15:03:26 +00:00
|
|
|
$this->lock();
|
|
|
|
|
$this->load();
|
2006-10-04 09:06:18 +00:00
|
|
|
$parserMemc->delete(wfMemcKey('sidebar'));
|
2004-03-20 15:03:26 +00:00
|
|
|
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 ) {
|
|
|
|
|
$this->mCache[$title] = '!TOO BIG';
|
|
|
|
|
$this->mMemc->set( "$this->mMemcKey:{$title}", ' '.$text, $this->mExpiry );
|
|
|
|
|
} else {
|
|
|
|
|
$this->mCache[$title] = ' ' . $text;
|
|
|
|
|
$this->mMemc->delete( "$this->mMemcKey:{$title}" );
|
|
|
|
|
}
|
2004-05-09 05:12:55 +00:00
|
|
|
$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-11-08 11:54:04 +00:00
|
|
|
# Save to local cache
|
2006-01-07 13:09:30 +00:00
|
|
|
if ( $wgLocalMessageCache !== false ) {
|
2005-11-08 11:54:04 +00:00
|
|
|
$serialized = serialize( $this->mCache );
|
|
|
|
|
$hash = md5( $serialized );
|
|
|
|
|
$this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
|
2006-05-28 18:29:42 +00:00
|
|
|
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
|
|
|
}
|
2004-03-20 15:03:26 +00:00
|
|
|
$this->unlock();
|
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
|
|
|
|
|
*/
|
2003-12-14 14:32:19 +00:00
|
|
|
function lock() {
|
|
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-22 17:24:50 +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
|
|
|
|
2003-12-14 14:32:19 +00:00
|
|
|
function unlock() {
|
|
|
|
|
if ( !$this->mUseCache ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-22 17:24:50 +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
|
|
|
|
|
* @param bool $forContent Get the message from the content language rather than the
|
|
|
|
|
* user language
|
|
|
|
|
* @param bool $isFullKey Specifies whether $key is a two part key "lang/msg".
|
|
|
|
|
*/
|
|
|
|
|
function get( $key, $useDB = true, $forContent = true, $isFullKey = false ) {
|
2006-07-26 08:26:51 +00:00
|
|
|
global $wgContLanguageCode, $wgContLang, $wgLang;
|
2007-01-05 18:08:29 +00:00
|
|
|
if( $forContent ) {
|
2004-11-21 13:56:04 +00:00
|
|
|
$lang =& $wgContLang;
|
|
|
|
|
} else {
|
|
|
|
|
$lang =& $wgLang;
|
2004-09-25 04:15:47 +00:00
|
|
|
}
|
2006-07-26 08:26:51 +00:00
|
|
|
$langcode = $lang->getCode();
|
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
|
|
|
}
|
2004-12-09 05:51:20 +00:00
|
|
|
# If cache initialization was deferred, start it now.
|
2005-08-14 07:21:43 +00:00
|
|
|
if( $this->mDeferred && !$this->mDisable && $useDB ) {
|
2004-12-09 05:51:20 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
2007-01-05 18:08:29 +00:00
|
|
|
$message = $this->getMsgFromNamespace( $title );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
# Try the extension array
|
2007-01-07 15:43:23 +00:00
|
|
|
if( $message === false && isset( $this->mExtensionMessages[$langcode][$lckey] ) ) {
|
|
|
|
|
$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
|
2005-09-11 14:50:47 +00:00
|
|
|
if( $message === false ) {
|
2006-07-26 07:15:39 +00:00
|
|
|
#wfDebug( "Trying language object for message $key\n" );
|
2004-09-20 14:55:25 +00:00
|
|
|
wfSuppressWarnings();
|
2007-01-07 15:43:23 +00:00
|
|
|
$message = $lang->getMessage( $lckey );
|
2004-09-20 14:55:25 +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
|
2007-01-07 15:43:23 +00:00
|
|
|
if( $message === false && strpos( $lckey, '/' ) ) {
|
|
|
|
|
$message = explode( '/', $lckey );
|
2006-08-10 09:10:06 +00:00
|
|
|
if ( $message[1] ) {
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
$message = Language::getMessageFor( $message[0], $message[1] );
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
if ( is_null( $message ) ) {
|
|
|
|
|
$message = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2006-08-07 12:21:06 +00:00
|
|
|
$message = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) ) {
|
2007-01-09 00:21:55 +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
|
|
|
}
|
2004-09-20 14:55:25 +00:00
|
|
|
|
2004-04-05 10:38:40 +00:00
|
|
|
# Replace brace tags
|
|
|
|
|
$message = $this->transform( $message );
|
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
|
|
|
/**
|
|
|
|
|
* Get a message from the MediaWiki namespace, with caching. The key must
|
|
|
|
|
* first be converted to two-part lang/msg form if necessary.
|
|
|
|
|
*
|
|
|
|
|
* @param string $title Message cache key with initial uppercase letter
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2005-03-13 11:50:54 +00:00
|
|
|
# Try the cache
|
2007-01-05 18:08:29 +00:00
|
|
|
if( $this->mUseCache && isset( $this->mCache[$title] ) ) {
|
|
|
|
|
$entry = $this->mCache[$title];
|
|
|
|
|
$type = substr( $entry, 0, 1 );
|
|
|
|
|
if ( $type == ' ' ) {
|
|
|
|
|
return substr( $entry, 1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
}
|
2005-07-07 03:08:58 +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;
|
|
|
|
|
}
|
|
|
|
|
if ( !$this->mDisableTransform && $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();
|
|
|
|
|
if ( $interface ) { $popts->setInterfaceMessage(true); }
|
|
|
|
|
$message = $this->mParser->transformMsg( $message, $popts );
|
|
|
|
|
if ( $interface ) { $popts->setInterfaceMessage(false); }
|
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; }
|
2004-05-03 10:21:26 +00:00
|
|
|
function disableTransform() { $this->mDisableTransform = true; }
|
2004-09-09 22:22:17 +00:00
|
|
|
function enableTransform() { $this->mDisableTransform = false; }
|
2005-11-28 01:14:12 +00:00
|
|
|
function setTransform( $x ) { $this->mDisableTransform = $x; }
|
|
|
|
|
function getTransform() { return $this->mDisableTransform; }
|
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__ );
|
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
|
|
|
/**
|
|
|
|
|
* Get the extension messages for a specific language
|
|
|
|
|
*
|
|
|
|
|
* @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 ) {
|
|
|
|
|
if ( $file ) {
|
|
|
|
|
$this->loadMessagesFile( $file );
|
|
|
|
|
$wgExtensionMessagesFiles[$name] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
*/
|
|
|
|
|
function loadMessagesFile( $filename ) {
|
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
|
|
|
|
|
|
|
|
if ( $messages !== false ) {
|
|
|
|
|
$this->addMessagesByLang( $messages );
|
|
|
|
|
}
|
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
|
|
|
}
|
2003-12-14 14:32:19 +00:00
|
|
|
}
|