Index: trunk/phase3/includes/Block.php |
— | — | @@ -405,26 +405,8 @@ |
406 | 406 | wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); |
407 | 407 | $dbw = wfGetDB( DB_MASTER ); |
408 | 408 | |
409 | | - # Unset ipb_anon_only for user blocks, makes no sense |
410 | | - if ( $this->mUser ) { |
411 | | - $this->mAnonOnly = 0; |
412 | | - } |
| 409 | + $this->validateBlockParams(); |
413 | 410 | |
414 | | - # Unset ipb_enable_autoblock for IP blocks, makes no sense |
415 | | - if ( !$this->mUser ) { |
416 | | - $this->mEnableAutoblock = 0; |
417 | | - $this->mBlockEmail = 0; //Same goes for email... |
418 | | - } |
419 | | - |
420 | | - if( !$this->mByName ) { |
421 | | - if( $this->mBy ) { |
422 | | - $this->mByName = User::whoIs( $this->mBy ); |
423 | | - } else { |
424 | | - global $wgUser; |
425 | | - $this->mByName = $wgUser->getName(); |
426 | | - } |
427 | | - } |
428 | | - |
429 | 411 | # Don't collide with expired blocks |
430 | 412 | Block::purgeExpired(); |
431 | 413 | |
— | — | @@ -458,6 +440,64 @@ |
459 | 441 | } |
460 | 442 | |
461 | 443 | /** |
| 444 | + * Update block with new parameters. |
| 445 | + */ |
| 446 | + public function update() { |
| 447 | + wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" ); |
| 448 | + $dbw = wfGetDB( DB_MASTER ); |
| 449 | + |
| 450 | + $this->validateBlockParams(); |
| 451 | + |
| 452 | + $dbw->update( 'ipblocks', |
| 453 | + array( |
| 454 | + 'ipb_user' => $this->mUser, |
| 455 | + 'ipb_by' => $this->mBy, |
| 456 | + 'ipb_by_text' => $this->mByName, |
| 457 | + 'ipb_reason' => $this->mReason, |
| 458 | + 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), |
| 459 | + 'ipb_auto' => $this->mAuto, |
| 460 | + 'ipb_anon_only' => $this->mAnonOnly, |
| 461 | + 'ipb_create_account' => $this->mCreateAccount, |
| 462 | + 'ipb_enable_autoblock' => $this->mEnableAutoblock, |
| 463 | + 'ipb_expiry' => self::encodeExpiry( $this->mExpiry, $dbw ), |
| 464 | + 'ipb_range_start' => $this->mRangeStart, |
| 465 | + 'ipb_range_end' => $this->mRangeEnd, |
| 466 | + 'ipb_deleted' => $this->mHideName, |
| 467 | + 'ipb_block_email' => $this->mBlockEmail ), |
| 468 | + array( 'ipb_id' => $this->mId ), |
| 469 | + 'Block::update' ); |
| 470 | + |
| 471 | + return $dbw->affectedRows(); |
| 472 | + } |
| 473 | + |
| 474 | + /** |
| 475 | + * Make sure all the proper members are set to sane values |
| 476 | + * before adding/updating a block |
| 477 | + */ |
| 478 | + private function validateBlockParams() { |
| 479 | + # Unset ipb_anon_only for user blocks, makes no sense |
| 480 | + if ( $this->mUser ) { |
| 481 | + $this->mAnonOnly = 0; |
| 482 | + } |
| 483 | + |
| 484 | + # Unset ipb_enable_autoblock for IP blocks, makes no sense |
| 485 | + if ( !$this->mUser ) { |
| 486 | + $this->mEnableAutoblock = 0; |
| 487 | + $this->mBlockEmail = 0; //Same goes for email... |
| 488 | + } |
| 489 | + |
| 490 | + if( !$this->mByName ) { |
| 491 | + if( $this->mBy ) { |
| 492 | + $this->mByName = User::whoIs( $this->mBy ); |
| 493 | + } else { |
| 494 | + global $wgUser; |
| 495 | + $this->mByName = $wgUser->getName(); |
| 496 | + } |
| 497 | + } |
| 498 | + } |
| 499 | + |
| 500 | + |
| 501 | + /** |
462 | 502 | * Retroactively autoblocks the last IP used by the user (if it is a user) |
463 | 503 | * blocked by this Block. |
464 | 504 | * @return bool Whether or not a retroactive autoblock was made. |
— | — | @@ -806,11 +846,8 @@ |
807 | 847 | |
808 | 848 | /** |
809 | 849 | * Convert a DB-encoded expiry into a real string that humans can read. |
810 | | - * @param |
| 850 | + * @param $encoded_expiry string Database encoded expiry time |
811 | 851 | * @return string |
812 | | - * @todo @fixme This is nasty. Forces a msg on the expiry, which isn't what |
813 | | - * we want. Probably want to abstract out the number formatting so it can |
814 | | - * be used elsewhere (some bug I forgot and can't find at the moment) |
815 | 852 | */ |
816 | 853 | static function formatExpiry( $encoded_expiry ) { |
817 | 854 | |