User::edits() was removed
[lhc/web/wiklou.git] / includes / user / User.php
index 273d555..df9dd3e 100644 (file)
@@ -166,7 +166,6 @@ class User implements IDBAccessObject {
                'noratelimit',
                'override-export-depth',
                'pagelang',
-               'passwordreset',
                'patrol',
                'patrolmarks',
                'protect',
@@ -301,6 +300,11 @@ class User implements IDBAccessObject {
        /** @var integer User::READ_* constant bitfield used to load data */
        protected $queryFlagsUsed = self::READ_NORMAL;
 
+       /** @var string Indicates type of block (used for eventlogging)
+        * Permitted values: 'cookie-block', 'proxy-block', 'openproxy-block', 'xff-block'
+        */
+       public $blockTrigger = false;
+
        public static $idCacheByName = [];
 
        /**
@@ -999,11 +1003,10 @@ class User implements IDBAccessObject {
         * able to set their password to this.
         *
         * @param string $password Desired password
-        * @param string $purpose one of 'login', 'create', 'reset'
         * @return Status
         * @since 1.23
         */
-       public function checkPasswordValidity( $password, $purpose = 'login' ) {
+       public function checkPasswordValidity( $password ) {
                global $wgPasswordPolicy;
 
                $upp = new UserPasswordPolicy(
@@ -1020,7 +1023,7 @@ class User implements IDBAccessObject {
                }
 
                if ( $result === false ) {
-                       $status->merge( $upp->checkUserPassword( $this, $password, $purpose ) );
+                       $status->merge( $upp->checkUserPassword( $this, $password ) );
                        return $status;
                } elseif ( $result === true ) {
                        return $status;
@@ -1094,20 +1097,6 @@ class User implements IDBAccessObject {
                return $name;
        }
 
-       /**
-        * Count the number of edits of a user
-        *
-        * @param int $uid User ID to check
-        * @return int The user's edit count
-        *
-        * @deprecated since 1.21 in favour of User::getEditCount
-        */
-       public static function edits( $uid ) {
-               wfDeprecated( __METHOD__, '1.21' );
-               $user = self::newFromId( $uid );
-               return $user->getEditCount();
-       }
-
        /**
         * Return a random password.
         *
@@ -1200,13 +1189,29 @@ class User implements IDBAccessObject {
                $user = $session->getUser();
                if ( $user->isLoggedIn() ) {
                        $this->loadFromUserObject( $user );
+
+                       // If this user is autoblocked, set a cookie to track the Block. This has to be done on
+                       // every session load, because an autoblocked editor might not edit again from the same
+                       // IP address after being blocked.
+                       $config = RequestContext::getMain()->getConfig();
+                       if ( $config->get( 'CookieSetOnAutoblock' ) === true ) {
+                               $block = $this->getBlock();
+                               $shouldSetCookie = $this->getRequest()->getCookie( 'BlockID' ) === null
+                                       && $block
+                                       && $block->getType() === Block::TYPE_USER
+                                       && $block->isAutoblocking();
+                               if ( $shouldSetCookie ) {
+                                       wfDebug( __METHOD__ . ': User is autoblocked, setting cookie to track' );
+                                       $block->setCookie( $this->getRequest()->response() );
+                               }
+                       }
+
                        // Other code expects these to be set in the session, so set them.
                        $session->set( 'wsUserID', $this->getId() );
                        $session->set( 'wsUserName', $this->getName() );
                        $session->set( 'wsToken', $this->getToken() );
                        return true;
                }
-
                return false;
        }
 
@@ -1609,6 +1614,31 @@ class User implements IDBAccessObject {
                // User/IP blocking
                $block = Block::newFromTarget( $this, $ip, !$bFromSlave );
 
+               // If no block has been found, check for a cookie indicating that the user is blocked.
+               $blockCookieVal = (int)$this->getRequest()->getCookie( 'BlockID' );
+               if ( !$block instanceof Block && $blockCookieVal > 0 ) {
+                       // Load the Block from the ID in the cookie.
+                       $tmpBlock = Block::newFromID( $blockCookieVal );
+                       if ( $tmpBlock instanceof Block ) {
+                               // Check the validity of the block.
+                               $blockIsValid = $tmpBlock->getType() == Block::TYPE_USER
+                                       && !$tmpBlock->isExpired()
+                                       && $tmpBlock->isAutoblocking();
+                               $config = RequestContext::getMain()->getConfig();
+                               $useBlockCookie = ( $config->get( 'CookieSetOnAutoblock' ) === true );
+                               if ( $blockIsValid && $useBlockCookie ) {
+                                       // Use the block.
+                                       $block = $tmpBlock;
+                                       $this->blockTrigger = 'cookie-block';
+                               } else {
+                                       // If the block is not valid, clear the block cookie (but don't delete it,
+                                       // because it needs to be cleared from LocalStorage as well and an empty string
+                                       // value is checked for in the mediawiki.user.blockcookie module).
+                                       $tmpBlock->setCookie( $this->getRequest()->response(), true );
+                               }
+                       }
+               }
+
                // Proxy blocking
                if ( !$block instanceof Block && $ip !== null && !in_array( $ip, $wgProxyWhitelist ) ) {
                        // Local list
@@ -1617,11 +1647,13 @@ class User implements IDBAccessObject {
                                $block->setBlocker( wfMessage( 'proxyblocker' )->text() );
                                $block->mReason = wfMessage( 'proxyblockreason' )->text();
                                $block->setTarget( $ip );
+                               $this->blockTrigger = 'proxy-block';
                        } elseif ( $this->isAnon() && $this->isDnsBlacklisted( $ip ) ) {
                                $block = new Block;
                                $block->setBlocker( wfMessage( 'sorbs' )->text() );
                                $block->mReason = wfMessage( 'sorbsreason' )->text();
                                $block->setTarget( $ip );
+                               $this->blockTrigger = 'openproxy-block';
                        }
                }
 
@@ -1640,6 +1672,7 @@ class User implements IDBAccessObject {
                                # Mangle the reason to alert the user that the block
                                # originated from matching the X-Forwarded-For header.
                                $block->mReason = wfMessage( 'xffblockreason', $block->mReason )->text();
+                               $this->blockTrigger = 'xff-block';
                        }
                }
 
@@ -1654,6 +1687,7 @@ class User implements IDBAccessObject {
                        $this->mBlockedby = '';
                        $this->mHideName = 0;
                        $this->mAllowUsertalk = false;
+                       $this->blockTrigger = false;
                }
 
                // Extensions
@@ -5017,13 +5051,27 @@ class User implements IDBAccessObject {
        /**
         * Get the description of a given right
         *
+        * @since 1.29
         * @param string $right Right to query
         * @return string Localized description of the right
         */
        public static function getRightDescription( $right ) {
                $key = "right-$right";
                $msg = wfMessage( $key );
-               return $msg->isBlank() ? $right : $msg->text();
+               return $msg->isDisabled() ? $right : $msg->text();
+       }
+
+       /**
+        * Get the name of a given grant
+        *
+        * @since 1.29
+        * @param string $grant Grant to query
+        * @return string Localized name of the grant
+        */
+       public static function getGrantName( $grant ) {
+               $key = "grant-$grant";
+               $msg = wfMessage( $key );
+               return $msg->isDisabled() ? $grant : $msg->text();
        }
 
        /**