r41118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41117‎ | r41118 | r41119 >
Date:15:16, 21 September 2008
Author:demon
Status:old
Tags:
Comment:
More block updates:
* Improve docs (formatExpiry() is fine, abstracting wouldn't do anything, as it would just become a wrapper for $wgLang->timeanddate())
* Abstract out some param validation from insert()
* Add an update() method to make modification of existing blocks a bit nicer.
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Block.php
@@ -405,26 +405,8 @@
406406 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
407407 $dbw = wfGetDB( DB_MASTER );
408408
409 - # Unset ipb_anon_only for user blocks, makes no sense
410 - if ( $this->mUser ) {
411 - $this->mAnonOnly = 0;
412 - }
 409+ $this->validateBlockParams();
413410
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 -
429411 # Don't collide with expired blocks
430412 Block::purgeExpired();
431413
@@ -458,6 +440,64 @@
459441 }
460442
461443 /**
 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+ /**
462502 * Retroactively autoblocks the last IP used by the user (if it is a user)
463503 * blocked by this Block.
464504 * @return bool Whether or not a retroactive autoblock was made.
@@ -806,11 +846,8 @@
807847
808848 /**
809849 * Convert a DB-encoded expiry into a real string that humans can read.
810 - * @param
 850+ * @param $encoded_expiry string Database encoded expiry time
811851 * @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)
815852 */
816853 static function formatExpiry( $encoded_expiry ) {
817854

Status & tagging log