Add devunt to CREDITS as patch contributor
[lhc/web/wiklou.git] / includes / Block.php
index b81cf3a..7ee36ce 100644 (file)
@@ -65,7 +65,7 @@ class Block {
                $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
                $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byText = '' )
        {
-               if( $timestamp === 0 ){
+               if( $timestamp === 0 ) {
                        $timestamp = wfTimestampNow();
                }
 
@@ -106,7 +106,7 @@ class Block {
         * user ID. Tries the user ID first, and if that doesn't work, tries
         * the address.
         *
-        * @param $address String: IP address of user/anon
+        * @param string $address IP address of user/anon
         * @param $user Integer: user id of user
         * @return Block Object
         * @deprecated since 1.18
@@ -199,23 +199,23 @@ class Block {
        /**
         * Get a block from the DB, with either the given address or the given username
         *
-        * @param $address string The IP address of the user, or blank to skip IP blocks
-        * @param $user int The user ID, or zero for anonymous users
+        * @param string $address The IP address of the user, or blank to skip IP blocks
+        * @param int $user The user ID, or zero for anonymous users
         * @return Boolean: the user is blocked from editing
         * @deprecated since 1.18
         */
        public function load( $address = '', $user = 0 ) {
                wfDeprecated( __METHOD__, '1.18' );
-               if( $user ){
+               if( $user ) {
                        $username = User::whoIs( $user );
                        $block = self::newFromTarget( $username, $address );
                } else {
                        $block = self::newFromTarget( null, $address );
                }
 
-               if( $block instanceof Block ){
+               if( $block instanceof Block ) {
                        # This is mildly evil, but hey, it's B/C :D
-                       foreach( $block as $variable => $value ){
+                       foreach( $block as $variable => $value ) {
                                $this->$variable = $value;
                        }
                        return true;
@@ -227,7 +227,7 @@ class Block {
        /**
         * Load a block from the database which affects the already-set $this->target:
         *     1) A block directly on the given user or IP
-        *     2) A rangeblock encompasing the given IP (smallest first)
+        *     2) A rangeblock encompassing the given IP (smallest first)
         *     3) An autoblock on the given IP
         * @param $vagueTarget User|String also search for blocks affecting this target.  Doesn't
         *     make any sense to use TYPE_AUTO / TYPE_ID here. Leave blank to skip IP lookups.
@@ -237,7 +237,7 @@ class Block {
        protected function newLoad( $vagueTarget = null ) {
                $db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
 
-               if( $this->type !== null ){
+               if( $this->type !== null ) {
                        $conds = array(
                                'ipb_address' => array( (string)$this->target ),
                        );
@@ -247,11 +247,11 @@ class Block {
 
                # Be aware that the != '' check is explicit, since empty values will be
                # passed by some callers (bug 29116)
-               if( $vagueTarget != ''){
+               if( $vagueTarget != '' ) {
                        list( $target, $type ) = self::parseTarget( $vagueTarget );
                        switch( $type ) {
                                case self::TYPE_USER:
-                                       # Slightly wierd, but who are we to argue?
+                                       # Slightly weird, but who are we to argue?
                                        $conds['ipb_address'][] = (string)$target;
                                        break;
 
@@ -285,20 +285,20 @@ class Block {
                # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
                $bestBlockPreventsEdit = null;
 
-               foreach( $res as $row ){
+               foreach( $res as $row ) {
                        $block = self::newFromRow( $row );
 
                        # Don't use expired blocks
-                       if( $block->deleteIfExpired() ){
+                       if( $block->deleteIfExpired() ) {
                                continue;
                        }
 
                        # Don't use anon only blocks on users
-                       if( $this->type == self::TYPE_USER && !$block->isHardblock() ){
+                       if( $this->type == self::TYPE_USER && !$block->isHardblock() ) {
                                continue;
                        }
 
-                       if( $block->getType() == self::TYPE_RANGE ){
+                       if( $block->getType() == self::TYPE_RANGE ) {
                                # This is the number of bits that are allowed to vary in the block, give
                                # or take some floating point errors
                                $end = wfBaseconvert( $block->getRangeEnd(), 16, 10 );
@@ -307,20 +307,20 @@ class Block {
 
                                # This has the nice property that a /32 block is ranked equally with a
                                # single-IP block, which is exactly what it is...
-                               $score = self::TYPE_RANGE  - 1 + ( $size / 128 );
+                               $score = self::TYPE_RANGE - 1 + ( $size / 128 );
 
                        } else {
                                $score = $block->getType();
                        }
 
-                       if( $score < $bestBlockScore ){
+                       if( $score < $bestBlockScore ) {
                                $bestBlockScore = $score;
                                $bestRow = $row;
                                $bestBlockPreventsEdit = $block->prevents( 'edit' );
                        }
                }
 
-               if( $bestRow !== null ){
+               if( $bestRow !== null ) {
                        $this->initFromRow( $bestRow );
                        $this->prevents( 'edit', $bestBlockPreventsEdit );
                        return true;
@@ -330,9 +330,9 @@ class Block {
        }
 
        /**
-        * Get a set of SQL conditions which will select rangeblocks encompasing a given range
-        * @param $start String Hexadecimal IP representation
-        * @param $end String Hexadecimal IP represenation, or null to use $start = $end
+        * Get a set of SQL conditions which will select rangeblocks encompassing a given range
+        * @param string $start Hexadecimal IP representation
+        * @param string $end Hexadecimal IP representation, or null to use $start = $end
         * @return String
         */
        public static function getRangeCond( $start, $end = null ) {
@@ -371,9 +371,9 @@ class Block {
        protected static function getIpFragment( $hex ) {
                global $wgBlockCIDRLimit;
                if ( substr( $hex, 0, 3 ) == 'v6-' ) {
-                       return 'v6-' . substr( substr( $hex, 3 ), 0,  floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
+                       return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
                } else {
-                       return substr( $hex, 0,  floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
+                       return substr( $hex, 0, floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
                }
        }
 
@@ -465,7 +465,7 @@ class Block {
                Block::purgeExpired();
 
                $row = $this->getDatabaseArray();
-               $row['ipb_id'] = $dbw->nextSequenceValue("ipblocks_ipb_id_seq");
+               $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" );
 
                $dbw->insert(
                        'ipblocks',
@@ -488,7 +488,7 @@ class Block {
         * Update a block in the DB with new parameters.
         * The ID field needs to be loaded first.
         *
-        * @return Int number of affected rows, which should probably be 1 or something's
+        * @return Int number of affected rows, which should probably be 1 or something has
         *     gone slightly awry
         */
        public function update() {
@@ -511,7 +511,7 @@ class Block {
         * @return Array
         */
        protected function getDatabaseArray( $db = null ) {
-               if( !$db ){
+               if( !$db ) {
                        $db = wfGetDB( DB_SLAVE );
                }
                $expiry = $db->encodeExpiry( $this->mExpiry );
@@ -572,7 +572,7 @@ class Block {
         * blocked by this Block. This will use the recentchanges table.
         *
         * @param Block $block
-        * @param Array &$blockIds
+        * @param array &$blockIds
         * @return Array: block IDs of retroactive autoblocks made
         */
        protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
@@ -592,7 +592,7 @@ class Block {
                $options['LIMIT'] = 1;
 
                $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
-                       __METHOD__ ,  $options );
+                       __METHOD__, $options );
 
                if ( !$res->numRows() ) {
                        # No results, don't autoblock anything
@@ -611,7 +611,7 @@ class Block {
         * Checks whether a given IP is on the autoblock whitelist.
         * TODO: this probably belongs somewhere else, but not sure where...
         *
-        * @param $ip String: The IP to check
+        * @param string $ip The IP to check
         * @return Boolean
         */
        public static function isWhitelistedFromAutoblocks( $ip ) {
@@ -654,7 +654,7 @@ class Block {
        /**
         * Autoblocks the given IP, referring to this Block.
         *
-        * @param $autoblockIP String: the IP to autoblock.
+        * @param string $autoblockIP the IP to autoblock.
         * @return mixed: block ID if an autoblock was inserted, false if not.
         */
        public function doAutoblock( $autoblockIP ) {
@@ -945,7 +945,7 @@ class Block {
        /**
         * Encode expiry for DB
         *
-        * @param $expiry String: timestamp for expiry, or
+        * @param string $expiry timestamp for expiry, or
         * @param $db DatabaseBase object
         * @return String
         * @deprecated since 1.18; use $dbw->encodeExpiry() instead
@@ -958,8 +958,8 @@ class Block {
        /**
         * Decode expiry which has come from the DB
         *
-        * @param $expiry String: Database expiry format
-        * @param $timestampType Int Requested timestamp format
+        * @param string $expiry Database expiry format
+        * @param int $timestampType Requested timestamp format
         * @return String
         * @deprecated since 1.18; use $wgLang->formatExpiry() instead
         */
@@ -982,9 +982,9 @@ class Block {
        }
 
        /**
-        * Gets rid of uneeded numbers in quad-dotted/octet IP strings
+        * Gets rid of unneeded numbers in quad-dotted/octet IP strings
         * For example, 127.111.113.151/24 -> 127.111.113.0/24
-        * @param $range String: IP address to normalize
+        * @param string $range IP address to normalize
         * @return string
         * @deprecated since 1.18, call IP::sanitizeRange() directly
         */
@@ -1018,7 +1018,7 @@ class Block {
        /**
         * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
         * ("24 May 2034"), into an absolute timestamp we can put into the database.
-        * @param $expiry String: whatever was typed into the form
+        * @param string $expiry whatever was typed into the form
         * @return String: timestamp or "infinity" string for th DB implementation
         * @deprecated since 1.18 moved to SpecialBlock::parseExpiryInput()
         */
@@ -1042,7 +1042,7 @@ class Block {
         * @param $vagueTarget String|User|Int as above, but we will search for *any* block which
         *     affects that target (so for an IP address, get ranges containing that IP; and also
         *     get any relevant autoblocks). Leave empty or blank to skip IP-based lookups.
-        * @param $fromMaster Bool whether to use the DB_MASTER database
+        * @param bool $fromMaster whether to use the DB_MASTER database
         * @return Block|null (null if no relevant block could be found).  The target and type
         *     of the returned Block will refer to the actual block which was found, which might
         *     not be the same as the target you gave if you used $vagueTarget!
@@ -1050,10 +1050,10 @@ class Block {
        public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
 
                list( $target, $type ) = self::parseTarget( $specificTarget );
-               if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
+               if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
                        return Block::newFromID( $target );
 
-               } elseif( $target === null && $vagueTarget == '' ){
+               } 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 (bug 29116)
@@ -1063,11 +1063,11 @@ class Block {
                        $block = new Block();
                        $block->fromMaster( $fromMaster );
 
-                       if( $type !== null ){
+                       if( $type !== null ) {
                                $block->setTarget( $target );
                        }
 
-                       if( $block->newLoad( $vagueTarget ) ){
+                       if( $block->newLoad( $vagueTarget ) ) {
                                return $block;
                        }
                }
@@ -1085,13 +1085,13 @@ class Block {
         */
        public static function parseTarget( $target ) {
                # We may have been through this before
-               if( $target instanceof User ){
-                       if( IP::isValid( $target->getName() ) ){
+               if( $target instanceof User ) {
+                       if( IP::isValid( $target->getName() ) ) {
                                return array( $target, self::TYPE_IP );
                        } else {
                                return array( $target, self::TYPE_USER );
                        }
-               } elseif( $target === null ){
+               } elseif( $target === null ) {
                        return array( null, null );
                }
 
@@ -1112,7 +1112,7 @@ class Block {
 
                # Consider the possibility that this is not a username at all
                # but actually an old subpage (bug #29797)
-               if( strpos( $target, '/' ) !== false ){
+               if( strpos( $target, '/' ) !== false ) {
                        # An old subpage, drill down to the user behind it
                        $parts = explode( '/', $target );
                        $target = $parts[0];
@@ -1193,7 +1193,7 @@ class Block {
 
        /**
         * Set the user who implemented (or will implement) this block
-        * @param $user User|string Local User object or username string for foriegn users
+        * @param $user User|string Local User object or username string for foreign users
         */
        public function setBlocker( $user ) {
                $this->blocker = $user;