Merge "includes/Linker.php: Added hook for "Media:" links"
[lhc/web/wiklou.git] / includes / Block.php
index 3575b9d..a3d3691 100644 (file)
@@ -31,22 +31,22 @@ class Block {
                $mCreateAccount,
                $mParentBlockId;
 
-       /// @var User|String
+       /** @var User|String */
        protected $target;
 
-       // @var Integer Hack for foreign blocking (CentralAuth)
+       /** @var Integer Hack for foreign blocking (CentralAuth) */
        protected $forcedTargetID;
 
-       /// @var Block::TYPE_ constant.  Can only be USER, IP or RANGE internally
+       /** @var Integer Block::TYPE_ constant. Can only be USER, IP or RANGE internally */
        protected $type;
 
-       /// @var User
+       /** @var User */
        protected $blocker;
 
-       /// @var Bool
+       /** @var Bool */
        protected $isHardblock = true;
 
-       /// @var Bool
+       /** @var Bool */
        protected $isAutoblocking = true;
 
        # TYPE constants
@@ -312,7 +312,7 @@ class Block {
        /**
         * Get the component of an IP address which is certain to be the same between an IP
         * address and a rangeblock containing that IP address.
-        * @param  $hex String Hexadecimal IP representation
+        * @param $hex String Hexadecimal IP representation
         * @return String
         */
        protected static function getIpFragment( $hex ) {
@@ -362,7 +362,7 @@ class Block {
 
        /**
         * Create a new Block object from a database row
-        * @param  $row ResultWrapper row from the ipblocks table
+        * @param $row ResultWrapper row from the ipblocks table
         * @return Block
         */
        public static function newFromRow( $row ) {
@@ -435,7 +435,8 @@ class Block {
         * Update a block in the DB with new parameters.
         * The ID field needs to be loaded first.
         *
-        * @return bool|array False on failure, array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs)
+        * @return bool|array False on failure, array on success:
+        *   ('id' => block ID, 'autoIds' => array of autoblock IDs)
         */
        public function update() {
                wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" );
@@ -452,12 +453,22 @@ class Block {
 
                $affected = $dbw->affectedRows();
 
-               $dbw->update(
-                       'ipblocks',
-                       $this->getAutoblockUpdateArray(),
-                       array( 'ipb_parent_block_id' => $this->getId() ),
-                       __METHOD__
-               );
+               if ( $this->isAutoblocking() ) {
+                       // update corresponding autoblock(s) (bug 48813)
+                       $dbw->update(
+                               'ipblocks',
+                               $this->getAutoblockUpdateArray(),
+                               array( 'ipb_parent_block_id' => $this->getId() ),
+                               __METHOD__
+                       );
+               } else {
+                       // autoblock no longer required, delete corresponding autoblock(s)
+                       $dbw->delete(
+                               'ipblocks',
+                               array( 'ipb_parent_block_id' => $this->getId() ),
+                               __METHOD__
+                       );
+               }
 
                $dbw->endAtomic( __METHOD__ );
 
@@ -676,7 +687,8 @@ class Block {
                wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
                $autoblock->setTarget( $autoblockIP );
                $autoblock->setBlocker( $this->getBlocker() );
-               $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )->inContentLanguage()->plain();
+               $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )
+                       ->inContentLanguage()->plain();
                $timestamp = wfTimestampNow();
                $autoblock->mTimestamp = $timestamp;
                $autoblock->mAuto = 1;
@@ -850,7 +862,7 @@ class Block {
        /**
         * Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range
         * @param $x Bool
-        * @return  Bool
+        * @return Bool
         */
        public function isHardblock( $x = null ) {
                wfSetVar( $this->isHardblock, $x );
@@ -973,7 +985,10 @@ class Block {
                        # passed by some callers (bug 29116)
                        return null;
 
-               } elseif ( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
+               } elseif ( in_array(
+                       $type,
+                       array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) )
+               ) {
                        $block = new Block();
                        $block->fromMaster( $fromMaster );