Index: trunk/phase3/maintenance/archives/patch-rc_user_text-index.sql |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +-- Add an index to recentchanges on rc_user_text |
| 3 | +-- |
| 4 | +-- Added 2006-11-08 |
| 5 | +-- |
| 6 | + |
| 7 | + ALTER TABLE /*$wgDBprefix*/recentchanges |
| 8 | +ADD INDEX rc_user_text(rc_user_text, rc_timestamp); |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/archives/patch-rc_user_text-index.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 9 | + native |
Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -779,8 +779,20 @@ |
780 | 780 | dbsource( archive( 'patch-recentchanges-utindex.sql' ) ); |
781 | 781 | } else { |
782 | 782 | # Index seems to exist |
783 | | - echo( "...seems to be ok\n" ); |
| 783 | + echo( "...index on ( rc_namespace, rc_user_text ) seems to be ok\n" ); |
784 | 784 | } |
| 785 | + |
| 786 | + #Add (rc_user_text, rc_timestamp) index [A. Garrett], November 2006 |
| 787 | + # See if we can find the index we want |
| 788 | + $info = $wgDatabase->indexInfo( 'recentchanges', 'rc_user_text', __METHOD__ ); |
| 789 | + if( !$info ) { |
| 790 | + # None, so create |
| 791 | + echo( "...index on ( rc_user_text, rc_timestamp ) not found; creating\n" ); |
| 792 | + dbsource( archive( 'patch-rc_user_text-index.sql' ) ); |
| 793 | + } else { |
| 794 | + # Index seems to exist |
| 795 | + echo( "...index on ( rc_user_text, rc_timestamp ) seems to be ok\n" ); |
| 796 | + } |
785 | 797 | } |
786 | 798 | |
787 | 799 | function do_all_updates( $doShared = false ) { |
Index: trunk/phase3/maintenance/tables.sql |
— | — | @@ -804,7 +804,8 @@ |
805 | 805 | INDEX rc_cur_id (rc_cur_id), |
806 | 806 | INDEX new_name_timestamp (rc_new,rc_namespace,rc_timestamp), |
807 | 807 | INDEX rc_ip (rc_ip), |
808 | | - INDEX rc_ns_usertext (rc_namespace, rc_user_text) |
| 808 | + INDEX rc_ns_usertext (rc_namespace, rc_user_text), |
| 809 | + INDEX rc_user_text (rc_user_text, rc_timestamp) |
809 | 810 | |
810 | 811 | ) TYPE=InnoDB; |
811 | 812 | |
Index: trunk/phase3/includes/User.php |
— | — | @@ -1924,46 +1924,8 @@ |
1925 | 1925 | return; |
1926 | 1926 | } |
1927 | 1927 | |
1928 | | - if ( !$userblock->mEnableAutoblock ) { |
1929 | | - return; |
1930 | | - } |
| 1928 | + $userblock->doAutoblock( wfGetIp() ); |
1931 | 1929 | |
1932 | | - # Check if this IP address is already blocked |
1933 | | - $ipblock = Block::newFromDB( wfGetIP() ); |
1934 | | - if ( $ipblock ) { |
1935 | | - # If the user is already blocked. Then check if the autoblock would |
1936 | | - # exceed the user block. If it would exceed, then do nothing, else |
1937 | | - # prolong block time |
1938 | | - if ($userblock->mExpiry && |
1939 | | - ($userblock->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp))) { |
1940 | | - return; |
1941 | | - } |
1942 | | - # Just update the timestamp |
1943 | | - $ipblock->updateTimestamp(); |
1944 | | - return; |
1945 | | - } else { |
1946 | | - $ipblock = new Block; |
1947 | | - } |
1948 | | - |
1949 | | - # Make a new block object with the desired properties |
1950 | | - wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" ); |
1951 | | - $ipblock->mAddress = wfGetIP(); |
1952 | | - $ipblock->mUser = 0; |
1953 | | - $ipblock->mBy = $userblock->mBy; |
1954 | | - $ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason ); |
1955 | | - $ipblock->mTimestamp = wfTimestampNow(); |
1956 | | - $ipblock->mAuto = 1; |
1957 | | - # If the user is already blocked with an expiry date, we don't |
1958 | | - # want to pile on top of that! |
1959 | | - if($userblock->mExpiry) { |
1960 | | - $ipblock->mExpiry = min ( $userblock->mExpiry, Block::getAutoblockExpiry( $ipblock->mTimestamp )); |
1961 | | - } else { |
1962 | | - $ipblock->mExpiry = Block::getAutoblockExpiry( $ipblock->mTimestamp ); |
1963 | | - } |
1964 | | - |
1965 | | - # Insert it |
1966 | | - $ipblock->insert(); |
1967 | | - |
1968 | 1930 | } |
1969 | 1931 | |
1970 | 1932 | /** |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -356,6 +356,10 @@ |
357 | 357 | return $dbw->affectedRows() > 0; |
358 | 358 | } |
359 | 359 | |
| 360 | + /** |
| 361 | + * Insert a block into the block table. |
| 362 | + *@return Whether or not the insertion was successful. |
| 363 | + */ |
360 | 364 | function insert() |
361 | 365 | { |
362 | 366 | wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); |
— | — | @@ -395,9 +399,89 @@ |
396 | 400 | ); |
397 | 401 | $affected = $dbw->affectedRows(); |
398 | 402 | $dbw->commit(); |
| 403 | + |
| 404 | + $this->doRetroactiveAutoblock(); |
| 405 | + |
399 | 406 | return $affected; |
400 | 407 | } |
401 | 408 | |
| 409 | + /** |
| 410 | + * Retroactively autoblocks the last IP used by the user (if it is a user) |
| 411 | + * blocked by this Block. |
| 412 | + *@return Whether or not a retroactive autoblock was made. |
| 413 | + */ |
| 414 | + function doRetroactiveAutoblock() { |
| 415 | + $dbr = wfGetDb( DB_SLAVE ); |
| 416 | + #If autoblock is enabled, autoblock the LAST IP used |
| 417 | + # - stolen shamelessly from CheckUser_body.php |
| 418 | + |
| 419 | + if ($this->mEnableAutoblock && $this->mUser) { |
| 420 | + wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n"); |
| 421 | + |
| 422 | + $row = $dbr->selectRow( 'recentchanges', array( 'rc_ip' ), array( 'rc_user_text' => $this->mAddress ), |
| 423 | + $fname, array( 'ORDER BY' => 'rc_timestamp DESC' ) ); |
| 424 | + |
| 425 | + if ( !$row || !$row->rc_ip ) { |
| 426 | + #No results, don't autoblock anything |
| 427 | + wfDebug("No IP found to retroactively autoblock\n"); |
| 428 | + } else { |
| 429 | + #Limit is 1, so no loop needed. |
| 430 | + $retroblockip = $row->rc_ip; |
| 431 | + return $this->doAutoblock($retroblockip); |
| 432 | + } |
| 433 | + } |
| 434 | + } |
| 435 | + |
| 436 | + /** |
| 437 | + * Autoblocks the given IP, referring to this Block. |
| 438 | + *@param $autoblockip The IP to autoblock. |
| 439 | + *@return Whether or not an autoblock was inserted. |
| 440 | + */ |
| 441 | + function doAutoblock( $autoblockip ) { |
| 442 | + # Check if this IP address is already blocked |
| 443 | + $dbw =& wfGetDb( DB_MASTER ); |
| 444 | + $dbw->begin(); |
| 445 | + |
| 446 | + if ( !$this->mEnableAutoblock ) { |
| 447 | + return; |
| 448 | + } |
| 449 | + |
| 450 | + $ipblock = Block::newFromDB( $autoblockip ); |
| 451 | + if ( $ipblock ) { |
| 452 | + # If the user is already blocked. Then check if the autoblock would |
| 453 | + # exceed the user block. If it would exceed, then do nothing, else |
| 454 | + # prolong block time |
| 455 | + if ($this->mExpiry && |
| 456 | + ($this->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp))) { |
| 457 | + return; |
| 458 | + } |
| 459 | + # Just update the timestamp |
| 460 | + $ipblock->updateTimestamp(); |
| 461 | + return; |
| 462 | + } else { |
| 463 | + $ipblock = new Block; |
| 464 | + } |
| 465 | + |
| 466 | + # Make a new block object with the desired properties |
| 467 | + wfDebug( "Autoblocking {$this->mAddress}@" . $autoblockip . "\n" ); |
| 468 | + $ipblock->mAddress = $autoblockip; |
| 469 | + $ipblock->mUser = 0; |
| 470 | + $ipblock->mBy = $this->mBy; |
| 471 | + $ipblock->mReason = wfMsgForContent( 'autoblocker', $this->mAddress, $this->mReason ); |
| 472 | + $ipblock->mTimestamp = wfTimestampNow(); |
| 473 | + $ipblock->mAuto = 1; |
| 474 | + |
| 475 | + # If the user is already blocked with an expiry date, we don't |
| 476 | + # want to pile on top of that! |
| 477 | + if($this->mExpiry) { |
| 478 | + $ipblock->mExpiry = min ( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp )); |
| 479 | + } else { |
| 480 | + $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp ); |
| 481 | + } |
| 482 | + # Insert it |
| 483 | + return $ipblock->insert(); |
| 484 | + } |
| 485 | + |
402 | 486 | function deleteIfExpired() |
403 | 487 | { |
404 | 488 | $fname = 'Block::deleteIfExpired'; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -153,8 +153,11 @@ |
154 | 154 | if they have selected that option in preferences. |
155 | 155 | * (bug 5936) Show an 'm' to the left of the edit summary on diff pages for minor edits. |
156 | 156 | * (bug 7820) Improve error reporting for uploads via URL. |
| 157 | +* (bug 5149) When autoblocks are enabled, retroactively apply an autoblock to the most |
| 158 | + recently used IP of a user when they are blocked. |
| 159 | +* Add an index on (rc_user_text,rc_timestamp) on the recentchanges table. This will |
| 160 | + make CheckUser.php and the new retroactive autoblock functionality faster. |
157 | 161 | |
158 | | - |
159 | 162 | == Languages updated == |
160 | 163 | |
161 | 164 | * Bishnupriya Manipuri (bpy) |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -1770,7 +1770,7 @@ |
1771 | 1771 | 'ipbreason' => 'Reason', |
1772 | 1772 | 'ipbanononly' => 'Block anonymous users only', |
1773 | 1773 | 'ipbcreateaccount' => 'Prevent account creation', |
1774 | | -'ipbenableautoblock' => 'Automatically block IP addresses used by this user', |
| 1774 | +'ipbenableautoblock' => 'Automatically block the last IP address used by this user, and any subsequent addresses they try to edit from', |
1775 | 1775 | 'ipbsubmit' => 'Block this user', |
1776 | 1776 | 'ipbother' => 'Other time', |
1777 | 1777 | 'ipboptions' => '2 hours:2 hours,1 day:1 day,3 days:3 days,1 week:1 week,2 weeks:2 weeks,1 month:1 month,3 months:3 months,6 months:6 months,1 year:1 year,infinite:infinite', |