Replace deprecated wfGetLB() calls here and there
authorWMDE-Fisch <christoph.jauera@wikimedia.de>
Thu, 4 Jan 2018 16:38:22 +0000 (17:38 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Sat, 20 Jan 2018 19:24:24 +0000 (19:24 +0000)
Change-Id: Ic7cec2dcc6b8e0d500a4c37eb134976b314c33ca

includes/api/ApiMain.php
includes/api/ApiQuerySiteinfo.php
includes/auth/AuthManager.php
includes/installer/MysqlUpdater.php
includes/page/WikiPage.php
includes/skins/Skin.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialWatchlist.php
includes/user/User.php

index 3bda3e8..82753a1 100644 (file)
@@ -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(
index 2e9e69c..6bab826 100644 (file)
@@ -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 ) {
index 9407c42..af070c2 100644 (file)
@@ -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;
                }
index a3caa07..44086a1 100644 (file)
@@ -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',
index 6847671..788ae61 100644 (file)
@@ -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 );
index 07964a4..c95f1f5 100644 (file)
@@ -911,7 +911,7 @@ abstract class Skin extends ContextSource {
                        $s = '';
                }
 
-               if ( wfGetLB()->getLaggedReplicaMode() ) {
+               if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) {
                        $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
                }
 
index 5a5f005..4775a7f 100644 (file)
@@ -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 );
                                }
index 5c8b3a6..975d64e 100644 (file)
@@ -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 );
                }
index 2ad70a6..7b3f25c 100644 (file)
@@ -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 );
                }
index 709bac7..0b3f8fd 100644 (file)
@@ -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;
                                }