(Bug 17970) {{PROTECTIONLEVEL}} should be able to return the status for pages besides...
[lhc/web/wiklou.git] / includes / Block.php
index 86b4d13..b81cf3a 100644 (file)
@@ -69,7 +69,7 @@ class Block {
                        $timestamp = wfTimestampNow();
                }
 
-               if( count( func_get_args() ) > 0 ){
+               if( count( func_get_args() ) > 0 ) {
                        # Soon... :D
                        # wfDeprecated( __METHOD__ . " with arguments" );
                }
@@ -164,7 +164,7 @@ class Block {
 
        /**
         * Check if two blocks are effectively equal.  Doesn't check irrelevant things like
-        * the blocking user or the block timestamp, only things which affect the blocked user   *
+        * the blocking user or the block timestamp, only things which affect the blocked user
         *
         * @param $block Block
         *
@@ -418,7 +418,7 @@ class Block {
         * @param  $row ResultWrapper row from the ipblocks table
         * @return Block
         */
-       public static function newFromRow( $row ){
+       public static function newFromRow( $row ) {
                $block = new Block;
                $block->initFromRow( $row );
                return $block;
@@ -510,7 +510,7 @@ class Block {
         * @param $db DatabaseBase
         * @return Array
         */
-       protected function getDatabaseArray( $db = null ){
+       protected function getDatabaseArray( $db = null ) {
                if( !$db ){
                        $db = wfGetDB( DB_SLAVE );
                }
@@ -536,10 +536,10 @@ class Block {
                        'ipb_expiry'           => $expiry,
                        'ipb_range_start'      => $this->getRangeStart(),
                        'ipb_range_end'        => $this->getRangeEnd(),
-                       'ipb_deleted'          => intval( $this->mHideName ), // typecast required for SQLite
+                       'ipb_deleted'          => intval( $this->mHideName ), // typecast required for SQLite
                        'ipb_block_email'      => $this->prevents( 'sendemail' ),
                        'ipb_allow_usertalk'   => !$this->prevents( 'editownusertalk' ),
-                       'ipb_parent_block_id'            => $this->mParentBlockId
+                       'ipb_parent_block_id'  => $this->mParentBlockId
                );
 
                return $a;
@@ -576,6 +576,13 @@ class Block {
         * @return Array: block IDs of retroactive autoblocks made
         */
        protected static function defaultRetroactiveAutoblock( Block $block, array &$blockIds ) {
+               global $wgPutIPinRC;
+
+               // No IPs are in recentchanges table, so nothing to select
+               if( !$wgPutIPinRC ) {
+                       return;
+               }
+
                $dbr = wfGetDB( DB_SLAVE );
 
                $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
@@ -587,7 +594,7 @@ class Block {
                $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
                        __METHOD__ ,  $options );
 
-               if ( !$dbr->numRows( $res ) ) {
+               if ( !$res->numRows() ) {
                        # No results, don't autoblock anything
                        wfDebug( "No IP found to retroactively autoblock\n" );
                } else {
@@ -689,7 +696,7 @@ class Block {
                wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
                $autoblock->setTarget( $autoblockIP );
                $autoblock->setBlocker( $this->getBlocker() );
-               $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )->inContentLanguage()->text();
+               $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )->inContentLanguage()->plain();
                $timestamp = wfTimestampNow();
                $autoblock->mTimestamp = $timestamp;
                $autoblock->mAuto = 1;
@@ -990,9 +997,11 @@ class Block {
         * Purge expired blocks from the ipblocks table
         */
        public static function purgeExpired() {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->delete( 'ipblocks',
-                       array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
+               if ( !wfReadOnly() ) {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $dbw->delete( 'ipblocks',
+                               array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
+               }
        }
 
        /**
@@ -1050,7 +1059,7 @@ class Block {
                        # passed by some callers (bug 29116)
                        return null;
 
-               } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE ) ) ) {
+               } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
                        $block = new Block();
                        $block->fromMaster( $fromMaster );
 
@@ -1066,12 +1075,13 @@ class Block {
        }
 
        /**
-        * From an existing Block, get the target and the type of target.  Note that it is
-        * always safe to treat the target as a string; for User objects this will return
-        * User::__toString() which in turn gives User::getName().
+        * From an existing Block, get the target and the type of target.
+        * Note that, except for null, it is always safe to treat the target
+        * as a string; for User objects this will return User::__toString()
+        * which in turn gives User::getName().
         *
-        * @param $target String|Int|User
-        * @return array( User|String, Block::TYPE_ constant )
+        * @param $target String|Int|User|null
+        * @return array( User|String|null, Block::TYPE_ constant|null )
         */
        public static function parseTarget( $target ) {
                # We may have been through this before
@@ -1169,7 +1179,7 @@ class Block {
         * Set the target for this block, and update $this->type accordingly
         * @param $target Mixed
         */
-       public function setTarget( $target ){
+       public function setTarget( $target ) {
                list( $this->target, $this->type ) = self::parseTarget( $target );
        }
 
@@ -1177,7 +1187,7 @@ class Block {
         * Get the user who implemented this block
         * @return User|string Local User object or string for a foreign user
         */
-       public function getBlocker(){
+       public function getBlocker() {
                return $this->blocker;
        }
 
@@ -1185,7 +1195,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
         */
-       public function setBlocker( $user ){
+       public function setBlocker( $user ) {
                $this->blocker = $user;
        }
 }