Drop AuthPlugin and related code, deprecated in 1.27
[lhc/web/wiklou.git] / includes / user / User.php
index f820861..1e3ecf2 100644 (file)
@@ -496,7 +496,6 @@ class User implements IDBAccessObject, UserIdentity {
         * @return string
         */
        protected function getCacheKey( WANObjectCache $cache ) {
-               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 
                return $cache->makeGlobalKey( 'user', 'id', $lbFactory->getLocalDomainID(), $this->mId );
@@ -520,7 +519,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @since 1.25
         */
        protected function loadFromCache() {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $data = $cache->getWithSetCallback(
                        $this->getCacheKey( $cache ),
                        $cache::TTL_HOUR,
@@ -1259,10 +1258,7 @@ class User implements IDBAccessObject, UserIdentity {
                        return false;
                }
 
-               // Reject various classes of invalid names
-               $name = AuthManager::callLegacyAuthPlugin(
-                       'getCanonicalName', [ $t->getText() ], $t->getText()
-               );
+               $name = $t->getText();
 
                switch ( $validate ) {
                        case false:
@@ -1668,7 +1664,6 @@ class User implements IDBAccessObject, UserIdentity {
 
                // update groups in external authentication database
                Hooks::run( 'UserGroupsChanged', [ $this, $toPromote, [], false, false, $oldUGMs, $newUGMs ] );
-               AuthManager::callLegacyAuthPlugin( 'updateExternalDBGroups', [ $this, $toPromote ] );
 
                $logEntry = new ManualLogEntry( 'rights', 'autopromote' );
                $logEntry->setPerformer( $this );
@@ -1928,7 +1923,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $this->mBlockedby = $block->getByName();
                        $this->mBlockreason = $block->mReason;
                        $this->mHideName = $block->mHideName;
-                       $this->mAllowUsertalk = !$block->prevents( 'editownusertalk' );
+                       $this->mAllowUsertalk = $block->isUsertalkEditAllowed();
                } else {
                        $this->mBlock = null;
                        $this->mBlockedby = '';
@@ -2276,7 +2271,8 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool True if blocked, false otherwise
         */
        public function isBlocked( $bFromReplica = true ) {
-               return $this->getBlock( $bFromReplica ) instanceof Block && $this->getBlock()->prevents( 'edit' );
+               return $this->getBlock( $bFromReplica ) instanceof Block &&
+                       $this->getBlock()->appliesToRight( 'edit' );
        }
 
        /**
@@ -2306,26 +2302,7 @@ class User implements IDBAccessObject, UserIdentity {
                                // Special handling for a user's own talk page. The block is not aware
                                // of the user, so this must be done here.
                                if ( $title->equals( $this->getTalkPage() ) ) {
-                                       if ( $block->isSitewide() ) {
-                                               // If the block is sitewide, whatever is set is what is honored.
-                                               // This must be checked here, because Block::appliesToPage will
-                                               // return true for a sitewide block.
-                                               $blocked = $block->prevents( 'editownusertalk' );
-                                       } else {
-                                               // The page restrictions always take precedence over the namespace
-                                               // restrictions. If the user is explicity blocked from their own
-                                               // talk page, nothing can change that.
-                                               $blocked = $block->appliesToPage( $title->getArticleID() );
-
-                                               // If the block applies to the user talk namespace, then whatever is
-                                               // set is what is honored.
-                                               if ( !$blocked && $block->appliesToNamespace( NS_USER_TALK ) ) {
-                                                       $blocked = $block->prevents( 'editownusertalk' );
-                                               }
-
-                                               // If another type of restriction is added, it should be checked
-                                               // here.
-                                       }
+                                       $blocked = $block->appliesToUsertalk( $title );
                                } else {
                                        $blocked = $block->appliesToTitle( $title );
                                }
@@ -2426,10 +2403,8 @@ class User implements IDBAccessObject, UserIdentity {
                if ( $this->mLocked !== null ) {
                        return $this->mLocked;
                }
-               // Avoid PHP 7.1 warning of passing $this by reference
-               $user = $this;
-               $authUser = AuthManager::callLegacyAuthPlugin( 'getUserInstance', [ &$user ], null );
-               $this->mLocked = $authUser && $authUser->isLocked();
+               // Reset for hook
+               $this->mLocked = false;
                Hooks::run( 'UserIsLocked', [ $this, &$this->mLocked ] );
                return $this->mLocked;
        }
@@ -2445,10 +2420,8 @@ class User implements IDBAccessObject, UserIdentity {
                }
                $this->getBlockedStatus();
                if ( !$this->mHideName ) {
-                       // Avoid PHP 7.1 warning of passing $this by reference
-                       $user = $this;
-                       $authUser = AuthManager::callLegacyAuthPlugin( 'getUserInstance', [ &$user ], null );
-                       $this->mHideName = $authUser && $authUser->isHidden();
+                       // Reset for hook
+                       $this->mHideName = false;
                        Hooks::run( 'UserIsHidden', [ $this, &$this->mHideName ] );
                }
                return (bool)$this->mHideName;
@@ -2658,7 +2631,7 @@ class User implements IDBAccessObject, UserIdentity {
                $rev = $timestamp ? Revision::loadFromTimestamp( $dbr, $utp, $timestamp ) : null;
                return [
                        [
-                               'wiki' => WikiMap::getWikiIdFromDomain( WikiMap::getCurrentWikiDomain() ),
+                               'wiki' => WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() ),
                                'link' => $utp->getLocalURL(),
                                'rev' => $rev
                        ]
@@ -2815,7 +2788,7 @@ class User implements IDBAccessObject, UserIdentity {
                        return;
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $key = $this->getCacheKey( $cache );
                if ( $mode === 'refresh' ) {
                        $cache->delete( $key, 1 );
@@ -4537,7 +4510,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function isBlockedFromCreateAccount() {
                $this->getBlockedStatus();
-               if ( $this->mBlock && $this->mBlock->prevents( 'createaccount' ) ) {
+               if ( $this->mBlock && $this->mBlock->appliesToRight( 'createaccount' ) ) {
                        return $this->mBlock;
                }
 
@@ -4548,7 +4521,7 @@ class User implements IDBAccessObject, UserIdentity {
                        $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() );
                }
                return $this->mBlockedFromCreateAccount instanceof Block
-                       && $this->mBlockedFromCreateAccount->prevents( 'createaccount' )
+                       && $this->mBlockedFromCreateAccount->appliesToRight( 'createaccount' )
                        ? $this->mBlockedFromCreateAccount
                        : false;
        }
@@ -4559,7 +4532,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function isBlockedFromEmailuser() {
                $this->getBlockedStatus();
-               return $this->mBlock && $this->mBlock->prevents( 'sendemail' );
+               return $this->mBlock && $this->mBlock->appliesToRight( 'sendemail' );
        }
 
        /**
@@ -4570,7 +4543,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public function isBlockedFromUpload() {
                $this->getBlockedStatus();
-               return $this->mBlock && $this->mBlock->prevents( 'upload' );
+               return $this->mBlock && $this->mBlock->appliesToRight( 'upload' );
        }
 
        /**
@@ -4743,22 +4716,38 @@ class User implements IDBAccessObject, UserIdentity {
 
                if ( $type == 'created' || $type === false ) {
                        $message = 'confirmemail_body';
+                       $type = 'created';
                } elseif ( $type === true ) {
                        $message = 'confirmemail_body_changed';
+                       $type = 'changed';
                } else {
                        // Messages: confirmemail_body_changed, confirmemail_body_set
                        $message = 'confirmemail_body_' . $type;
                }
 
-               return $this->sendMail( wfMessage( 'confirmemail_subject' )->text(),
-                       wfMessage( $message,
+               $mail = [
+                       'subject' => wfMessage( 'confirmemail_subject' )->text(),
+                       'body' => wfMessage( $message,
                                $this->getRequest()->getIP(),
                                $this->getName(),
                                $url,
                                $wgLang->userTimeAndDate( $expiration, $this ),
                                $invalidateURL,
                                $wgLang->userDate( $expiration, $this ),
-                               $wgLang->userTime( $expiration, $this ) )->text() );
+                               $wgLang->userTime( $expiration, $this ) )->text(),
+                       'from' => null,
+                       'replyTo' => null,
+               ];
+               $info = [
+                       'type' => $type,
+                       'ip' => $this->getRequest()->getIP(),
+                       'confirmURL' => $url,
+                       'invalidateURL' => $invalidateURL,
+                       'expiration' => $expiration
+               ];
+
+               Hooks::run( 'UserSendConfirmationMail', [ $this, &$mail, $info ] );
+               return $this->sendMail( $mail['subject'], $mail['body'], $mail['from'], $mail['replyTo'] );
        }
 
        /**
@@ -4769,7 +4758,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @param string $body Message body
         * @param User|null $from Optional sending user; if unspecified, default
         *   $wgPasswordSender will be used.
-        * @param string|null $replyto Reply-To address
+        * @param MailAddress|null $replyto Reply-To address
         * @return Status
         */
        public function sendMail( $subject, $body, $from = null, $replyto = null ) {
@@ -5125,31 +5114,6 @@ class User implements IDBAccessObject, UserIdentity {
                return true;
        }
 
-       /**
-        * Get the localized descriptive name for a group, if it exists
-        * @deprecated since 1.29 Use UserGroupMembership::getGroupName instead
-        *
-        * @param string $group Internal group name
-        * @return string Localized descriptive group name
-        */
-       public static function getGroupName( $group ) {
-               wfDeprecated( __METHOD__, '1.29' );
-               return UserGroupMembership::getGroupName( $group );
-       }
-
-       /**
-        * Get the localized descriptive name for a member of a group, if it exists
-        * @deprecated since 1.29 Use UserGroupMembership::getGroupMemberName instead
-        *
-        * @param string $group Internal group name
-        * @param string $username Username for gender (since 1.19)
-        * @return string Localized name for group member
-        */
-       public static function getGroupMember( $group, $username = '#' ) {
-               wfDeprecated( __METHOD__, '1.29' );
-               return UserGroupMembership::getGroupMemberName( $group, $username );
-       }
-
        /**
         * Return the set of defined explicit groups.
         * The implicit groups (by default *, 'user' and 'autoconfirmed')