r84588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84587‎ | r84588 | r84589 >
Date:00:10, 23 March 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Try to untangle the autoblock time logic, which made very little sense and led to very old indefinite blocks triggering autoblocks with ipb_expiry < ipb_timestamp.
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Block.php
@@ -562,10 +562,9 @@
563563 * Autoblocks the given IP, referring to this Block.
564564 *
565565 * @param $autoblockIP String: the IP to autoblock.
566 - * @param $justInserted Boolean: the main block was just inserted.
567566 * @return mixed: block ID if an autoblock was inserted, false if not.
568567 */
569 - public function doAutoblock( $autoblockIP, $justInserted = false ) {
 568+ public function doAutoblock( $autoblockIP ) {
570569 # If autoblocks are disabled, go away.
571570 if ( !$this->isAutoblocking() ) {
572571 return false;
@@ -589,45 +588,44 @@
590589 # If the user is already blocked. Then check if the autoblock would
591590 # exceed the user block. If it would exceed, then do nothing, else
592591 # prolong block time
593 - if ( $this->mExpiry &&
594 - ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) )
 592+ if ( $this->mExpiry > Block::getAutoblockExpiry( $ipblock->mTimestamp )
595593 ) {
596 - return false;
597 - }
598 -
599 - # Just update the timestamp
600 - if ( !$justInserted ) {
 594+ # If the block is an autoblock, reset its timestamp to now and its expiry
 595+ # to an $wgAutoblockExpiry in the future; otherwise do nothing
601596 $ipblock->updateTimestamp();
602597 }
603 -
604598 return false;
605 - } else {
606 - $ipblock = new Block;
 599+
607600 }
608601
609602 # Make a new block object with the desired properties
 603+ $autoblock = new Block;
610604 wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
611 - $ipblock->setTarget( $autoblockIP );
612 - $ipblock->setBlocker( $this->getBlocker() );
613 - $ipblock->mReason = wfMsgForContent( 'autoblocker', $this->getTarget(), $this->mReason );
614 - $ipblock->mTimestamp = wfTimestampNow();
615 - $ipblock->mAuto = 1;
616 - $ipblock->mCreateAccount = $this->mCreateAccount;
 605+ $autoblock->setTarget( $autoblockIP );
 606+ $autoblock->setBlocker( $this->getBlocker() );
 607+ $autoblock->mReason = wfMsgForContent( 'autoblocker', $this->getTarget(), $this->mReason );
 608+ $autoblock->mTimestamp = wfTimestampNow();
 609+ $autoblock->mAuto = 1;
 610+ $autoblock->prevents( 'createaccount', $this->prevents( 'createaccount' ) );
617611 # Continue suppressing the name if needed
618 - $ipblock->mHideName = $this->mHideName;
619 - $ipblock->mDisableUsertalk = $this->mDisableUsertalk;
 612+ $autoblock->mHideName = $this->mHideName;
 613+ $autoblock->prevents( 'editownusertalk', $this->prevents( 'editownusertalk' ) );
620614
621 - # If the user is already blocked with an expiry date, we don't
622 - # want to pile on top of that!
623 - if ( $this->mExpiry ) {
624 - $ipblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp ) );
 615+ $dbr = wfGetDB( DB_READ );
 616+ if ( $this->mTimestamp == $dbr->getInfinity() ) {
 617+ # Original block was indefinite, start an autoblock now
 618+ $autoblock->mExpiry = Block::getAutoblockExpiry( wfTimestampNow() );
625619 } else {
626 - $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
 620+ # If the user is already blocked with an expiry date, we don't
 621+ # want to pile on top of that.
 622+ $autoblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( wfTimestampNow() ) );
627623 }
628624
629625 # Insert it
630 - $status = $ipblock->insert();
631 - return $status ? $status['id'] : false;
 626+ $status = $autoblock->insert();
 627+ return $status
 628+ ? $status['id']
 629+ : false;
632630 }
633631
634632 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r90860Follow-up r84588 CRhappy-melon23:10, 26 June 2011

Comments

#Comment by Duplicatebug (talk | contribs)   14:25, 23 April 2011

DB_READ is obsolete

#Comment by Aaron Schulz (talk | contribs)   00:38, 18 June 2011
+  if ( $this->mTimestamp == $dbr->getInfinity() ) {

Shouldn't that be comparing mExpiry?

#Comment by Happy-melon (talk | contribs)   23:11, 26 June 2011

In a word, "yes". DB_READ was replaced at some point since this revision.

Status & tagging log