http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84523
Revision: 84523
Author: aaron
Date: 2011-03-22 11:22:15 +0000 (Tue, 22 Mar 2011)
Log Message:
-----------
Relate block log entries to block table rows (useful for bug 25763)
Modified Paths:
--------------
trunk/phase3/includes/Block.php
trunk/phase3/includes/specials/SpecialBlock.php
Modified: trunk/phase3/includes/Block.php
===================================================================
--- trunk/phase3/includes/Block.php 2011-03-22 11:14:11 UTC (rev 84522)
+++ trunk/phase3/includes/Block.php 2011-03-22 11:22:15 UTC (rev 84523)
@@ -487,7 +487,8 @@
* 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" );
@@ -528,10 +529,12 @@
);
$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;
}
/**
@@ -604,7 +607,7 @@
* 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 );
@@ -635,11 +638,12 @@
} else {
foreach ( $res as $row ) {
if ( $row->rc_ip ) {
- $this->doAutoblock( $row->rc_ip
);
+ return $this->doAutoblock(
$row->rc_ip );
}
}
}
}
+ return false;
}
/**
@@ -689,18 +693,18 @@
* 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.
@@ -719,7 +723,7 @@
if ( $this->mExpiry &&
( $this->mExpiry < Block::getAutoblockExpiry(
$ipblock->mTimestamp ) )
) {
- return;
+ return false;
}
# Just update the timestamp
@@ -727,7 +731,7 @@
$ipblock->updateTimestamp();
}
- return;
+ return false;
} else {
$ipblock = new Block;
}
@@ -755,7 +759,8 @@
}
# Insert it
- return $ipblock->insert();
+ $status = $ipblock->insert();
+ return $status ? $status['id'] : false;
}
/**
Modified: trunk/phase3/includes/specials/SpecialBlock.php
===================================================================
--- trunk/phase3/includes/specials/SpecialBlock.php 2011-03-22 11:14:11 UTC
(rev 84522)
+++ trunk/phase3/includes/specials/SpecialBlock.php 2011-03-22 11:22:15 UTC
(rev 84523)
@@ -553,15 +553,13 @@
}
# 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 );
@@ -577,7 +575,7 @@
}
$currentBlock->delete();
- $block->insert();
+ $status = $block->insert();
$logaction = 'reblock';
# Unset _deleted fields if requested
@@ -590,7 +588,6 @@
$data['HideUser'] = true;
}
}
-
} else {
$logaction = 'block';
}
@@ -619,12 +616,18 @@
# 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;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs