Merge "Deprecate Block::isValid method"
[lhc/web/wiklou.git] / includes / Block.php
index 7e32f7e..b17ec86 100644 (file)
@@ -166,7 +166,7 @@ class Block {
                }
 
                $this->setReason( $options['reason'] );
-               $this->mTimestamp = wfTimestamp( TS_MW, $options['timestamp'] );
+               $this->setTimestamp( wfTimestamp( TS_MW, $options['timestamp'] ) );
                $this->setExpiry( wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] ) );
 
                # Boolean settings
@@ -471,7 +471,7 @@ class Block {
                        $row->ipb_by, $row->ipb_by_text, $row->ipb_by_actor ?? null
                ) );
 
-               $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
+               $this->setTimestamp( wfTimestamp( TS_MW, $row->ipb_timestamp ) );
                $this->mAuto = $row->ipb_auto;
                $this->setHideName( $row->ipb_deleted );
                $this->mId = (int)$row->ipb_id;
@@ -904,7 +904,7 @@ class Block {
                                ->inContentLanguage()->plain()
                );
                $timestamp = wfTimestampNow();
-               $autoblock->mTimestamp = $timestamp;
+               $autoblock->setTimestamp( $timestamp );
                $autoblock->mAuto = 1;
                $autoblock->isCreateAccountBlocked( $this->isCreateAccountBlocked() );
                # Continue suppressing the name if needed
@@ -964,9 +964,12 @@ class Block {
 
        /**
         * Is the block address valid (i.e. not a null string?)
+        *
+        * @deprecated since 1.33 No longer needed in core.
         * @return bool
         */
        public function isValid() {
+               wfDeprecated( __METHOD__, '1.33' );
                return $this->getTarget() != null;
        }
 
@@ -975,7 +978,7 @@ class Block {
         */
        public function updateTimestamp() {
                if ( $this->mAuto ) {
-                       $this->mTimestamp = wfTimestamp();
+                       $this->setTimestamp( wfTimestamp() );
                        $this->setExpiry( self::getAutoblockExpiry( $this->getTimestamp() ) );
 
                        $dbw = wfGetDB( DB_MASTER );
@@ -1036,10 +1039,7 @@ class Block {
         * @return int (0 for foreign users)
         */
        public function getBy() {
-               $blocker = $this->getBlocker();
-               return ( $blocker instanceof User )
-                       ? $blocker->getId()
-                       : 0;
+               return $this->getBlocker()->getId();
        }
 
        /**
@@ -1048,10 +1048,7 @@ class Block {
         * @return string
         */
        public function getByName() {
-               $blocker = $this->getBlocker();
-               return ( $blocker instanceof User )
-                       ? $blocker->getName()
-                       : (string)$blocker; // username
+               return $this->getBlocker()->getName();
        }
 
        /**
@@ -2124,4 +2121,46 @@ class Block {
 
                return null;
        }
+
+       /**
+        * Check if the block should be tracked with a cookie.
+        *
+        * @since 1.33
+        * @param bool $isIpUser The user is logged out
+        * @return bool The block should be tracked with a cookie
+        */
+       public function shouldTrackWithCookie( $isIpUser ) {
+               $config = RequestContext::getMain()->getConfig();
+               switch ( $this->getType() ) {
+                       case self::TYPE_IP:
+                       case self::TYPE_RANGE:
+                               return $isIpUser && $config->get( 'CookieSetOnIpBlock' );
+                       case self::TYPE_USER:
+                               return !$isIpUser && $config->get( 'CookieSetOnAutoblock' ) && $this->isAutoblocking();
+                       default:
+                               return false;
+               }
+       }
+
+       /**
+        * Check if the block prevents a user from resetting their password
+        *
+        * @since 1.33
+        * @return bool|null The block blocks password reset
+        */
+       public function appliesToPasswordReset() {
+               switch ( $this->getSystemBlockType() ) {
+                       case null:
+                       case 'global-block':
+                               return $this->isCreateAccountBlocked();
+                       case 'proxy':
+                               return true;
+                       case 'dnsbl':
+                       case 'wgSoftBlockRanges':
+                               return false;
+                       default:
+                               return false;
+               }
+       }
+
 }