Merge "Deprecate Parser::fetchFile() since it's unused"
[lhc/web/wiklou.git] / includes / user / BotPassword.php
index b898d8a..6b8153c 100644 (file)
@@ -18,6 +18,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Session\BotPasswordSessionProvider;
 use Wikimedia\Rdbms\IMaintainableDatabase;
 
@@ -74,9 +75,10 @@ class BotPassword implements IDBAccessObject {
        public static function getDB( $db ) {
                global $wgBotPasswordsCluster, $wgBotPasswordsDatabase;
 
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                $lb = $wgBotPasswordsCluster
-                       ? wfGetLBFactory()->getExternalLB( $wgBotPasswordsCluster )
-                       : wfGetLB( $wgBotPasswordsDatabase );
+                       ? $lbFactory->getExternalLB( $wgBotPasswordsCluster )
+                       : $lbFactory->getMainLB( $wgBotPasswordsDatabase );
                return $lb->getConnectionRef( $db, [], $wgBotPasswordsDatabase );
        }
 
@@ -259,6 +261,15 @@ class BotPassword implements IDBAccessObject {
                }
        }
 
+       /**
+        * Whether the password is currently invalid
+        * @since 1.32
+        * @return bool
+        */
+       public function isInvalid() {
+               return $this->getPassword() instanceof InvalidPassword;
+       }
+
        /**
         * Save the BotPassword to the database
         * @param string $operation 'update' or 'insert'
@@ -489,7 +500,11 @@ class BotPassword implements IDBAccessObject {
                }
 
                // Check the password
-               if ( !$bp->getPassword()->equals( $password ) ) {
+               $passwordObj = $bp->getPassword();
+               if ( $passwordObj instanceof InvalidPassword ) {
+                       return Status::newFatal( 'botpasswords-needs-reset', $name, $appId );
+               }
+               if ( !$passwordObj->equals( $password ) ) {
                        return Status::newFatal( 'wrongpassword' );
                }