r114672 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114671‎ | r114672 | r114673 >
Date:23:22, 2 April 2012
Author:aaron
Status:ok
Tags:
Comment:
(bug 35011) Use the correct user name & ID for crosswiki blocks.

Previously (r112563), using setId() ensured the correct ID, but caused a reload of the name from the DB the script is running on (metawiki), which was broken as it was inserting blocks into other wikis.

Instead, the User object is now always made from the name, which works since Block uses User::newFromName() and that still returns a User object regardless of whether a user with the name exists on the wiki (metawiki). Additionally, if a user ID is passed into the Block constructor, a special 'forcedTargetID' field is set which is used as the user ID for DB insertions/updates. This is horribly hacky and needs refactoring some day...
Modified paths:
  • /branches/wmf/1.19wmf1/includes/Block.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/includes/Block.php
@@ -33,6 +33,9 @@
3434 /// @var User|String
3535 protected $target;
3636
 37+ // @var Integer Hack for foreign blocking (CentralAuth)
 38+ protected $forcedTargetID;
 39+
3740 /// @var Block::TYPE_ constant. Can only be USER, IP or RANGE internally
3841 protected $type;
3942
@@ -72,7 +75,7 @@
7376
7477 $this->setTarget( $address );
7578 if ( $this->target instanceof User && $user ) {
76 - $this->target->setId( $user ); // needed for foreign users
 79+ $this->forcedTargetID = $user; // needed for foreign users
7780 }
7881 if ( $by ) { // local user
7982 $this->setBlocker( User::newFromID( $by ) );
@@ -483,9 +486,15 @@
484487 }
485488 $expiry = $db->encodeExpiry( $this->mExpiry );
486489
 490+ if ( $this->forcedTargetID ) {
 491+ $uid = $this->forcedTargetID;
 492+ } else {
 493+ $uid = $this->target instanceof User ? $this->target->getID() : 0;
 494+ }
 495+
487496 $a = array(
488497 'ipb_address' => (string)$this->target,
489 - 'ipb_user' => $this->target instanceof User ? $this->target->getID() : 0,
 498+ 'ipb_user' => $uid,
490499 'ipb_by' => $this->getBy(),
491500 'ipb_by_text' => $this->getByName(),
492501 'ipb_reason' => $this->mReason,

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112563Force the target user ID to be the correct foreign ID on the relevant local w...aaron02:04, 28 February 2012

Status & tagging log