* Insert a block into the block table. Will fail if there is a conflicting
* block (same name and options) already in the database.
*
- * @return Boolean: whether or not the insertion was successful.
+ * @return mixed: false on failure, assoc array on success:
+ * ('id' => block ID, 'autoId' => autoblock ID or false)
*/
public function insert( $dbw = null ) {
wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
);
$affected = $dbw->affectedRows();
- if ( $affected )
- $this->doRetroactiveAutoblock();
+ if ( $affected ) {
+ $auto_ipd_id = $this->doRetroactiveAutoblock();
+ return array( 'id' => $ipb_id, 'autoId' => $auto_ipd_id );
+ }
- return (bool)$affected;
+ return false;
}
/**
* Retroactively autoblocks the last IP used by the user (if it is a user)
* blocked by this Block.
*
- * @return Boolean: whether or not a retroactive autoblock was made.
+ * @return mixed: block ID if a retroactive autoblock was made, false if not.
*/
protected function doRetroactiveAutoblock() {
$dbr = wfGetDB( DB_SLAVE );
} else {
foreach ( $res as $row ) {
if ( $row->rc_ip ) {
- $this->doAutoblock( $row->rc_ip );
+ return $this->doAutoblock( $row->rc_ip );
}
}
}
}
+ return false;
}
/**
* Autoblocks the given IP, referring to this Block.
*
* @param $autoblockIP String: the IP to autoblock.
- * @param $justInserted Boolean: the main block was just inserted
- * @return Boolean: whether or not an autoblock was inserted.
+ * @param $justInserted Boolean: the main block was just inserted.
+ * @return mixed: block ID if an autoblock was inserted, false if not.
*/
public function doAutoblock( $autoblockIP, $justInserted = false ) {
# If autoblocks are disabled, go away.
if ( !$this->mEnableAutoblock ) {
- return;
+ return false;
}
# Check for presence on the autoblock whitelist
if ( Block::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
- return;
+ return false;
}
# # Allow hooks to cancel the autoblock.
if ( $this->mExpiry &&
( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) )
) {
- return;
+ return false;
}
# Just update the timestamp
$ipblock->updateTimestamp();
}
- return;
+ return false;
} else {
$ipblock = new Block;
}
}
# Insert it
- return $ipblock->insert();
+ $status = $ipblock->insert();
+ return $status ? $status['id'] : false;
}
/**
}
# Try to insert block. Is there a conflicting block?
- if( !$block->insert() ) {
-
+ $status = $block->insert();
+ if( !$status ) {
# Show form unless the user is already aware of this...
if( !$data['AlreadyBlocked'] ) {
return array( array( 'ipb_already_blocked', $data['Target'] ) );
-
# Otherwise, try to update the block...
} else {
-
# This returns direct blocks before autoblocks/rangeblocks, since we should
# be sure the user is blocked by now it should work for our purposes
$currentBlock = Block::newFromTarget( $target );
}
$currentBlock->delete();
- $block->insert();
+ $status = $block->insert();
$logaction = 'reblock';
# Unset _deleted fields if requested
$data['HideUser'] = true;
}
}
-
} else {
$logaction = 'block';
}
# Make log entry, if the name is hidden, put it in the oversight log
$log_type = $data['HideUser'] ? 'suppress' : 'block';
$log = new LogPage( $log_type );
- $log->addEntry(
+ $log_id = $log->addEntry(
$logaction,
Title::makeTitle( NS_USER, $target ),
$data['Reason'][0],
$logParams
);
+ # Relate log ID to block IDs (bug 25763)
+ $blockIds = array( $status['id'] ); // main block
+ if ( $status['autoId'] ) {
+ $blockIds[] = $status['autoId']; // automatic block
+ }
+ $log->addRelations( 'ipb_id', $blockIds, $log_id );
# Report to the user
return true;