From e174a4ddfb96feee0a8305c60aade97c0ee30d3c Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 4 Oct 2006 09:06:18 +0000 Subject: [PATCH] Abolished $wgDBname as a unique wiki identifier, it doesn't work with the new-fangled feature we call "table prefixes". Instead use wfWikiID() for an identifier containing the DB name and the prefix if there is one, and wfMemcKey() for cache key construction. 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. --- includes/BagOStuff.php | 6 +-- includes/DateFormatter.php | 6 +-- includes/DifferenceEngine.php | 4 +- includes/FileStore.php | 3 +- includes/GlobalFunctions.php | 55 ++++++++++++++++++++++++---- includes/Image.php | 6 +-- includes/LinkCache.php | 3 +- includes/LoadBalancer.php | 6 +-- includes/MemcachedSessions.php | 3 +- includes/MessageCache.php | 24 ++++++------ includes/ParserCache.php | 4 +- includes/ProfilerSimpleUDP.php | 3 +- includes/ProfilerStub.php | 8 ++-- includes/ProxyTools.php | 4 +- includes/Revision.php | 4 +- includes/Setup.php | 2 +- includes/Skin.php | 4 +- includes/SkinTemplate.php | 3 +- includes/SpecialAllpages.php | 4 +- includes/SpecialRecentchanges.php | 6 +-- includes/SpecialUserlogin.php | 4 +- includes/SpecialWatchlist.php | 4 +- includes/Title.php | 20 ++++------ includes/User.php | 33 ++++++++--------- includes/WatchedItem.php | 3 +- languages/Language.php | 5 +-- languages/LanguageConverter.php | 3 +- maintenance/FiveUpgrade.inc | 3 +- maintenance/InitialiseMessages.inc | 2 +- maintenance/attachLatest.php | 6 +-- maintenance/backup.inc | 3 +- maintenance/checkUsernames.php | 4 +- maintenance/cleanupDupes.inc | 9 ++--- maintenance/cleanupTable.inc | 5 +-- maintenance/cleanupWatchlist.php | 3 +- maintenance/createAndPromote.php | 5 +-- maintenance/deleteImageMemcached.php | 6 +-- maintenance/deleteRevision.php | 2 +- maintenance/dumpInterwiki.inc | 2 +- maintenance/dumpTextPass.php | 3 +- maintenance/generateSitemap.php | 11 ++---- maintenance/rebuildImages.php | 4 +- maintenance/refreshImageCount.php | 4 +- maintenance/stats.php | 26 ++++++------- maintenance/update.php | 5 +-- maintenance/userDupes.inc | 12 +++--- 46 files changed, 176 insertions(+), 169 deletions(-) diff --git a/includes/BagOStuff.php b/includes/BagOStuff.php index 31d357cc4d..1dc93a2fb0 100644 --- a/includes/BagOStuff.php +++ b/includes/BagOStuff.php @@ -553,11 +553,7 @@ class DBABagOStuff extends BagOStuff { 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; } diff --git a/includes/DateFormatter.php b/includes/DateFormatter.php index 99d8be71ed..dc077fdc60 100644 --- a/includes/DateFormatter.php +++ b/includes/DateFormatter.php @@ -105,13 +105,13 @@ class DateFormatter * @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; diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 21ac558b3c..448bcb5d01 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -297,7 +297,7 @@ CONTROL; * Returns false on error */ function getDiffBody() { - global $wgMemc, $wgDBname; + global $wgMemc; $fname = 'DifferenceEngine::getDiffBody'; wfProfileIn( $fname ); @@ -305,7 +305,7 @@ CONTROL; $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' ); diff --git a/includes/FileStore.php b/includes/FileStore.php index 69e4be8a1f..35ebd55433 100644 --- a/includes/FileStore.php +++ b/includes/FileStore.php @@ -62,8 +62,7 @@ class FileStore { } private static function lockName() { - global $wgDBname, $wgDBprefix; - return "MediaWiki.{$wgDBname}.{$wgDBprefix}FileStore"; + return 'MediaWiki.' . wfWikiID() . '.FileStore'; } /** diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index fbd1f317e8..623f9d3b50 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -189,11 +189,12 @@ function wfDebug( $text, $logonly = false ) { * 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 ); } @@ -1377,7 +1378,7 @@ function swap( &$x, &$y ) { } function wfGetCachedNotice( $name ) { - global $wgOut, $parserMemc, $wgDBname; + global $wgOut, $parserMemc; $fname = 'wfGetCachedNotice'; wfProfileIn( $fname ); @@ -1388,7 +1389,7 @@ function wfGetCachedNotice( $name ) { return( false ); } - $cachedNotice = $parserMemc->get( $wgDBname . ':' . $name ); + $cachedNotice = $parserMemc->get( wfMemcKey( $name ) ); if( is_array( $cachedNotice ) ) { if( md5( $notice ) == $cachedNotice['hash'] ) { $notice = $cachedNotice['html']; @@ -1402,7 +1403,7 @@ function wfGetCachedNotice( $name ) { 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' ); @@ -1541,8 +1542,8 @@ function wfMkdirParents( $fullDir, $mode = 0777 ) { * 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 ); } @@ -2022,4 +2023,44 @@ function wfGetAllCallers() { 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; + } +} + ?> diff --git a/includes/Image.php b/includes/Image.php index c66c6bbd85..0754f67ac1 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -121,12 +121,12 @@ class Image * 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; } diff --git a/includes/LinkCache.php b/includes/LinkCache.php index a7cbe47ee9..8e56225ba0 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -37,8 +37,7 @@ class LinkCache { } /* private */ function getKey( $title ) { - global $wgDBname; - return $wgDBname.':lc:title:'.$title; + return wfMemcKey( 'lc', 'title', $title ); } /** diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index a374c6b6a4..3e81aea941 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -599,14 +599,12 @@ class LoadBalancer { * 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']; @@ -634,7 +632,7 @@ class LoadBalancer { # 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']); diff --git a/includes/MemcachedSessions.php b/includes/MemcachedSessions.php index af49109ce9..e2dc52ca7f 100644 --- a/includes/MemcachedSessions.php +++ b/includes/MemcachedSessions.php @@ -13,8 +13,7 @@ * @todo document */ function memsess_key( $id ) { - global $wgDBname; - return "$wgDBname:session:$id"; + return wfMemcKey( 'session', $id ); } /** diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 3859e5f3bd..aa1fa1f48e 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -58,14 +58,14 @@ class MessageCache { * 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' ); @@ -88,13 +88,13 @@ class MessageCache { * 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 ); @@ -111,12 +111,12 @@ class MessageCache { } 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' ); @@ -129,16 +129,16 @@ class MessageCache { 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 ); @@ -361,11 +361,11 @@ class MessageCache { } 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 ); @@ -617,7 +617,7 @@ class MessageCache { * 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 ); diff --git a/includes/ParserCache.php b/includes/ParserCache.php index 612790a38b..1f2e2aaf09 100644 --- a/includes/ParserCache.php +++ b/includes/ParserCache.php @@ -33,7 +33,7 @@ class ParserCache { } 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 @@ -43,7 +43,7 @@ class ParserCache { } $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; } diff --git a/includes/ProfilerSimpleUDP.php b/includes/ProfilerSimpleUDP.php index 1eb2c5f01f..e04905129d 100644 --- a/includes/ProfilerSimpleUDP.php +++ b/includes/ProfilerSimpleUDP.php @@ -10,7 +10,6 @@ class ProfilerSimpleUDP extends ProfilerSimple { function getFunctionReport() { global $wgUDPProfilerHost; global $wgUDPProfilerPort; - global $wgDBname; if ( $this->mCollated['-total']['real'] < $this->mMinimumTime ) { # Less than minimum, ignore @@ -22,7 +21,7 @@ class ProfilerSimpleUDP extends ProfilerSimple { $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(""); */ diff --git a/includes/ProfilerStub.php b/includes/ProfilerStub.php index 4cf0aa4494..b4f8caf23b 100644 --- a/includes/ProfilerStub.php +++ b/includes/ProfilerStub.php @@ -4,20 +4,20 @@ $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() {} diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index 09a1f8197e..7974c88273 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -75,7 +75,7 @@ function wfGetIP() { */ function wfProxyCheck() { global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath; - global $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry; + global $wgUseMemCached, $wgMemc, $wgProxyMemcExpiry; global $wgProxyKey; if ( !$wgBlockOpenProxies ) { @@ -87,7 +87,7 @@ function wfProxyCheck() { # 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; diff --git a/includes/Revision.php b/includes/Revision.php index e8d802d692..bd68e05a80 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -685,8 +685,8 @@ class Revision { 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 ) ) { diff --git a/includes/Setup.php b/includes/Setup.php index d529fea995..8fe9ef71ac 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -145,7 +145,7 @@ $wgLang = new StubUserLang; $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' ); diff --git a/includes/Skin.php b/includes/Skin.php index 074cf2b11e..1c92ccdaf1 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1509,14 +1509,14 @@ END; * @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()); diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index c796cc72ab..482680e632 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -138,7 +138,6 @@ class SkinTemplate extends Skin { global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks; - global $wgDBname; global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames; $fname = 'SkinTemplate::outputPage'; @@ -284,7 +283,7 @@ class SkinTemplate extends Skin { } $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 ) ) { diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php index 08cea926e9..345c48e606 100644 --- a/includes/SpecialAllpages.php +++ b/includes/SpecialAllpages.php @@ -94,8 +94,8 @@ function showToplevel ( $namespace = NS_MAIN, $including = false ) { $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 ) ) { diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index d3d9453f6d..a85e194c42 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -319,7 +319,7 @@ function rcFilterByCategories ( &$rows , $categories , $any ) { } function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) { - global $messageMemc, $wgDBname, $wgFeedCacheTimeout; + global $messageMemc, $wgFeedCacheTimeout; global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode; if( !isset( $wgFeedClasses[$feedFormat] ) ) { @@ -327,8 +327,8 @@ function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) { 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 . ']'; diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index cc7339f87b..574579cc8b 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -195,7 +195,7 @@ class LoginForm { 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 @@ -258,7 +258,7 @@ class LoginForm { } if ( $wgAccountCreationThrottle ) { - $key = $wgDBname.':acctcreate:ip:'.$ip; + $key = wfMemcKey( 'acctcreate', 'ip', $ip ); $value = $wgMemc->incr( $key ); if ( !$value ) { $wgMemc->set( $key, 1, 86400 ); diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index b24d1e3738..3825675b61 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -17,7 +17,7 @@ require_once( 'SpecialRecentchanges.php' ); */ 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'; @@ -103,7 +103,7 @@ function wfSpecialWatchlist( $par ) { } 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') ); diff --git a/includes/Title.php b/includes/Title.php index cf79780f2c..0e86063ee4 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -392,13 +392,13 @@ class Title { * @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; } @@ -445,18 +445,18 @@ class Title { * @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); @@ -476,7 +476,7 @@ class Title { $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; } /** @@ -488,12 +488,10 @@ class Title { * @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; @@ -508,13 +506,11 @@ class Title { * @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); } diff --git a/includes/User.php b/includes/User.php index 7dc4689731..6df9e0c2ce 100644 --- a/includes/User.php +++ b/includes/User.php @@ -665,7 +665,7 @@ class User { return false; } - global $wgMemc, $wgDBname, $wgRateLimitLog; + global $wgMemc, $wgRateLimitLog; $fname = 'User::pingLimiter'; wfProfileIn( $fname ); @@ -675,15 +675,15 @@ class User { $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']; @@ -703,7 +703,7 @@ class User { 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 { @@ -783,7 +783,7 @@ class User { * @static */ function loadFromSession() { - global $wgMemc, $wgDBname, $wgCookiePrefix; + global $wgMemc, $wgCookiePrefix; if ( isset( $_SESSION['wsUserID'] ) ) { if ( 0 != $_SESSION['wsUserID'] ) { @@ -807,7 +807,7 @@ class User { } $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; @@ -958,8 +958,8 @@ class User { # 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; @@ -979,7 +979,6 @@ class User { * 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; @@ -988,7 +987,7 @@ class User { return array(); $up = $this->getUserPage(); $utp = $up->getTalkPage(); - return array(array("wiki" => $wgDBname, "link" => $utp->getLocalURL())); + return array(array("wiki" => wfWikiID(), "link" => $utp->getLocalURL())); } @@ -1083,8 +1082,8 @@ class User { 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 ) { @@ -1115,8 +1114,8 @@ class User { */ 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 ) ); } } @@ -1164,7 +1163,7 @@ class User { # 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; @@ -1173,7 +1172,7 @@ class User { } 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; } diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index 3885bb985a..788774fb20 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -35,8 +35,7 @@ class WatchedItem { * 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 ); } /** diff --git a/languages/Language.php b/languages/Language.php index 6b984eb4d4..454d60e147 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -26,7 +26,6 @@ global $wgLanguageNames; require_once( 'Names.php' ); global $wgInputEncoding, $wgOutputEncoding; -global $wgDBname, $wgMemc; /** * These are always UTF-8, they exist only for backwards compatibility @@ -1462,7 +1461,7 @@ class Language { */ static function loadLocalisation( $code, $disableCache = false ) { static $recursionGuard = array(); - global $wgMemc, $wgDBname; + global $wgMemc; if ( !$code ) { throw new MWException( "Invalid language code requested" ); @@ -1486,7 +1485,7 @@ class Language { } # Try the global cache - $memcKey = "$wgDBname:localisation:$code"; + $memcKey = wfMemcKey('localisation', $code ); $cache = $wgMemc->get( $memcKey ); if ( $cache ) { $expired = false; diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index f24332e61b..a949ad4e0b 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -38,13 +38,12 @@ class LanguageConverter { $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); diff --git a/maintenance/FiveUpgrade.inc b/maintenance/FiveUpgrade.inc index c9fe2eed18..4bbf07334a 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/FiveUpgrade.inc @@ -159,8 +159,7 @@ class FiveUpgrade { * @access private */ function log( $message ) { - global $wgDBname; - echo $wgDBname . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n"; + echo wfWikiID() . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n"; flush(); } diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index ab0f3c597c..22e26b946b 100644 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -72,7 +72,7 @@ function initialiseMessages( $overwrite = false, $messageArray = false, $outputC 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(); diff --git a/maintenance/attachLatest.php b/maintenance/attachLatest.php index 024a4fac2b..f4c11c0193 100644 --- a/maintenance/attachLatest.php +++ b/maintenance/attachLatest.php @@ -47,17 +47,17 @@ while( $row = $dbw->fetchObject( $result ) ) { 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 ); diff --git a/maintenance/backup.inc b/maintenance/backup.inc index 734a13272d..d40636a6f3 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -262,9 +262,8 @@ class BackupDumper { $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 ) ); } } diff --git a/maintenance/checkUsernames.php b/maintenance/checkUsernames.php index b577ebc66f..4c0ecdce02 100644 --- a/maintenance/checkUsernames.php +++ b/maintenance/checkUsernames.php @@ -10,7 +10,6 @@ class checkUsernames { $this->log = fopen( '/home/wikipedia/logs/checkUsernames.log', 'at' ); } function main() { - global $wgDBname; $fname = 'checkUsernames::main'; $dbr =& wfGetDB( DB_SLAVE ); @@ -21,10 +20,9 @@ class checkUsernames { $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 ); } diff --git a/maintenance/cleanupDupes.inc b/maintenance/cleanupDupes.inc index 18daab08ed..5db6bb3941 100644 --- a/maintenance/cleanupDupes.inc +++ b/maintenance/cleanupDupes.inc @@ -113,19 +113,18 @@ END } 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 +?> diff --git a/maintenance/cleanupTable.inc b/maintenance/cleanupTable.inc index 265eca9768..cc551bce9c 100644 --- a/maintenance/cleanupTable.inc +++ b/maintenance/cleanupTable.inc @@ -44,9 +44,8 @@ abstract class TableCleanup extends FiveUpgrade { $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, @@ -84,4 +83,4 @@ abstract class TableCleanup extends FiveUpgrade { } -?> \ No newline at end of file +?> diff --git a/maintenance/cleanupWatchlist.php b/maintenance/cleanupWatchlist.php index d2925db387..027859a435 100644 --- a/maintenance/cleanupWatchlist.php +++ b/maintenance/cleanupWatchlist.php @@ -70,9 +70,8 @@ class WatchlistCleanup extends FiveUpgrade { $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, diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index df29c114fb..43ddcdd1cd 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -18,8 +18,7 @@ if( !count( $args ) == 2 ) { $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 ); @@ -45,4 +44,4 @@ $ssu->doUpdate(); echo( "done.\n" ); -?> \ No newline at end of file +?> diff --git a/maintenance/deleteImageMemcached.php b/maintenance/deleteImageMemcached.php index 4e17d21eba..6af0e3a9fa 100644 --- a/maintenance/deleteImageMemcached.php +++ b/maintenance/deleteImageMemcached.php @@ -14,7 +14,7 @@ class DeleteImageCache { } function main() { - global $wgMemc, $wgDBname; + global $wgMemc; $fname = 'DeleteImageCache::main'; ini_set( 'display_errors', false ); @@ -32,9 +32,9 @@ class DeleteImageCache { 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 ); diff --git a/maintenance/deleteRevision.php b/maintenance/deleteRevision.php index e7d005b6a2..eb65e23406 100644 --- a/maintenance/deleteRevision.php +++ b/maintenance/deleteRevision.php @@ -8,7 +8,7 @@ if ( count( $args ) == 0 ) { 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 ) { diff --git a/maintenance/dumpInterwiki.inc b/maintenance/dumpInterwiki.inc index f7a56ee7af..2039f2df4b 100644 --- a/maintenance/dumpInterwiki.inc +++ b/maintenance/dumpInterwiki.inc @@ -31,7 +31,7 @@ class Site { } function getRebuildInterwikiDump() { - global $langlist, $languageAliases, $prefixRewrites, $wgDBname; + global $langlist, $languageAliases, $prefixRewrites; # Multi-language sites # db suffix => db suffix, iw prefix, hostname diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index b6cbc01d2b..8c1563ad03 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -190,9 +190,8 @@ class TextPassDumper extends BackupDumper { $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 ) ); } } diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index 2cf8312a95..a0b6979d0d 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -145,7 +145,7 @@ class GenerateSitemap { * @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; @@ -157,7 +157,7 @@ class GenerateSitemap { $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' ); } /** @@ -232,7 +232,7 @@ class GenerateSitemap { * @access public */ function main() { - global $wgDBname, $wgContLang; + global $wgContLang; fwrite( $this->findex, $this->openIndex() ); @@ -314,11 +314,8 @@ class GenerateSitemap { * @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"; } /** diff --git a/maintenance/rebuildImages.php b/maintenance/rebuildImages.php index 45477097a8..38b89a4805 100644 --- a/maintenance/rebuildImages.php +++ b/maintenance/rebuildImages.php @@ -125,8 +125,8 @@ class ImageBuilder extends FiveUpgrade { // 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( diff --git a/maintenance/refreshImageCount.php b/maintenance/refreshImageCount.php index 15ce2b91a0..88ac3c52c3 100644 --- a/maintenance/refreshImageCount.php +++ b/maintenance/refreshImageCount.php @@ -10,7 +10,7 @@ $dbw =& wfGetDB( DB_MASTER ); // 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', @@ -22,4 +22,4 @@ $dbw->update( 'site_stats', array( 'ss_images' => $count ), array( 'ss_row_id' => 1 ) ); -?> \ No newline at end of file +?> diff --git a/maintenance/stats.php b/maintenance/stats.php index 8ebc382305..bb19e67152 100644 --- a/maintenance/stats.php +++ b/maintenance/stats.php @@ -2,8 +2,8 @@ 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 ); @@ -11,11 +11,11 @@ printf( "total: %-10d %6.2f%%\n", $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 ); @@ -24,18 +24,18 @@ printf( "absent: %-10d %6.2f%%\n", $absent, $absent/$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 ); diff --git a/maintenance/update.php b/maintenance/update.php index 1d24aa8fea..d2dcbf92bb 100644 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -15,7 +15,6 @@ require_once( "commandLine.inc" ); require_once( "updaters.inc" ); $wgTitle = Title::newFromText( "MediaWiki database updater" ); $dbclass = 'Database' . ucfirst( $wgDBtype ) ; -$dbc = new $dbclass; echo( "MediaWiki {$wgVersion} Updater\n\n" ); @@ -31,7 +30,7 @@ if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) { # 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 @@ -40,7 +39,7 @@ if( !$wgDatabase->isOpen() ) { 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'] ) ) { diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index f66051d45f..e632f73778 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -79,10 +79,8 @@ class UserDupes { * @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; } @@ -92,7 +90,7 @@ class UserDupes { $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; @@ -114,9 +112,9 @@ class UserDupes { 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"; } } @@ -325,4 +323,4 @@ class UserDupes { } -?> \ No newline at end of file +?> -- 2.20.1