Followup r91672: remove commented-out reference to removed file (rtl.css)
[lhc/web/wiklou.git] / includes / Block.php
index 7911163..ba875fa 100644 (file)
@@ -20,7 +20,7 @@
  * @file
  */
 class Block {
-       /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName, $mAngryAutoblock;
+       /* public*/ var $mReason, $mTimestamp, $mAuto, $mExpiry, $mHideName;
 
        protected
                $mId,
@@ -84,7 +84,6 @@ class Block {
                $this->prevents( 'editownusertalk', !$allowUsertalk );
 
                $this->mFromMaster = false;
-               $this->mAngryAutoblock = false;
        }
 
        /**
@@ -203,7 +202,8 @@ class Block {
                        $conds = array( 'ipb_address' => array() );
                }
 
-               # Be aware that the != '' check is explicit, since empty values will be passed by some callers.
+               # Be aware that the != '' check is explicit, since empty values will be
+               # passed by some callers (bug 29116)
                if( $vagueTarget != ''){
                        list( $target, $type ) = self::parseTarget( $vagueTarget );
                        switch( $type ) {
@@ -487,43 +487,51 @@ class Block {
         */
        protected function doRetroactiveAutoblock() {
                $blockIds = array();
-
-               $dbr = wfGetDB( DB_SLAVE );
-               # If autoblock is enabled, autoblock the LAST IP used
-               # - stolen shamelessly from CheckUser_body.php
-
+               # If autoblock is enabled, autoblock the LAST IP(s) used
                if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
                        wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
 
-                       $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
-                       $conds = array( 'rc_user_text' => (string)$this->getTarget() );
+                       $continue = wfRunHooks(
+                               'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
 
-                       if ( $this->mAngryAutoblock ) {
-                               // Block any IP used in the last 7 days. Up to five IPs.
-                               $conds[] = 'rc_timestamp < ' .
-                                       $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) );
-                               $options['LIMIT'] = 5;
-                       } else {
-                               // Just the last IP used.
-                               $options['LIMIT'] = 1;
+                       if ( $continue ) {
+                               self::defaultRetroactiveAutoblock( $this, $blockIds );
                        }
+               }
+               return $blockIds;
+       }
+
+       /**
+        * Retroactively autoblocks the last IP used by the user (if it is a user)
+        * blocked by this Block. This will use the recentchanges table.
+        *
+        * @param Block $block
+        * @param Array &$blockIds
+        * @return Array: block IDs of retroactive autoblocks made
+        */
+       protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
+               $dbr = wfGetDB( DB_SLAVE );
 
-                       $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
-                               __METHOD__ ,  $options );
+               $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
+               $conds = array( 'rc_user_text' => (string)$block->getTarget() );
 
-                       if ( !$dbr->numRows( $res ) ) {
-                               # No results, don't autoblock anything
-                               wfDebug( "No IP found to retroactively autoblock\n" );
-                       } else {
-                               foreach ( $res as $row ) {
-                                       if ( $row->rc_ip ) {
-                                               $id = $this->doAutoblock( $row->rc_ip );
-                                               if ( $id ) $blockIds[] = $id;
-                                       }
+               // Just the last IP used.
+               $options['LIMIT'] = 1;
+
+               $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
+                       __METHOD__ ,  $options );
+
+               if ( !$dbr->numRows( $res ) ) {
+                       # No results, don't autoblock anything
+                       wfDebug( "No IP found to retroactively autoblock\n" );
+               } else {
+                       foreach ( $res as $row ) {
+                               if ( $row->rc_ip ) {
+                                       $id = $block->doAutoblock( $row->rc_ip );
+                                       if ( $id ) $blockIds[] = $id;
                                }
                        }
                }
-               return $blockIds;
        }
 
        /**
@@ -625,7 +633,7 @@ class Block {
                $autoblock->prevents( 'editownusertalk', $this->prevents( 'editownusertalk' ) );
 
                $dbr = wfGetDB( DB_SLAVE );
-               if ( $this->mTimestamp == $dbr->getInfinity() ) {
+               if ( $this->mExpiry == $dbr->getInfinity() ) {
                        # Original block was indefinite, start an autoblock now
                        $autoblock->mExpiry = Block::getAutoblockExpiry( $timestamp );
                } else {
@@ -988,11 +996,6 @@ class Block {
         *     not be the same as the target you gave if you used $vagueTarget!
         */
        public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
-               # (bug 29116) passing $vagueTarget = '' is not unreasonable here, but int(0)
-               # is a valid username, so we can't just use weak comparisons.
-               if( $vagueTarget === '' ){
-                       $vagueTarget = null;
-               }
 
                list( $target, $type ) = self::parseTarget( $specificTarget );
                if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
@@ -1000,7 +1003,8 @@ class Block {
 
                } elseif( $target === null && $vagueTarget == '' ){
                        # We're not going to find anything useful here
-                       # Be aware that the == '' check is explicit, since empty values will be passed by some callers.
+                       # Be aware that the == '' check is explicit, since empty values will be
+                       # passed by some callers (bug 29116)
                        return null;
 
                } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
@@ -1043,6 +1047,14 @@ class Block {
                        return array( null, null );
                }
 
+               # Consider the possibility that this is not a username at all
+               # but actually an old subpage (bug #29797)
+               if( strpos( $target, '/' ) !== false ){
+                       # An old subpage, drill down to the user behind it
+                       $parts = explode( '/', $target );
+                       $target = $parts[0];
+               }
+
                $userObj = User::newFromName( $target );
                if ( $userObj instanceof User ) {
                        # Note that since numbers are valid usernames, a $target of "12345" will be