Caches for wikis with table prefixes will be lost on upgrade, caches for wikis without table prefixes will be preserved. Custom cache keys in extensions can be migrated at leisure. Extensions which write to core cache keys should be migrated ASAP, as I have done with Special:Makesysop.
global $wgTmpDirectory;
$dir = $wgTmpDirectory;
}
- global $wgDBname, $wgDBprefix;
- $this->mFile = "$dir/mw-cache-$wgDBname";
- if ( $wgDBprefix ) {
- $this->mFile .= '-' . $wgDBprefix;
- }
+ $this->mFile = "$dir/mw-cache-" . wfWikiID();
$this->mFile .= '.db';
$this->mHandler = $handler;
}
* @static
*/
function &getInstance() {
- global $wgDBname, $wgMemc;
+ global $wgMemc;
static $dateFormatter = false;
if ( !$dateFormatter ) {
- $dateFormatter = $wgMemc->get( "$wgDBname:dateformatter" );
+ $dateFormatter = $wgMemc->get( wfMemcKey( 'dateformatter' ) );
if ( !$dateFormatter ) {
$dateFormatter = new DateFormatter;
- $wgMemc->set( "$wgDBname:dateformatter", $dateFormatter, 3600 );
+ $wgMemc->set( wfMemcKey( 'dateformatter' ), $dateFormatter, 3600 );
}
}
return $dateFormatter;
* Returns false on error
*/
function getDiffBody() {
- global $wgMemc, $wgDBname;
+ global $wgMemc;
$fname = 'DifferenceEngine::getDiffBody';
wfProfileIn( $fname );
$key = false;
if ( $this->mOldid && $this->mNewid ) {
// Try cache
- $key = "$wgDBname:diff:oldid:{$this->mOldid}:newid:{$this->mNewid}";
+ $key = wfMemcKey( 'diff', 'oldid', $this->mOldid, 'newid', $this->mNewid );
$difftext = $wgMemc->get( $key );
if ( $difftext ) {
wfIncrStats( 'diff_cache_hit' );
}
private static function lockName() {
- global $wgDBname, $wgDBprefix;
- return "MediaWiki.{$wgDBname}.{$wgDBprefix}FileStore";
+ return 'MediaWiki.' . wfWikiID() . '.FileStore';
}
/**
* log file is specified, (default true)
*/
function wfDebugLog( $logGroup, $text, $public = true ) {
- global $wgDebugLogGroups, $wgDBname;
+ global $wgDebugLogGroups;
if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n";
if( isset( $wgDebugLogGroups[$logGroup] ) ) {
$time = wfTimestamp( TS_DB );
- @error_log( "$time $wgDBname: $text", 3, $wgDebugLogGroups[$logGroup] );
+ $wiki = wfWikiID();
+ @error_log( "$time $wiki: $text", 3, $wgDebugLogGroups[$logGroup] );
} else if ( $public === true ) {
wfDebug( $text, true );
}
}
function wfGetCachedNotice( $name ) {
- global $wgOut, $parserMemc, $wgDBname;
+ global $wgOut, $parserMemc;
$fname = 'wfGetCachedNotice';
wfProfileIn( $fname );
return( false );
}
- $cachedNotice = $parserMemc->get( $wgDBname . ':' . $name );
+ $cachedNotice = $parserMemc->get( wfMemcKey( $name ) );
if( is_array( $cachedNotice ) ) {
if( md5( $notice ) == $cachedNotice['hash'] ) {
$notice = $cachedNotice['html'];
if( $needParse ) {
if( is_object( $wgOut ) ) {
$parsed = $wgOut->parse( $notice );
- $parserMemc->set( $wgDBname . ':' . $name, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
+ $parserMemc->set( wfMemcKey( $name ), array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
$notice = $parsed;
} else {
wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' );
* Increment a statistics counter
*/
function wfIncrStats( $key ) {
- global $wgDBname, $wgMemc;
- $key = "$wgDBname:stats:$key";
+ global $wgMemc;
+ $key = wfMemcKey( 'stats', $key );
if ( is_null( $wgMemc->incr( $key ) ) ) {
$wgMemc->add( $key, 1 );
}
array_reverse(debug_backtrace())));
}
+/**
+ * Get a cache key
+ */
+function wfMemcKey( /*... */ ) {
+ global $wgDBprefix, $wgDBname;
+ $args = func_get_args();
+ if ( $wgDBprefix ) {
+ $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args );
+ } else {
+ $key = $wgDBname . ':' . implode( ':', $args );
+ }
+ return $key;
+}
+
+/**
+ * Get a cache key for a foreign DB
+ */
+function wfForeignMemcKey( $db, $prefix /*, ... */ ) {
+ $args = array_slice( func_get_args(), 2 );
+ if ( $prefix ) {
+ $key = "$db-$prefix:" . implode( ':', $args );
+ } else {
+ $key = $db . ':' . implode( ':', $args );
+ }
+ return $key;
+}
+
+/**
+ * Get an ASCII string identifying this wiki
+ * This is used as a prefix in memcached keys
+ */
+function wfWikiID() {
+ global $wgDBprefix, $wgDBname;
+ if ( $wgDBprefix ) {
+ return "$wgDBname-$wgDBprefix";
+ } else {
+ return $wgDBname;
+ }
+}
+
?>
* Returns an array, first element is the local cache key, second is the shared cache key, if there is one
*/
function getCacheKeys( ) {
- global $wgDBname, $wgUseSharedUploads, $wgSharedUploadDBname, $wgCacheSharedUploads;
+ global $wgUseSharedUploads, $wgSharedUploadDBname, $wgCacheSharedUploads;
$hashedName = md5($this->name);
- $keys = array( "$wgDBname:Image:$hashedName" );
+ $keys = array( wfMemcKey( 'Image', $hashedName ) );
if ( $wgUseSharedUploads && $wgSharedUploadDBname && $wgCacheSharedUploads ) {
- $keys[] = "$wgSharedUploadDBname:Image:$hashedName";
+ $keys[] = wfForeignMemcKey( $wgSharedUploadDBname, false, 'Image', $hashedName );
}
return $keys;
}
}
/* private */ function getKey( $title ) {
- global $wgDBname;
- return $wgDBname.':lc:title:'.$title;
+ return wfMemcKey( 'lc', 'title', $title );
}
/**
* Results are cached for a short time in memcached
*/
function getLagTimes() {
- global $wgDBname;
-
wfProfileIn( __METHOD__ );
$expiry = 5;
$requestRate = 10;
global $wgMemc;
- $times = $wgMemc->get( "$wgDBname:lag_times" );
+ $times = $wgMemc->get( wfMemcKey( 'lag_times' ) );
if ( $times ) {
# Randomly recache with probability rising over $expiry
$elapsed = time() - $times['timestamp'];
# Add a timestamp key so we know when it was cached
$times['timestamp'] = time();
- $wgMemc->set( "$wgDBname:lag_times", $times, $expiry );
+ $wgMemc->set( wfMemcKey( 'lag_times' ), $times, $expiry );
# But don't give the timestamp to the caller
unset($times['timestamp']);
* @todo document
*/
function memsess_key( $id ) {
- global $wgDBname;
- return "$wgDBname:session:$id";
+ return wfMemcKey( 'session', $id );
}
/**
* Try to load the cache from a local file
*/
function loadFromLocal( $hash ) {
- global $wgLocalMessageCache, $wgDBname;
+ global $wgLocalMessageCache;
$this->mCache = false;
if ( $wgLocalMessageCache === false ) {
return;
}
- $filename = "$wgLocalMessageCache/messages-$wgDBname";
+ $filename = "$wgLocalMessageCache/messages-" . wfWikiID();
wfSuppressWarnings();
$file = fopen( $filename, 'r' );
* Save the cache to a local file
*/
function saveToLocal( $serialized, $hash ) {
- global $wgLocalMessageCache, $wgDBname;
+ global $wgLocalMessageCache;
if ( $wgLocalMessageCache === false ) {
return;
}
- $filename = "$wgLocalMessageCache/messages-$wgDBname";
+ $filename = "$wgLocalMessageCache/messages-" . wfWikiID();
$oldUmask = umask( 0 );
wfMkdirParents( $wgLocalMessageCache, 0777 );
umask( $oldUmask );
}
function loadFromScript( $hash ) {
- global $wgLocalMessageCache, $wgDBname;
+ global $wgLocalMessageCache;
if ( $wgLocalMessageCache === false ) {
return;
}
- $filename = "$wgLocalMessageCache/messages-$wgDBname";
+ $filename = "$wgLocalMessageCache/messages-" . wfWikiID();
wfSuppressWarnings();
$file = fopen( $filename, 'r' );
if ($hash!=$localHash) {
return;
}
- require("$wgLocalMessageCache/messages-$wgDBname");
+ require("$wgLocalMessageCache/messages-" . wfWikiID());
}
function saveToScript($array, $hash) {
- global $wgLocalMessageCache, $wgDBname;
+ global $wgLocalMessageCache;
if ( $wgLocalMessageCache === false ) {
return;
}
- $filename = "$wgLocalMessageCache/messages-$wgDBname";
+ $filename = "$wgLocalMessageCache/messages-" . wfWikiID();
$oldUmask = umask( 0 );
wfMkdirParents( $wgLocalMessageCache, 0777 );
umask( $oldUmask );
}
function replace( $title, $text ) {
- global $wgLocalMessageCache, $wgLocalMessageCacheSerialized, $parserMemc, $wgDBname;
+ global $wgLocalMessageCache, $wgLocalMessageCacheSerialized, $parserMemc;
$this->lock();
$this->load();
- $parserMemc->delete("$wgDBname:sidebar");
+ $parserMemc->delete(wfMemcKey('sidebar'));
if ( is_array( $this->mCache ) ) {
$this->mCache[$title] = $text;
$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
* Clear all stored messages. Mainly used after a mass rebuild.
*/
function clear() {
- global $wgLocalMessageCache, $wgDBname;
+ global $wgLocalMessageCache;
if( $this->mUseCache ) {
# Global cache
$this->mMemc->delete( $this->mMemcKey );
}
function getKey( &$article, &$user ) {
- global $wgDBname, $action;
+ global $action;
$hash = $user->getPageRenderingHash();
if( !$article->mTitle->userCanEdit() ) {
// section edit links are suppressed even if the user has them on
}
$pageid = intval( $article->getID() );
$renderkey = (int)($action == 'render');
- $key = "$wgDBname:pcache:idhash:$pageid-$renderkey!$hash$edit";
+ $key = wfMemcKey( 'pcache', 'idhash', "$pageid-$renderkey!$hash$edit" );
return $key;
}
function getFunctionReport() {
global $wgUDPProfilerHost;
global $wgUDPProfilerPort;
- global $wgDBname;
if ( $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
# Less than minimum, ignore
$plength=0;
$packet="";
foreach ($this->mCollated as $entry=>$pfdata) {
- $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", $wgDBname,"-",$pfdata['count'],
+ $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", wfWikiID(),"-",$pfdata['count'],
$pfdata['cpu'],$pfdata['cpu_sq'],$pfdata['real'],$pfdata['real_sq'],$entry);
$length=strlen($pfline);
/* printf("<!-- $pfline -->"); */
$haveProctitle=function_exists("setproctitle");
function wfProfileIn( $fn = '' ) {
- global $hackwhere, $wgDBname, $haveProctitle;
+ global $hackwhere, $haveProctitle;
if ($haveProctitle) {
$hackwhere[] = $fn;
- setproctitle($fn . " [$wgDBname]");
+ setproctitle($fn . ' ['.wfWikiID().']');
}
}
function wfProfileOut( $fn = '' ) {
- global $hackwhere, $wgDBname, $haveProctitle;
+ global $hackwhere, $haveProctitle;
if (!$haveProctitle)
return;
if (count($hackwhere))
array_pop($hackwhere);
if (count($hackwhere))
- setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
+ setproctitle($hackwhere[count($hackwhere)-1] . ' ['.wfWikiID().']');
}
function wfGetProfilingOutput( $s, $e ) {}
function wfProfileClose() {}
*/
function wfProxyCheck() {
global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
- global $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
+ global $wgUseMemCached, $wgMemc, $wgProxyMemcExpiry;
global $wgProxyKey;
if ( !$wgBlockOpenProxies ) {
# Get MemCached key
$skip = false;
if ( $wgUseMemCached ) {
- $mcKey = "$wgDBname:proxy:ip:$ip";
+ $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
$mcValue = $wgMemc->get( $mcKey );
if ( $mcValue ) {
$skip = true;
wfProfileIn( $fname );
// Caching may be beneficial for massive use of external storage
- global $wgRevisionCacheExpiry, $wgMemc, $wgDBname;
- $key = "$wgDBname:revisiontext:textid:" . $this->getTextId();
+ global $wgRevisionCacheExpiry, $wgMemc;
+ $key = wfMemcKey( 'revisiontext', 'textid', $this->getTextId() );
if( $wgRevisionCacheExpiry ) {
$text = $wgMemc->get( $key );
if( is_string( $text ) ) {
$wgOut = new StubObject( 'wgOut', 'OutputPage' );
$wgParser = new StubObject( 'wgParser', 'Parser' );
$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
- array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname) );
+ array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
wfProfileOut( $fname.'-globals' );
wfProfileIn( $fname.'-User' );
* @private
*/
function buildSidebar() {
- global $wgDBname, $parserMemc, $wgEnableSidebarCache;
+ global $parserMemc, $wgEnableSidebarCache;
global $wgLang, $wgContLang;
$fname = 'SkinTemplate::buildSidebar';
wfProfileIn( $fname );
- $key = "{$wgDBname}:sidebar";
+ $key = wfMemcKey( 'sidebar' );
$cacheSidebar = $wgEnableSidebarCache &&
($wgLang->getCode() == $wgContLang->getCode());
global $wgMaxCredits, $wgShowCreditsIfMax;
global $wgPageShowWatchingUsers;
global $wgUseTrackbacks;
- global $wgDBname;
global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
$fname = 'SkinTemplate::outputPage';
}
$newtalks = $wgUser->getNewMessageLinks();
- if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
+ if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
$usertitle = $this->mUser->getUserPage();
$usertalktitle = $usertitle->getTalkPage();
if( !$usertalktitle->equals( $this->mTitle ) ) {
$out = "";
$where = array( 'page_namespace' => $namespace );
- global $wgMemc, $wgDBname;
- $key = "$wgDBname:allpages:ns:$namespace";
+ global $wgMemc;
+ $key = wfMemcKey( 'allpages', 'ns', $namespace );
$lines = $wgMemc->get( $key );
if( !is_array( $lines ) ) {
}
function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
- global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
+ global $messageMemc, $wgFeedCacheTimeout;
global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
if( !isset( $wgFeedClasses[$feedFormat] ) ) {
return false;
}
- $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
- $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
+ $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
+ $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
$feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
' [' . $wgContLanguageCode . ']';
function addNewAccountInternal() {
global $wgUser, $wgOut;
global $wgEnableSorbs, $wgProxyWhitelist;
- global $wgMemc, $wgAccountCreationThrottle, $wgDBname;
+ global $wgMemc, $wgAccountCreationThrottle;
global $wgAuth, $wgMinimalPasswordLength;
// If the user passes an invalid domain, something is fishy
}
if ( $wgAccountCreationThrottle ) {
- $key = $wgDBname.':acctcreate:ip:'.$ip;
+ $key = wfMemcKey( 'acctcreate', 'ip', $ip );
$value = $wgMemc->incr( $key );
if ( !$value ) {
$wgMemc->set( $key, 1, 86400 );
*/
function wfSpecialWatchlist( $par ) {
global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang;
- global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
+ global $wgUseWatchlistCache, $wgWLCacheTimeout;
global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
global $wgEnotifWatchlist;
$fname = 'wfSpecialWatchlist';
}
if ( $wgUseWatchlistCache ) {
- $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
+ $memckey = wfMemcKey( 'watchlist', 'id', $wgUser->getId() );
$cache_s = @$wgMemc->get( $memckey );
if( $cache_s ){
$wgOut->addWikiText( wfMsg('wlsaved') );
* @access public
*/
function getInterwikiLink( $key ) {
- global $wgMemc, $wgDBname, $wgInterwikiExpiry;
+ global $wgMemc, $wgInterwikiExpiry;
global $wgInterwikiCache;
$fname = 'Title::getInterwikiLink';
$key = strtolower( $key );
- $k = $wgDBname.':interwiki:'.$key;
+ $k = wfMemcKey( 'interwiki', $key );
if( array_key_exists( $k, Title::$interwikiCache ) ) {
return Title::$interwikiCache[$k]->iw_url;
}
* @access public
*/
function getInterwikiCached( $key ) {
- global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
+ global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
static $db, $site;
if (!$db)
$db=dba_open($wgInterwikiCache,'r','cdb');
/* Resolve site name */
if ($wgInterwikiScopes>=3 and !$site) {
- $site = dba_fetch("__sites:{$wgDBname}", $db);
+ $site = dba_fetch('__sites:' . wfWikiID(), $db);
if ($site=="")
$site = $wgInterwikiFallbackSite;
}
- $value = dba_fetch("{$wgDBname}:{$key}", $db);
+ $value = dba_fetch( wfMemcKey( $key ), $db);
if ($value=='' and $wgInterwikiScopes>=3) {
/* try site-level */
$value = dba_fetch("_{$site}:{$key}", $db);
$s->iw_url=$url;
$s->iw_local=(int)$local;
}
- Title::$interwikiCache[$wgDBname.':interwiki:'.$key] = $s;
+ Title::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
return $s->iw_url;
}
/**
* @access public
*/
function isLocal() {
- global $wgDBname;
-
if ( $this->mInterwiki != '' ) {
# Make sure key is loaded into cache
$this->getInterwikiLink( $this->mInterwiki );
- $k = $wgDBname.':interwiki:' . $this->mInterwiki;
+ $k = wfMemcKey( 'interwiki', $this->mInterwiki );
return (bool)(Title::$interwikiCache[$k]->iw_local);
} else {
return true;
* @access public
*/
function isTrans() {
- global $wgDBname;
-
if ($this->mInterwiki == '')
return false;
# Make sure key is loaded into cache
$this->getInterwikiLink( $this->mInterwiki );
- $k = $wgDBname.':interwiki:' . $this->mInterwiki;
+ $k = wfMemcKey( 'interwiki', $this->mInterwiki );
return (bool)(Title::$interwikiCache[$k]->iw_trans);
}
return false;
}
- global $wgMemc, $wgDBname, $wgRateLimitLog;
+ global $wgMemc, $wgRateLimitLog;
$fname = 'User::pingLimiter';
wfProfileIn( $fname );
$ip = wfGetIP();
if( isset( $limits['anon'] ) && $id == 0 ) {
- $keys["$wgDBname:limiter:$action:anon"] = $limits['anon'];
+ $keys[wfMemcKey( 'limiter', $action, 'anon' )] = $limits['anon'];
}
if( isset( $limits['user'] ) && $id != 0 ) {
- $keys["$wgDBname:limiter:$action:user:$id"] = $limits['user'];
+ $keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $limits['user'];
}
if( $this->isNewbie() ) {
if( isset( $limits['newbie'] ) && $id != 0 ) {
- $keys["$wgDBname:limiter:$action:user:$id"] = $limits['newbie'];
+ $keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
}
if( isset( $limits['ip'] ) ) {
$keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
if( $count > $max ) {
wfDebug( "$fname: tripped! $key at $count $summary\n" );
if( $wgRateLimitLog ) {
- @error_log( wfTimestamp( TS_MW ) . ' ' . $wgDBname . ': ' . $this->getName() . " tripped $key at $count $summary\n", 3, $wgRateLimitLog );
+ @error_log( wfTimestamp( TS_MW ) . ' ' . wfWikiID() . ': ' . $this->getName() . " tripped $key at $count $summary\n", 3, $wgRateLimitLog );
}
$triggered = true;
} else {
* @static
*/
function loadFromSession() {
- global $wgMemc, $wgDBname, $wgCookiePrefix;
+ global $wgMemc, $wgCookiePrefix;
if ( isset( $_SESSION['wsUserID'] ) ) {
if ( 0 != $_SESSION['wsUserID'] ) {
}
$passwordCorrect = FALSE;
- $user = $wgMemc->get( $key = "$wgDBname:user:id:$sId" );
+ $user = $wgMemc->get( $key = wfMemcKey( 'user', 'id', $sId ) );
if( !is_object( $user ) || $user->mVersion < MW_USER_VERSION ) {
# Expire old serialized objects; they may be corrupt.
$user = false;
# Check memcached separately for anons, who have no
# entire User object stored in there.
if( !$this->mId ) {
- global $wgDBname, $wgMemc;
- $key = "$wgDBname:newtalk:ip:" . $this->getName();
+ global $wgMemc;
+ $key = wfMemcKey( 'newtalk', 'ip', $this->getName() );
$newtalk = $wgMemc->get( $key );
if( is_integer( $newtalk ) ) {
$this->mNewtalk = (bool)$newtalk;
* Return the talk page(s) this user has new messages on.
*/
function getNewMessageLinks() {
- global $wgDBname;
$talks = array();
if (!wfRunHooks('UserRetrieveNewTalks', array(&$this, &$talks)))
return $talks;
return array();
$up = $this->getUserPage();
$utp = $up->getTalkPage();
- return array(array("wiki" => $wgDBname, "link" => $utp->getLocalURL()));
+ return array(array("wiki" => wfWikiID(), "link" => $utp->getLocalURL()));
}
if( $this->isAnon() ) {
// Anons have a separate memcached space, since
// user records aren't kept for them.
- global $wgDBname, $wgMemc;
- $key = "$wgDBname:newtalk:ip:$val";
+ global $wgMemc;
+ $key = wfMemcKey( 'newtalk', 'ip', $val );
$wgMemc->set( $key, $val ? 1 : 0 );
} else {
if( $val ) {
*/
private function clearUserCache() {
if( $this->mId ) {
- global $wgMemc, $wgDBname;
- $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
+ global $wgMemc;
+ $wgMemc->delete( wfMemcKey( 'user', 'id', $this->mId ) );
}
}
# Set the random token (used for persistent authentication)
function setToken( $token = false ) {
- global $wgSecretKey, $wgProxyKey, $wgDBname;
+ global $wgSecretKey, $wgProxyKey;
if ( !$token ) {
if ( $wgSecretKey ) {
$key = $wgSecretKey;
} else {
$key = microtime();
}
- $this->mToken = md5( $key . mt_rand( 0, 0x7fffffff ) . $wgDBname . $this->mId );
+ $this->mToken = md5( $key . mt_rand( 0, 0x7fffffff ) . wfWikiID() . $this->mId );
} else {
$this->mToken = $token;
}
* Returns the memcached key for this item
*/
function watchKey() {
- global $wgDBname;
- return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
+ return wfMemcKey( 'watchlist', 'user', $this->id, 'page', $this->ns, $this->ti );
}
/**
require_once( 'Names.php' );
global $wgInputEncoding, $wgOutputEncoding;
-global $wgDBname, $wgMemc;
/**
* These are always UTF-8, they exist only for backwards compatibility
*/
static function loadLocalisation( $code, $disableCache = false ) {
static $recursionGuard = array();
- global $wgMemc, $wgDBname;
+ global $wgMemc;
if ( !$code ) {
throw new MWException( "Invalid language code requested" );
}
# Try the global cache
- $memcKey = "$wgDBname:localisation:$code";
+ $memcKey = wfMemcKey('localisation', $code );
$cache = $wgMemc->get( $memcKey );
if ( $cache ) {
$expired = false;
$variantfallbacks=array(),
$markup=array(),
$flags = array()) {
- global $wgDBname;
global $wgLegalTitleChars;
$this->mLangObj = $langobj;
$this->mMainLanguageCode = $maincode;
$this->mVariants = $variants;
$this->mVariantFallbacks = $variantfallbacks;
- $this->mCacheKey = $wgDBname . ":conversiontables";
+ $this->mCacheKey = wfMemcKey( 'conversiontables' );
$m = array('begin'=>'-{', 'flagsep'=>'|', 'codesep'=>':',
'varsep'=>';', 'end'=>'}-');
$this->mMarkup = array_merge($m, $markup);
* @access private
*/
function log( $message ) {
- global $wgDBname;
- echo $wgDBname . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n";
+ echo wfWikiID() . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n";
flush();
}
function initialiseMessagesReal( $overwrite = false, $messageArray = false, $outputCallback = false ) {
global $wgContLang, $wgScript, $wgServer, $wgLanguageCode;
global $wgOut, $wgArticle, $wgUser;
- global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
+ global $wgMessageCache, $wgMemc, $wgUseMemCached;
# Initialise $wgOut and $wgUser for a command line script
$wgOut->disable();
array( 'rev_page' => $pageId ),
$fname );
if( !$latestTime ) {
- echo "$wgDBname $pageId [[$name]] can't find latest rev time?!\n";
+ echo wfWikiID()." $pageId [[$name]] can't find latest rev time?!\n";
continue;
}
$revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
if( is_null( $revision ) ) {
- echo "$wgDBname $pageId [[$name]] latest time $latestTime, can't find revision id\n";
+ echo wfWikiID()." $pageId [[$name]] latest time $latestTime, can't find revision id\n";
continue;
}
$id = $revision->getId();
- echo "$wgDBname $pageId [[$name]] latest time $latestTime, rev id $id\n";
+ echo wfWikiID()." $pageId [[$name]] latest time $latestTime, rev id $id\n";
if( $fixit ) {
$article = new Article( $title );
$article->updateRevisionOn( $dbw, $revision );
$revrate = '-';
$etats = '-';
}
- global $wgDBname;
$this->progress( sprintf( "%s: %s %d pages (%0.3f/sec), %d revs (%0.3f/sec), ETA %s [max %d]",
- $now, $wgDBname, $this->pageCount, $rate, $this->revCount, $revrate, $etats, $this->maxCount ) );
+ $now, wfWikiID(), $this->pageCount, $rate, $this->revCount, $revrate, $etats, $this->maxCount ) );
}
}
$this->log = fopen( '/home/wikipedia/logs/checkUsernames.log', 'at' );
}
function main() {
- global $wgDBname;
$fname = 'checkUsernames::main';
$dbr =& wfGetDB( DB_SLAVE );
$fname
);
- #fwrite( $this->stderr, "Checking $wgDBname\n" );
while ( $row = $dbr->fetchObject( $res ) ) {
if ( ! User::isValidUserName( $row->user_name ) ) {
- $out = sprintf( "%s: %6d: '%s'\n", $wgDBname, $row->user_id, $row->user_name );
+ $out = sprintf( "%s: %6d: '%s'\n", wfWikiID(), $row->user_id, $row->user_name );
fwrite( $this->stderr, $out );
fwrite( $this->log, $out );
}
}
function checkDupes( $fixthem = false, $indexonly = false ) {
- global $wgDBname;
$dbw =& wfGetDB( DB_MASTER );
if( $dbw->indexExists( 'cur', 'name_title' ) &&
$dbw->indexUnique( 'cur', 'name_title' ) ) {
- echo "$wgDBname: cur table has the current unique index; no duplicate entries.\n";
+ echo wfWikiID().": cur table has the current unique index; no duplicate entries.\n";
} elseif( $dbw->indexExists( 'cur', 'name_title_dup_prevention' ) ) {
- echo "$wgDBname: cur table has a temporary name_title_dup_prevention unique index; no duplicate entries.\n";
+ echo wfWikiID().": cur table has a temporary name_title_dup_prevention unique index; no duplicate entries.\n";
} else {
- echo "$wgDBname: cur table has the old non-unique index and may have duplicate entries.\n";
+ echo wfWikiID().": cur table has the old non-unique index and may have duplicate entries.\n";
if( !$indexonly ) {
fixDupes( $fixthem );
}
}
}
-?>
\ No newline at end of file
+?>
$estimatedTotalTime = $delta / $portion;
$eta = $this->startTime + $estimatedTotalTime;
- global $wgDBname;
printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
- $wgDBname,
+ wfWikiID(),
wfTimestamp( TS_DB, intval( $now ) ),
$portion * 100.0,
$this->table,
}
-?>
\ No newline at end of file
+?>
$estimatedTotalTime = $delta / $portion;
$eta = $this->startTime + $estimatedTotalTime;
- global $wgDBname;
printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
- $wgDBname,
+ wfWikiID(),
wfTimestamp( TS_DB, intval( $now ) ),
$portion * 100.0,
$this->table,
$username = $args[0];
$password = $args[1];
-global $wgDBname;
-echo( "{$wgDBname}: Creating and promoting User:{$username}..." );
+echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
# Validate username and check it doesn't exist
$user = User::newFromName( $username );
echo( "done.\n" );
-?>
\ No newline at end of file
+?>
}
function main() {
- global $wgMemc, $wgDBname;
+ global $wgMemc;
$fname = 'DeleteImageCache::main';
ini_set( 'display_errors', false );
while ( $row = $dbr->fetchObject( $res ) ) {
if ($i % $this->report == 0)
- printf("%s: %13s done (%s)\n", $wgDBname, "$i/$total", wfPercent( $i / $total * 100 ));
+ printf("%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ));
$md5 = md5( $row->img_name );
- $wgMemc->delete( "$wgDBname:Image:$md5" );
+ $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
if ($this->sleep != 0)
usleep( $this->sleep );
exit(1);
}
-echo "Deleting revision(s) " . implode( ',', $args ) . " from $wgDBname...\n";
+echo "Deleting revision(s) " . implode( ',', $args ) . " from ".wfWikiID()."...\n";
$affected = 0;
foreach ( $args as $revID ) {
}
function getRebuildInterwikiDump() {
- global $langlist, $languageAliases, $prefixRewrites, $wgDBname;
+ global $langlist, $languageAliases, $prefixRewrites;
# Multi-language sites
# db suffix => db suffix, iw prefix, hostname
$etats = '-';
$fetchrate = '-';
}
- global $wgDBname;
$this->progress( sprintf( "%s: %s %d pages (%0.3f/sec), %d revs (%0.3f/sec), %0.1f%% prefetched, ETA %s [max %d]",
- $now, $wgDBname, $this->pageCount, $rate, $this->revCount, $revrate, $fetchrate, $etats, $this->maxCount ) );
+ $now, wfWikiID(), $this->pageCount, $rate, $this->revCount, $revrate, $fetchrate, $etats, $this->maxCount ) );
}
}
* @param bool $compress Whether to compress the sitemap files
*/
function GenerateSitemap( $fspath, $path, $compress ) {
- global $wgDBname, $wgScriptPath;
+ global $wgScriptPath;
$this->url_limit = 50000;
$this->size_limit = pow( 2, 20 ) * 10;
$this->dbr =& wfGetDB( DB_SLAVE );
$this->generateNamespaces();
$this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() );
- $this->findex = fopen( "{$this->fspath}sitemap-index-$wgDBname.xml", 'wb' );
+ $this->findex = fopen( "{$this->fspath}sitemap-index-" . wfWikiID() . ".xml", 'wb' );
}
/**
* @access public
*/
function main() {
- global $wgDBname, $wgContLang;
+ global $wgContLang;
fwrite( $this->findex, $this->openIndex() );
* @return string
*/
function sitemapFilename( $namespace, $count ) {
- global $wgDBname;
-
$ext = $this->compress ? '.gz' : '';
-
- return "sitemap-$wgDBname-NS_$namespace-$count.xml$ext";
+ return "sitemap-".wfWikiID()."-NS_$namespace-$count.xml$ext";
}
/**
// Fill in the new image info fields
$info = $this->imageInfo( $row->img_name );
- global $wgMemc, $wgDBname;
- $key = $wgDBname . ":Image:" . md5( $row->img_name );
+ global $wgMemc;
+ $key = wfMemcKey( "Image", md5( $row->img_name ) );
$wgMemc->delete( $key );
return array(
// Load the current value from the master
$count = $dbw->selectField( 'site_stats', 'ss_images' );
-echo "$wgDBname: forcing ss_images to $count\n";
+echo wfWikiID().": forcing ss_images to $count\n";
// First set to NULL so that it changes on the master
$dbw->update( 'site_stats',
array( 'ss_images' => $count ),
array( 'ss_row_id' => 1 ) );
-?>
\ No newline at end of file
+?>
require_once('commandLine.inc');
print "Requests\n";
-$session = intval($wgMemc->get("$wgDBname:stats:request_with_session"));
-$noSession = intval($wgMemc->get("$wgDBname:stats:request_without_session"));
+$session = intval($wgMemc->get(wfMemcKey('stats','request_with_session')));
+$noSession = intval($wgMemc->get(wfMemcKey('stats','request_without_session')));
$total = $session + $noSession;
printf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 );
printf( "without session: %-10d %6.2f%%\n", $noSession, $noSession/$total*100 );
print "\nParser cache\n";
-$hits = intval($wgMemc->get("$wgDBname:stats:pcache_hit"));
-$invalid = intval($wgMemc->get("$wgDBname:stats:pcache_miss_invalid"));
-$expired = intval($wgMemc->get("$wgDBname:stats:pcache_miss_expired"));
-$absent = intval($wgMemc->get("$wgDBname:stats:pcache_miss_absent"));
-$stub = intval($wgMemc->get("$wgDBname:stats:pcache_miss_stub"));
+$hits = intval($wgMemc->get(wfMemcKey('stats','pcache_hit')));
+$invalid = intval($wgMemc->get(wfMemcKey('stats','pcache_miss_invalid')));
+$expired = intval($wgMemc->get(wfMemcKey('stats','pcache_miss_expired')));
+$absent = intval($wgMemc->get(wfMemcKey('stats','pcache_miss_absent')));
+$stub = intval($wgMemc->get(wfMemcKey('stats','pcache_miss_stub')));
$total = $hits + $invalid + $expired + $absent + $stub;
printf( "hits: %-10d %6.2f%%\n", $hits, $hits/$total*100 );
printf( "invalid: %-10d %6.2f%%\n", $invalid, $invalid/$total*100 );
printf( "stub threshold: %-10d %6.2f%%\n", $stub, $stub/$total*100 );
printf( "total: %-10d %6.2f%%\n", $total, 100 );
-$hits = intval($wgMemc->get("$wgDBname:stats:image_cache_hit"));
-$misses = intval($wgMemc->get("$wgDBname:stats:image_cache_miss"));
-$updates = intval($wgMemc->get("$wgDBname:stats:image_cache_update"));
+$hits = intval($wgMemc->get(wfMemcKey('stats','image_cache_hit')));
+$misses = intval($wgMemc->get(wfMemcKey('stats','image_cache_miss')));
+$updates = intval($wgMemc->get(wfMemcKey('stats','image_cache_update')));
$total = $hits + $misses;
print("\nImage cache\n");
printf( "hits: %-10d %6.2f%%\n", $hits, $hits/$total*100 );
printf( "misses: %-10d %6.2f%%\n", $misses, $misses/$total*100 );
printf( "updates: %-10d\n", $updates );
-$hits = intval($wgMemc->get("$wgDBname:stats:diff_cache_hit"));
-$misses = intval($wgMemc->get("$wgDBname:stats:diff_cache_miss"));
-$uncacheable = intval($wgMemc->get("$wgDBname:stats:diff_uncacheable"));
+$hits = intval($wgMemc->get(wfMemcKey('stats','diff_cache_hit')));
+$misses = intval($wgMemc->get(wfMemcKey('stats','diff_cache_miss')));
+$uncacheable = intval($wgMemc->get(wfMemcKey('stats','diff_uncacheable')));
$total = $hits + $misses + $uncacheable;
print("\nDiff cache\n");
printf( "hits: %-10d %6.2f%%\n", $hits, $hits/$total*100 );
require_once( "updaters.inc" );
$wgTitle = Title::newFromText( "MediaWiki database updater" );
$dbclass = 'Database' . ucfirst( $wgDBtype ) ;
-$dbc = new $dbclass;
echo( "MediaWiki {$wgVersion} Updater\n\n" );
# Attempt to connect to the database as a privileged user
# This will vomit up an error if there are permissions problems
-$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
+$wgDatabase = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
if( !$wgDatabase->isOpen() ) {
# Appears to have failed
exit();
}
-print "Going to run database updates for $wgDBname\n";
+print "Going to run database updates for ".wfWikiID()."\n";
print "Depending on the size of your database this may take a while!\n";
if( !isset( $options['quick'] ) ) {
* @return bool
*/
function checkDupes( $doDelete = false ) {
- global $wgDBname;
-
if( $this->hasUniqueIndex() ) {
- echo "$wgDBname already has a unique index on its user table.\n";
+ echo wfWikiID()." already has a unique index on its user table.\n";
return true;
}
$dupes = $this->getDupes();
$count = count( $dupes );
- echo "Found $count accounts with duplicate records on $wgDBname.\n";
+ echo "Found $count accounts with duplicate records on ".wfWikiID().".\n";
$this->trimmed = 0;
$this->reassigned = 0;
$this->failed = 0;
if( $this->trimmed > 0 ) {
if( $doDelete ) {
- echo "$this->trimmed duplicate user records were deleted from $wgDBname.\n";
+ echo "$this->trimmed duplicate user records were deleted from ".wfWikiID().".\n";
} else {
- echo "$this->trimmed duplicate user accounts were found on $wgDBname which can be removed safely.\n";
+ echo "$this->trimmed duplicate user accounts were found on ".wfWikiID()." which can be removed safely.\n";
}
}
}
-?>
\ No newline at end of file
+?>