https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114672
Revision: 114672
Author: aaron
Date: 2012-04-02 23:22:07 +0000 (Mon, 02 Apr 2012)
Log Message:
-----------
(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: branches/wmf/1.19wmf1/includes/Block.php
===================================================================
--- branches/wmf/1.19wmf1/includes/Block.php 2012-04-02 22:59:06 UTC (rev
114671)
+++ branches/wmf/1.19wmf1/includes/Block.php 2012-04-02 23:22:07 UTC (rev
114672)
@@ -33,6 +33,9 @@
/// @var User|String
protected $target;
+ // @var Integer Hack for foreign blocking (CentralAuth)
+ protected $forcedTargetID;
+
/// @var Block::TYPE_ constant. Can only be USER, IP or RANGE
internally
protected $type;
@@ -72,7 +75,7 @@
$this->setTarget( $address );
if ( $this->target instanceof User && $user ) {
- $this->target->setId( $user ); // needed for foreign
users
+ $this->forcedTargetID = $user; // needed for foreign
users
}
if ( $by ) { // local user
$this->setBlocker( User::newFromID( $by ) );
@@ -483,9 +486,15 @@
}
$expiry = $db->encodeExpiry( $this->mExpiry );
+ if ( $this->forcedTargetID ) {
+ $uid = $this->forcedTargetID;
+ } else {
+ $uid = $this->target instanceof User ?
$this->target->getID() : 0;
+ }
+
$a = array(
'ipb_address' => (string)$this->target,
- 'ipb_user' => $this->target instanceof User
? $this->target->getID() : 0,
+ 'ipb_user' => $uid,
'ipb_by' => $this->getBy(),
'ipb_by_text' => $this->getByName(),
'ipb_reason' => $this->mReason,
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs