$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
/**
* 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 ) {
/**
* 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 ) {
* 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 has
- * gone slightly awry
+ * @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" );
$dbw = wfGetDB( DB_MASTER );
+ $dbw->startAtomic( __METHOD__ );
+
$dbw->update(
'ipblocks',
$this->getDatabaseArray( $dbw ),
__METHOD__
);
- return $dbw->affectedRows();
+ $affected = $dbw->affectedRows();
+
+ 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__ );
+
+ if ( $affected ) {
+ $auto_ipd_ids = $this->doRetroactiveAutoblock();
+ return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
+ }
+
+ return false;
}
/**
return $a;
}
+ /**
+ * @return Array
+ */
+ protected function getAutoblockUpdateArray() {
+ return array(
+ 'ipb_by' => $this->getBy(),
+ 'ipb_by_text' => $this->getByName(),
+ 'ipb_reason' => $this->mReason,
+ 'ipb_create_account' => $this->prevents( 'createaccount' ),
+ 'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite
+ 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
+ );
+ }
+
/**
* Retroactively autoblocks the last IP used by the user (if it is a user)
* blocked by this 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;
/**
* 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 );
# 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 );