From a7872722b7f78f811971c58c3440146c70b33345 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Thu, 4 Jan 2018 17:38:22 +0100 Subject: [PATCH] Replace deprecated wfGetLB() calls here and there Change-Id: Ic7cec2dcc6b8e0d500a4c37eb134976b314c33ca --- includes/api/ApiMain.php | 6 +++--- includes/api/ApiQuerySiteinfo.php | 2 +- includes/auth/AuthManager.php | 5 ++++- includes/installer/MysqlUpdater.php | 5 +++-- includes/page/WikiPage.php | 5 +++-- includes/skins/Skin.php | 2 +- includes/specials/SpecialContributions.php | 4 +++- includes/specials/SpecialDeletedContributions.php | 5 ++++- includes/specials/SpecialWatchlist.php | 2 +- includes/user/User.php | 3 ++- 10 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 3bda3e8113..82753a19f3 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1452,7 +1452,7 @@ class ApiMain extends ApiBase { if ( $module->isWriteMode() && $this->getUser()->isBot() - && wfGetLB()->getServerCount() > 1 + && MediaWikiServices::getInstance()->getDBLoadBalancer()->getServerCount() > 1 ) { $this->checkBotReadOnly(); } @@ -1466,7 +1466,7 @@ class ApiMain extends ApiBase { $numLagged = 0; $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' ); $laggedServers = []; - $loadBalancer = wfGetLB(); + $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer(); foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) { if ( $lag > $lagLimit ) { ++$numLagged; @@ -1475,7 +1475,7 @@ class ApiMain extends ApiBase { } // If a majority of replica DBs are too lagged then disallow writes - $replicaCount = wfGetLB()->getServerCount() - 1; + $replicaCount = $loadBalancer->getServerCount() - 1; if ( $numLagged >= ceil( $replicaCount / 2 ) ) { $laggedServers = implode( ', ', $laggedServers ); wfDebugLog( diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 2e9e69c9a5..6bab8269a6 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -449,7 +449,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { protected function appendDbReplLagInfo( $property, $includeAll ) { $data = []; - $lb = wfGetLB(); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); $showHostnames = $this->getConfig()->get( 'ShowHostnames' ); if ( $includeAll ) { if ( !$showHostnames ) { diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php index 9407c42274..af070c25cb 100644 --- a/includes/auth/AuthManager.php +++ b/includes/auth/AuthManager.php @@ -1551,7 +1551,10 @@ class AuthManager implements LoggerAwareInterface { // Fetch the user ID from the master, so that we don't try to create the user // when they already exist, due to replication lag // @codeCoverageIgnoreStart - if ( !$localId && wfGetLB()->getReaderIndex() != 0 ) { + if ( + !$localId && + MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() != 0 + ) { $localId = User::idFromName( $username, User::READ_LATEST ); $flags = User::READ_LATEST; } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index a3caa07db3..44086a125e 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -872,7 +872,8 @@ class MysqlUpdater extends DatabaseUpdater { $this->applyPatch( 'patch-templatelinks.sql', false, "Creating templatelinks table" ); $this->output( "Populating...\n" ); - if ( wfGetLB()->getServerCount() > 1 ) { + $services = MediaWikiServices::getInstance(); + if ( $services->getDBLoadBalancer()->getServerCount() > 1 ) { // Slow, replication-friendly update $res = $this->db->select( 'pagelinks', [ 'pl_from', 'pl_namespace', 'pl_title' ], [ 'pl_namespace' => NS_TEMPLATE ], __METHOD__ ); @@ -880,7 +881,7 @@ class MysqlUpdater extends DatabaseUpdater { foreach ( $res as $row ) { $count = ( $count + 1 ) % 100; if ( $count == 0 ) { - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory = $services->getDBLoadBalancerFactory(); $lbFactory->waitForReplication( [ 'wiki' => wfWikiID() ] ); } $this->db->insert( 'templatelinks', diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 68476715f8..788ae61bac 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1425,14 +1425,15 @@ class WikiPage implements Page, IDBAccessObject { ) { $baseRevId = null; if ( $edittime && $sectionId !== 'new' ) { + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); $dbr = wfGetDB( DB_REPLICA ); $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime ); // Try the master if this thread may have just added it. // This could be abstracted into a Revision method, but we don't want // to encourage loading of revisions by timestamp. if ( !$rev - && wfGetLB()->getServerCount() > 1 - && wfGetLB()->hasOrMadeRecentMasterChanges() + && $lb->getServerCount() > 1 + && $lb->hasOrMadeRecentMasterChanges() ) { $dbw = wfGetDB( DB_MASTER ); $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 07964a4d55..c95f1f502c 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -911,7 +911,7 @@ abstract class Skin extends ContextSource { $s = ''; } - if ( wfGetLB()->getLaggedReplicaMode() ) { + if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) { $s .= ' ' . $this->msg( 'laggedslavemode' )->parse() . ''; } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 5a5f005baf..4775a7f928 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -21,6 +21,7 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; use MediaWiki\Widget\DateInputWidget; /** @@ -220,7 +221,8 @@ class SpecialContributions extends IncludableSpecialPage { $out->addWikiMsg( 'nocontribs', $target ); } else { # Show a message about replica DB lag, if applicable - $lag = wfGetLB()->safeGetLag( $pager->getDatabase() ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $lag = $lb->safeGetLag( $pager->getDatabase() ); if ( $lag > 0 ) { $out->showLagWarning( $lag ); } diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 5c8b3a6206..975d64e348 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; + /** * Implements Special:DeletedContributions to display archived revisions * @ingroup SpecialPage @@ -97,7 +99,8 @@ class DeletedContributionsPage extends SpecialPage { } # Show a message about replica DB lag, if applicable - $lag = wfGetLB()->safeGetLag( $pager->getDatabase() ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $lag = $lb->safeGetLag( $pager->getDatabase() ); if ( $lag > 0 ) { $out->showLagWarning( $lag ); } diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 2ad70a67a8..7b3f25c838 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -486,7 +486,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { $output = $this->getOutput(); # Show a message about replica DB lag, if applicable - $lag = wfGetLB()->safeGetLag( $dbr ); + $lag = MediaWikiServices::getInstance()->getDBLoadBalancer()->safeGetLag( $dbr ); if ( $lag > 0 ) { $output->showLagWarning( $lag ); } diff --git a/includes/user/User.php b/includes/user/User.php index 709bac7e68..0b3f8fdea9 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -384,7 +384,8 @@ class User implements IDBAccessObject, UserIdentity { break; case 'name': // Make sure this thread sees its own changes - if ( wfGetLB()->hasOrMadeRecentMasterChanges() ) { + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + if ( $lb->hasOrMadeRecentMasterChanges() ) { $flags |= self::READ_LATEST; $this->queryFlagsUsed = $flags; } -- 2.20.1