r84475 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84474‎ | r84475 | r84476 >
Date:19:12, 21 March 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Blame hashar for this giant commit; he teased me for making so many smaller ones earlier... :D
* Internalise $mAddress/$mUser, $mBy/$mByName, $mEnableAutoblock, $mId as getTarget(), getBlockers(), isAutoblocking(), getId().
* This required editing AbuseFilter and CheckUser backwards-incompatibly, so push the rest of the changes out to those extensions.
* Attack the evil 14-parameter constructor and gratuitously-confusing newFromDB( $notVeryImportantParameter, $moreImportantParameter)
* Reimplement the hack for bug 13611 in a slightly less fragile fashion; could still do with further cleanup, but then again the login frontend is its own can of worms... :S
* Remove transitionary getTargetAndType() and newFromTargetAndType() methods
* Some optimisation in parseTarget()
* Fix the broken phpunit test mentioned in r84251
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)
  • /trunk/extensions/regexBlock/regexBlockCore.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockme.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnblock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
@@ -53,12 +53,12 @@
5454 'user' => 'UTBlockee',
5555 'reason' => 'Some reason',
5656 'token' => $pageinfo['blocktoken'] ), $data );
 57+
 58+ $block = Block::newFromTarget('UTBlockee');
5759
58 - $block = Block::newFromDB('UTBlockee');
59 -
6060 $this->assertTrue( !is_null( $block ), 'Block is valid' );
6161
62 - $this->assertEquals( 'UTBlockee', $block->mAddress );
 62+ $this->assertEquals( 'UTBlockee', (string)$block->getTarget() );
6363 $this->assertEquals( 'Some reason', $block->mReason );
6464 $this->assertEquals( 'infinity', $block->mExpiry );
6565
Index: trunk/phase3/includes/User.php
@@ -1129,42 +1129,26 @@
11301130 $this->mHideName = 0;
11311131 $this->mAllowUsertalk = 0;
11321132
1133 - # Check if we are looking at an IP or a logged-in user
1134 - if ( $this->isAllowed( 'ipblock-exempt' ) ) {
1135 - # Exempt from all types of IP-block
1136 - $ip = '';
1137 - } elseif ( $this->isIP( $this->getName() ) ) {
1138 - $ip = $this->getName();
 1133+ # We only need to worry about passing the IP address to the Block generator if the
 1134+ # user is not immune to autoblocks/hardblocks, and they are the current user so we
 1135+ # know which IP address they're actually coming from
 1136+ if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
 1137+ $ip = wfGetIP();
11391138 } else {
1140 - # Check if we are looking at the current user
1141 - # If we don't, and the user is logged in, we don't know about
1142 - # his IP / autoblock status, so ignore autoblock of current user's IP
1143 - if ( $this->getID() != $wgUser->getID() ) {
1144 - $ip = '';
1145 - } else {
1146 - # Get IP of current user
1147 - $ip = wfGetIP();
1148 - }
 1139+ $ip = null;
11491140 }
11501141
11511142 # User/IP blocking
1152 - $this->mBlock = new Block();
1153 - $this->mBlock->fromMaster( !$bFromSlave );
1154 - if ( $this->mBlock->load( $ip , $this->mId ) ) {
 1143+ $this->mBlock = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
 1144+ if ( $this->mBlock instanceof Block ) {
11551145 wfDebug( __METHOD__ . ": Found block.\n" );
1156 - $this->mBlockedby = $this->mBlock->mBy;
1157 - if( $this->mBlockedby == 0 )
1158 - $this->mBlockedby = $this->mBlock->mByName;
 1146+ $this->mBlockedby = $this->mBlock->getBlocker()->getName();
11591147 $this->mBlockreason = $this->mBlock->mReason;
11601148 $this->mHideName = $this->mBlock->mHideName;
11611149 $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' );
11621150 if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) {
11631151 $this->spreadBlock();
11641152 }
1165 - } else {
1166 - // Bug 13611: don't remove mBlock here, to allow account creation blocks to
1167 - // apply to users. Note that the existence of $this->mBlock is not used to
1168 - // check for edit blocks, $this->mBlockedby is instead.
11691153 }
11701154
11711155 # Proxy blocking
@@ -1374,7 +1358,7 @@
13751359 */
13761360 function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site
13771361 $this->getBlockedStatus( $bFromSlave );
1378 - return $this->mBlockedby !== 0;
 1362+ return $this->mBlock instanceof Block && $this->mBlock->prevents( 'edit' );
13791363 }
13801364
13811365 /**
@@ -1427,7 +1411,7 @@
14281412 */
14291413 function getBlockId() {
14301414 $this->getBlockedStatus();
1431 - return ( $this->mBlock ? $this->mBlock->mId : false );
 1415+ return ( $this->mBlock ? $this->mBlock->getId() : false );
14321416 }
14331417
14341418 /**
@@ -2735,7 +2719,7 @@
27362720 return;
27372721 }
27382722
2739 - $userblock = Block::newFromDB( '', $this->mId );
 2723+ $userblock = Block::newFromTarget( $this->getName() );
27402724 if ( !$userblock ) {
27412725 return;
27422726 }
@@ -2797,11 +2781,24 @@
27982782
27992783 /**
28002784 * Get whether the user is explicitly blocked from account creation.
2801 - * @return Bool
 2785+ * @return Bool|Block
28022786 */
28032787 function isBlockedFromCreateAccount() {
28042788 $this->getBlockedStatus();
2805 - return $this->mBlock && $this->mBlock->prevents( 'createaccount' );
 2789+ if( $this->mBlock && $this->mBlock->prevents( 'createaccount' ) ){
 2790+ return $this->mBlock;
 2791+ }
 2792+
 2793+ # bug 13611: if the IP address the user is trying to create an account from is
 2794+ # blocked with createaccount disabled, prevent new account creation there even
 2795+ # when the user is logged in
 2796+ static $accBlock = false;
 2797+ if( $accBlock === false ){
 2798+ $accBlock = Block::newFromTarget( null, wfGetIP() );
 2799+ }
 2800+ return $accBlock instanceof Block && $accBlock->prevents( 'createaccount' )
 2801+ ? $accBlock
 2802+ : false;
28062803 }
28072804
28082805 /**
Index: trunk/phase3/includes/Article.php
@@ -1115,8 +1115,7 @@
11161116 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
11171117 # Don't index user and user talk pages for blocked users (bug 11443)
11181118 if ( !$this->mTitle->isSubpage() ) {
1119 - $block = new Block();
1120 - if ( $block->load( $this->mTitle->getText() ) ) {
 1119+ if ( Block::newFromTarget( null, $this->mTitle->getText() ) instanceof Block ) {
11211120 return array(
11221121 'index' => 'noindex',
11231122 'follow' => 'nofollow'
Index: trunk/phase3/includes/OutputPage.php
@@ -1910,7 +1910,7 @@
19111911
19121912 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
19131913
1914 - $blockid = $wgUser->mBlock->mId;
 1914+ $blockid = $wgUser->mBlock->getId();
19151915
19161916 $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry );
19171917
@@ -1922,7 +1922,7 @@
19231923
19241924 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
19251925 * This could be a username, an IP range, or a single IP. */
1926 - $intended = $wgUser->mBlock->mAddress;
 1926+ $intended = $wgUser->mBlock->getTarget();
19271927
19281928 $this->addWikiMsg(
19291929 $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -82,7 +82,7 @@
8383 $this->dieUsageMsg( $retval[0] );
8484 }
8585
86 - $res['id'] = $block->mId;
 86+ $res['id'] = $block->getId();
8787 $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
8888 $res['reason'] = $params['reason'];
8989 $this->getResult()->addValue( null, $this->getModuleName(), $res );
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -98,11 +98,11 @@
9999 $this->dieUsageMsg( $retval );
100100 }
101101
102 - list( $target, $type ) = SpecialBlock::getTargetAndType( $params['user'] );
 102+ list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] );
103103 $res['user'] = $params['user'];
104104 $res['userID'] = $target instanceof User ? $target->getId() : 0;
105105
106 - $block = Block::newFromTargetAndType( $target, $type );
 106+ $block = Block::newFromTarget( $target );
107107 if( $block instanceof Block ){
108108 $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity()
109109 ? 'infinite'
Index: trunk/phase3/includes/Title.php
@@ -1562,7 +1562,7 @@
15631563 }
15641564
15651565 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1566 - $blockid = $block->mId;
 1566+ $blockid = $block->getId();
15671567 $blockExpiry = $user->mBlock->mExpiry;
15681568 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
15691569 if ( $blockExpiry == 'infinity' ) {
@@ -1571,7 +1571,7 @@
15721572 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
15731573 }
15741574
1575 - $intended = $user->mBlock->mAddress;
 1575+ $intended = $user->mBlock->getTarget();
15761576
15771577 $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name,
15781578 $blockid, $blockExpiry, $intended, $blockTimestamp );
Index: trunk/phase3/includes/specials/SpecialUnblock.php
@@ -49,7 +49,7 @@
5050 }
5151
5252 list( $this->target, $this->type ) = SpecialBlock::getTargetAndType( $par, $wgRequest );
53 - $this->block = Block::newFromTargetAndType( $this->target, $this->type );
 53+ $this->block = Block::newFromTarget( $this->target );
5454
5555 # bug 15810: blocked admins should have limited access here. This won't allow sysops
5656 # to remove autoblocks on themselves, but they should have ipblock-exempt anyway
@@ -168,7 +168,7 @@
169169 # unblock the whole range.
170170 list( $target, $type ) = SpecialBlock::getTargetAndType( $target );
171171 if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) {
172 - $range = $block->mAddress;
 172+ $range = $block->getTarget();
173173 return array( array( 'ipb_blocked_as_range', $target, $range ) );
174174 }
175175
@@ -185,7 +185,12 @@
186186
187187 # Unset _deleted fields as needed
188188 if( $block->mHideName ) {
189 - RevisionDeleteUser::unsuppressUserName( $block->mAddress, $block->mUser );
 189+ # Something is deeply FUBAR if this is not a User object, but who knows?
 190+ $id = $block->getTarget() instanceof User
 191+ ? $block->getTarget()->getID()
 192+ : User::idFromName( $block->getTarget() );
 193+
 194+ RevisionDeleteUser::unsuppressUserName( $block->getTarget(), $id );
190195 }
191196
192197 # Make log entry
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -304,7 +304,7 @@
305305 $wgOut->permissionRequired( 'createaccount' );
306306 return false;
307307 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
308 - $this->userBlockedMessage();
 308+ $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );
309309 return false;
310310 }
311311
@@ -918,9 +918,15 @@
919919 }
920920 }
921921
922 - /** */
923 - function userBlockedMessage() {
924 - global $wgOut, $wgUser;
 922+ /**
 923+ * Output a message that informs the user that they cannot create an account because
 924+ * there is a block on them or their IP which prevents account creation. Note that
 925+ * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
 926+ * setting on blocks (bug 13611).
 927+ * @param $block Block the block causing this error
 928+ */
 929+ function userBlockedMessage( Block $block ) {
 930+ global $wgOut;
925931
926932 # Let's be nice about this, it's likely that this feature will be used
927933 # for blocking large numbers of innocent people, e.g. range blocks on
@@ -932,14 +938,18 @@
933939
934940 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
935941
936 - $ip = wfGetIP();
937 - $blocker = User::whoIs( $wgUser->mBlock->mBy );
938 - $block_reason = $wgUser->mBlock->mReason;
939 -
 942+ $block_reason = $block->mReason;
940943 if ( strval( $block_reason ) === '' ) {
941944 $block_reason = wfMsg( 'blockednoreason' );
942945 }
943 - $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
 946+
 947+ $wgOut->addWikiMsg(
 948+ 'cantcreateaccount-text',
 949+ $block->getTarget(),
 950+ $block_reason,
 951+ $block->getBlocker()->getName()
 952+ );
 953+
944954 $wgOut->returnToMain( false );
945955 }
946956
@@ -963,7 +973,7 @@
964974 $wgOut->readOnlyPage();
965975 return;
966976 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
967 - $this->userBlockedMessage();
 977+ $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );
968978 return;
969979 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
970980 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
Index: trunk/phase3/includes/specials/SpecialBlockme.php
@@ -48,10 +48,12 @@
4949 if ( !$user->isLoggedIn() ) {
5050 $user->addToDatabase();
5151 }
52 - $id = $user->getId();
53 - $reason = wfMsg( 'proxyblockreason' );
5452
55 - $block = new Block( $ip, 0, $id, $reason, wfTimestampNow() );
 53+ $block = new Block();
 54+ $block->setTarget( $ip );
 55+ $block->setBlocker( $user );
 56+ $block->mReason = wfMsg( 'proxyblockreason' );
 57+
5658 $block->insert();
5759
5860 $wgOut->addWikiMsg( 'proxyblocksuccess' );
Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -201,16 +201,16 @@
202202 protected function maybeAlterFormDefaults( &$fields ){
203203 $fields['Target']['default'] = (string)$this->target;
204204
205 - $block = Block::newFromTargetAndType( $this->target, $this->type );
 205+ $block = Block::newFromTarget( $this->target );
206206
207207 if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
208208 && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
209 - || $block->mAddress == $this->target ) # or if it is, the range is what we're about to block
 209+ || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block
210210 )
211211 {
212212 $fields['HardBlock']['default'] = $block->isHardblock();
213213 $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
214 - $fields['AutoBlock']['default'] = $block->mEnableAutoblock;
 214+ $fields['AutoBlock']['default'] = $block->isAutoblocking();
215215 if( isset( $fields['DisableEmail'] ) ){
216216 $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
217217 }
@@ -531,24 +531,18 @@
532532 }
533533 }
534534
535 - # Create block object. Note that for a user block, ipb_address is only for display purposes
536 - # FIXME: Why do we need to pass fourteen optional parameters to do this!?!
537 - $block = new Block(
538 - $target, # IP address or User name
539 - $userId, # User id
540 - $wgUser->getId(), # Blocker id
541 - $data['Reason'][0], # Reason string
542 - wfTimestampNow(), # Block Timestamp
543 - 0, # Is this an autoblock (no)
544 - self::parseExpiryInput( $data['Expiry'] ), # Expiry time
545 - !$data['HardBlock'], # Block anon only
546 - $data['CreateAccount'],
547 - $data['AutoBlock'],
548 - $data['HideUser']
549 - );
550 -
 535+ # Create block object.
 536+ $block = new Block();
 537+ $block->setTarget( $target );
 538+ $block->setBlocker( $wgUser );
 539+ $block->mReason = $data['Reason'][0];
 540+ $block->mExpiry = self::parseExpiryInput( $data['Expiry'] );
 541+ $block->prevents( 'createaccount', $data['CreateAccount'] );
551542 $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
552543 $block->prevents( 'sendemail', $data['DisableEmail'] );
 544+ $block->isHardblock( $data['HardBlock'] );
 545+ $block->isAutoblocking( $data['AutoBlock'] );
 546+ $block->mHideName = $data['HideUser'];
553547
554548 if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
555549 return array( 'hookaborted' );
@@ -566,7 +560,7 @@
567561
568562 # This returns direct blocks before autoblocks/rangeblocks, since we should
569563 # be sure the user is blocked by now it should work for our purposes
570 - $currentBlock = Block::newFromTargetAndType( $target, $type );
 564+ $currentBlock = Block::newFromTarget( $target );
571565
572566 if( $block->equals( $currentBlock ) ) {
573567 return array( 'ipb_already_blocked' );
@@ -611,7 +605,7 @@
612606
613607 # Block constructor sanitizes certain block options on insert
614608 $data['BlockEmail'] = $block->prevents( 'sendemail' );
615 - $data['AutoBlock'] = $block->mEnableAutoblock;
 609+ $data['AutoBlock'] = $block->isAutoblocking();
616610
617611 # Prepare log parameters
618612 $logParams = array();
@@ -641,8 +635,8 @@
642636 public static function getSuggestedDurations( $lang = null ){
643637 $a = array();
644638 $msg = $lang === null
645 - ? wfMessage( 'ipboptions' )->inContentLanguage()
646 - : wfMessage( 'ipboptions' )->inLanguage( $lang );
 639+ ? wfMessage( 'ipboptions' )->inContentLanguage()->text()
 640+ : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
647641
648642 if( $msg == '-' ){
649643 return array();
Index: trunk/phase3/includes/Block.php
@@ -15,18 +15,32 @@
1616 * FIXME: this whole class is a cesspit, needs a complete rewrite
1717 */
1818 class Block {
19 - /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
20 - $mEnableAutoblock, $mHideName,
21 - $mByName, $mAngryAutoblock;
 19+ /* public*/ var $mUser, $mReason, $mTimestamp, $mAuto, $mExpiry,
 20+ $mHideName,
 21+ $mAngryAutoblock;
2222 protected
 23+ $mAddress,
 24+ $mId,
 25+ $mBy,
 26+ $mByName,
2327 $mFromMaster,
2428 $mRangeStart,
2529 $mRangeEnd,
2630 $mAnonOnly,
 31+ $mEnableAutoblock,
2732 $mBlockEmail,
2833 $mAllowUsertalk,
2934 $mCreateAccount;
3035
 36+ /// @var User|String
 37+ protected $target;
 38+
 39+ /// @var Block::TYPE_ constant. Can only be USER, IP or RANGE internally
 40+ protected $type;
 41+
 42+ /// @var User
 43+ protected $blocker;
 44+
3145 # TYPE constants
3246 const TYPE_USER = 1;
3347 const TYPE_IP = 2;
@@ -34,10 +48,19 @@
3549 const TYPE_AUTO = 4;
3650 const TYPE_ID = 5;
3751
 52+ /**
 53+ * Constructor
 54+ * FIXME: Don't know what the best format to have for this constructor is, but fourteen
 55+ * optional parameters certainly isn't it.
 56+ */
3857 function __construct( $address = '', $user = 0, $by = 0, $reason = '',
3958 $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
4059 $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byName = false )
4160 {
 61+ if( $timestamp === 0 ){
 62+ $timestamp = wfTimestampNow();
 63+ }
 64+
4265 $this->mId = 0;
4366 # Expand valid IPv6 addresses
4467 $address = IP::sanitizeIP( $address );
@@ -139,99 +162,128 @@
140163 * @param $user int The user ID, or zero for anonymous users
141164 * @param $killExpired bool Whether to delete expired rows while loading
142165 * @return Boolean: the user is blocked from editing
143 - *
 166+ * @deprecated since 1.18
144167 */
145168 public function load( $address = '', $user = 0, $killExpired = true ) {
146 - wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
 169+ wfDeprecated( __METHOD__ );
 170+ if( $user ){
 171+ $username = User::whoIs( $user );
 172+ $block = self::newFromTarget( $username, $address );
 173+ } else {
 174+ $block = self::newFromTarget( null, $address );
 175+ }
147176
148 - $db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
149 -
150 - if ( 0 == $user && $address === '' ) {
151 - # Invalid user specification, not blocked
152 - $this->clear();
153 -
 177+ if( $block instanceof Block ){
 178+ # This is mildly evil, but hey, it's B/C :D
 179+ foreach( $block as $variable => $value ){
 180+ $this->$variable = $value;
 181+ }
 182+ return true;
 183+ } else {
154184 return false;
155185 }
 186+ }
156187
157 - # Try user block
158 - if ( $user ) {
159 - $res = $db->resultObject( $db->select(
160 - 'ipblocks',
161 - '*',
162 - array( 'ipb_user' => $user ),
163 - __METHOD__
164 - ) );
 188+ /**
 189+ * Load a block from the database which affects the already-set $this->target:
 190+ * 1) A block directly on the given user or IP
 191+ * 2) A rangeblock encompasing the given IP (smallest first)
 192+ * 3) An autoblock on the given IP
 193+ * @param $vagueTarget User|String also search for blocks affecting this target. Doesn't
 194+ * make any sense to use TYPE_AUTO / TYPE_ID here
 195+ * @return Bool whether a relevant block was found
 196+ */
 197+ protected function newLoad( $vagueTarget = null ) {
 198+ $db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
165199
166 - if ( $this->loadFromResult( $res, $killExpired ) ) {
167 - return true;
168 - }
 200+ if( $this->type !== null ){
 201+ $conds = array(
 202+ 'ipb_address' => array( (string)$this->target ),
 203+ );
 204+ } else {
 205+ $conds = array( 'ipb_address' => array() );
169206 }
170207
171 - # Try IP block
172 - # TODO: improve performance by merging this query with the autoblock one
173 - # Slightly tricky while handling killExpired as well
174 - if ( $address !== '' ) {
175 - $conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
176 - $res = $db->resultObject( $db->select(
177 - 'ipblocks',
178 - '*',
179 - $conds,
180 - __METHOD__
181 - ) );
 208+ if( $vagueTarget !== null ){
 209+ list( $target, $type ) = self::parseTarget( $vagueTarget );
 210+ switch( $type ) {
 211+ case self::TYPE_USER:
 212+ # Slightly wierd, but who are we to argue?
 213+ $conds['ipb_address'][] = (string)$target;
 214+ break;
182215
183 - if ( $this->loadFromResult( $res, $killExpired ) ) {
184 - if ( $user && $this->mAnonOnly ) {
185 - # Block is marked anon-only
186 - # Whitelist this IP address against autoblocks and range blocks
187 - # (but not account creation blocks -- bug 13611)
188 - if ( !$this->mCreateAccount ) {
189 - $this->clear();
190 - }
 216+ case self::TYPE_IP:
 217+ $conds['ipb_address'][] = (string)$target;
 218+ $conds[] = self::getRangeCond( IP::toHex( $target ) );
 219+ $conds = $db->makeList( $conds, LIST_OR );
 220+ break;
191221
192 - return false;
193 - } else {
194 - return true;
195 - }
 222+ case self::TYPE_RANGE:
 223+ list( $start, $end ) = IP::parseRange( $target );
 224+ $conds['ipb_address'][] = (string)$target;
 225+ $conds[] = self::getRangeCond( $start, $end );
 226+ $conds = $db->makeList( $conds, LIST_OR );
 227+ break;
 228+
 229+ default:
 230+ throw new MWException( "Tried to load block with invalid type" );
196231 }
197232 }
198233
199 - # Try range block
200 - if ( $this->loadRange( $address, $killExpired, $user ) ) {
201 - if ( $user && $this->mAnonOnly ) {
202 - # Respect account creation blocks on logged-in users -- bug 13611
203 - if ( !$this->mCreateAccount ) {
204 - $this->clear();
205 - }
 234+ $res = $db->select( 'ipblocks', '*', $conds, __METHOD__ );
206235
207 - return false;
208 - } else {
209 - return true;
210 - }
211 - }
 236+ # This result could contain a block on the user, a block on the IP, and a russian-doll
 237+ # set of rangeblocks. We want to choose the most specific one, so keep a leader board.
 238+ $bestRow = null;
212239
213 - # Try autoblock
214 - if ( $address ) {
215 - $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
 240+ # Lower will be better
 241+ $bestBlockScore = 100;
216242
217 - if ( $user ) {
218 - $conds['ipb_anon_only'] = 0;
 243+ # This is begging for $this = $bestBlock, but that's not allowed in PHP :(
 244+ $bestBlockPreventsEdit = null;
 245+
 246+ foreach( $res as $row ){
 247+ $block = Block::newFromRow( $row );
 248+
 249+ # Don't use expired blocks
 250+ if( $block->deleteIfExpired() ){
 251+ continue;
219252 }
220253
221 - $res = $db->resultObject( $db->select(
222 - 'ipblocks',
223 - '*',
224 - $conds,
225 - __METHOD__
226 - ) );
 254+ # Don't use anon only blocks on users
 255+ if( $this->type == self::TYPE_USER && !$block->isHardblock() ){
 256+ continue;
 257+ }
227258
228 - if ( $this->loadFromResult( $res, $killExpired ) ) {
229 - return true;
 259+ if( $block->getType() == self::TYPE_RANGE ){
 260+ # This is the number of bits that are allowed to vary in the block, give
 261+ # or take some floating point errors
 262+ $end = wfBaseconvert( $block->getRangeEnd(), 16, 10 );
 263+ $start = wfBaseconvert( $block->getRangeStart(), 16, 10 );
 264+ $size = log( $end - $start + 1, 2 );
 265+
 266+ # This has the nice property that a /32 block is ranked equally with a
 267+ # single-IP block, which is exactly what it is...
 268+ $score = self::TYPE_RANGE - 1 + ( $size / 128 );
 269+
 270+ } else {
 271+ $score = $block->getType();
230272 }
 273+
 274+ if( $score < $bestBlockScore ){
 275+ $bestBlockScore = $score;
 276+ $bestRow = $row;
 277+ $bestBlockPreventsEdit = $block->prevents( 'edit' );
 278+ }
231279 }
232280
233 - # Give up
234 - $this->clear();
235 - return false;
 281+ if( $bestRow !== null ){
 282+ $this->initFromRow( $bestRow );
 283+ $this->prevents( 'edit', $bestBlockPreventsEdit );
 284+ return true;
 285+ } else {
 286+ return false;
 287+ }
236288 }
237289
238290 /**
@@ -367,11 +419,13 @@
368420 * @param $row ResultWrapper: a row from the ipblocks table
369421 */
370422 protected function initFromRow( $row ) {
371 - $this->mAddress = $row->ipb_address;
 423+ list( $this->target, $this->type ) = self::parseTarget( $row->ipb_address );
 424+
 425+ $this->setTarget( $row->ipb_address );
 426+ $this->setBlocker( User::newFromId( $row->ipb_by ) );
 427+
372428 $this->mReason = $row->ipb_reason;
373429 $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
374 - $this->mUser = $row->ipb_user;
375 - $this->mBy = $row->ipb_by;
376430 $this->mAuto = $row->ipb_auto;
377431 $this->mAnonOnly = $row->ipb_anon_only;
378432 $this->mCreateAccount = $row->ipb_create_account;
@@ -381,18 +435,22 @@
382436 $this->mHideName = $row->ipb_deleted;
383437 $this->mId = $row->ipb_id;
384438 $this->mExpiry = $row->ipb_expiry;
385 -
386 - if ( isset( $row->user_name ) ) {
387 - $this->mByName = $row->user_name;
388 - } else {
389 - $this->mByName = $row->ipb_by_text;
390 - }
391 -
392439 $this->mRangeStart = $row->ipb_range_start;
393440 $this->mRangeEnd = $row->ipb_range_end;
394441 }
395442
396443 /**
 444+ * Create a new Block object from a database row
 445+ * @param $row ResultWrapper row from the ipblocks table
 446+ * @return Block
 447+ */
 448+ public static function newFromRow( $row ){
 449+ $block = new Block;
 450+ $block->initFromRow( $row );
 451+ return $block;
 452+ }
 453+
 454+ /**
397455 * Once $mAddress has been set, get the range they came from.
398456 * Wrapper for IP::parseRange
399457 */
@@ -813,6 +871,14 @@
814872 }
815873
816874 /**
 875+ * Get the block ID
 876+ * @return int
 877+ */
 878+ public function getId() {
 879+ return $this->mId;
 880+ }
 881+
 882+ /**
817883 * Get/set the SELECT ... FOR UPDATE flag
818884 * @deprecated since 1.18
819885 */
@@ -840,6 +906,10 @@
841907 return !$y;
842908 }
843909
 910+ public function isAutoblocking( $x = null ) {
 911+ return wfSetVar( $this->mEnableAutoblock, $x );
 912+ }
 913+
844914 /**
845915 * Get/set whether the Block prevents a given action
846916 * @param $action String
@@ -849,7 +919,7 @@
850920 public function prevents( $action, $x = null ) {
851921 switch( $action ) {
852922 case 'edit':
853 - # TODO Not actually quite this simple (bug 13611 etc)
 923+ # For now... <evil laugh>
854924 return true;
855925
856926 case 'createaccount':
@@ -1000,46 +1070,47 @@
10011071
10021072 /**
10031073 * Given a target and the target's type, get an existing Block object if possible.
1004 - * Note that passing an IP address will get an applicable rangeblock if the IP is
1005 - * not individually blocked but falls within that range
1006 - * TODO: check that that fallback handles nested rangeblocks nicely (should return
1007 - * smallest one)
1008 - * @param $target String|User|Int a block target, which may be one of several types:
 1074+ * @param $specificTarget String|User|Int a block target, which may be one of several types:
10091075 * * A user to block, in which case $target will be a User
10101076 * * An IP to block, in which case $target will be a User generated by using
10111077 * User::newFromName( $ip, false ) to turn off name validation
10121078 * * An IP range, in which case $target will be a String "123.123.123.123/18" etc
1013 - * * The ID of an existing block, in which case $target will be an Int
1014 - * @param $type Block::TYPE_ constant the type of block as described above
1015 - * @return Block|null (null if the target is not blocked)
 1079+ * * The ID of an existing block, in the format "#12345" (since pure numbers are valid
 1080+ * usernames
 1081+ * Calling this with a user, IP address or range will not select autoblocks, and will
 1082+ * only select a block where the targets match exactly (so looking for blocks on
 1083+ * 1.2.3.4 will not select 1.2.0.0/16 or even 1.2.3.4/32)
 1084+ * @param $vagueTarget String|User|Int as above, but we will search for *any* block which
 1085+ * affects that target (so for an IP address, get ranges containing that IP; and also
 1086+ * get any relevant autoblocks)
 1087+ * @param $fromMaster Bool whether to use the DB_MASTER database
 1088+ * @return Block|null (null if no relevant block could be found). The target and type
 1089+ * of the returned Block will refer to the actual block which was found, which might
 1090+ * not be the same as the target you gave if you used $vagueTarget!
10161091 */
1017 - public static function newFromTargetAndType( $target, $type ) {
1018 - if ( $target instanceof User ) {
1019 - if ( $type == Block::TYPE_IP ) {
1020 - return Block::newFromDB( $target->getName(), 0 );
1021 - } elseif ( $type == Block::TYPE_USER ) {
1022 - return Block::newFromDB( '', $target->getId() );
 1092+ public static function newFromTarget( $specificTarget, $vagueTarget = null, $fromMaster = false ) {
 1093+ list( $target, $type ) = self::parseTarget( $specificTarget );
 1094+ if( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
 1095+ return Block::newFromID( $target );
 1096+
 1097+ } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
 1098+ $block = new Block();
 1099+ $block->fromMaster( $fromMaster );
 1100+
 1101+ if( $type !== null ){
 1102+ $block->setTarget( $target );
 1103+ }
 1104+
 1105+ if( $block->newLoad( $vagueTarget ) ){
 1106+ return $block;
10231107 } else {
1024 - # Should be unreachable;
10251108 return null;
10261109 }
1027 -
1028 - } elseif ( $type == Block::TYPE_RANGE ) {
1029 - return Block::newFromDB( $target, 0 );
1030 -
1031 - } elseif ( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
1032 - return Block::newFromID( $target );
1033 -
10341110 } else {
10351111 return null;
10361112 }
10371113 }
10381114
1039 - public static function newFromTarget( $target ) {
1040 - list( $target, $type ) = self::parseTarget( $target );
1041 - return self::newFromTargetAndType( $target, $type );
1042 - }
1043 -
10441115 /**
10451116 * From an existing Block, get the target and the type of target. Note that it is
10461117 * always safe to treat the target as a string; for User objects this will return
@@ -1049,6 +1120,17 @@
10501121 public static function parseTarget( $target ) {
10511122 $target = trim( $target );
10521123
 1124+ # We may have been through this before
 1125+ if( $target instanceof User ){
 1126+ if( IP::isValid( $target->getName() ) ){
 1127+ return self::TYPE_IP;
 1128+ } else {
 1129+ return self::TYPE_USER;
 1130+ }
 1131+ } elseif( $target === null ){
 1132+ return array( null, null );
 1133+ }
 1134+
10531135 $userObj = User::newFromName( $target );
10541136 if ( $userObj instanceof User ) {
10551137 # Note that since numbers are valid usernames, a $target of "12345" will be
@@ -1079,30 +1161,61 @@
10801162 }
10811163
10821164 /**
1083 - * Get the target and target type for this particular Block. Note that for autoblocks,
 1165+ * Get the type of target for this particular block
 1166+ * @return Block::TYPE_ constant, will never be TYPE_ID
 1167+ */
 1168+ public function getType() {
 1169+ return $this->mAuto
 1170+ ? self::TYPE_AUTO
 1171+ : $this->type;
 1172+ }
 1173+
 1174+ /**
 1175+ * Get the target for this particular Block. Note that for autoblocks,
10841176 * this returns the unredacted name; frontend functions need to call $block->getRedactedName()
10851177 * in this situation.
1086 - * @return array( User|String, Block::TYPE_ constant )
1087 - * FIXME: this should be an integral part of the Block member variables
 1178+ * @return User|String
10881179 */
1089 - public function getTargetAndType() {
1090 - list( $target, $type ) = self::parseTarget( $this->mAddress );
 1180+ public function getTarget() {
 1181+ return $this->target;
 1182+ }
10911183
1092 - # Check whether it's an autoblock
1093 - if ( $this->mAuto ) {
1094 - $type = self::TYPE_AUTO;
 1184+ /**
 1185+ * Set the target for this block, and update $this->type accordingly
 1186+ * @param $target Mixed
 1187+ */
 1188+ public function setTarget( $target ){
 1189+ list( $this->target, $this->type ) = self::parseTarget( $target );
 1190+
 1191+ $this->mAddress = (string)$this->target;
 1192+ if( $this->type == self::TYPE_USER ){
 1193+ if( $this->target instanceof User ){
 1194+ # Cheat
 1195+ $this->mUser = $this->target->getID();
 1196+ } else {
 1197+ $this->mUser = User::idFromName( $this->target );
 1198+ }
 1199+ } else {
 1200+ $this->mUser = 0;
10951201 }
1096 -
1097 - return array( $target, $type );
10981202 }
10991203
1100 - public function getType() {
1101 - list( /*...*/, $type ) = $this->getTargetAndType();
1102 - return $type;
 1204+ /**
 1205+ * Get the user who implemented this block
 1206+ * @return User
 1207+ */
 1208+ public function getBlocker(){
 1209+ return $this->blocker;
11031210 }
11041211
1105 - public function getTarget() {
1106 - list( $target, /*...*/ ) = $this->getTargetAndType();
1107 - return $target;
 1212+ /**
 1213+ * Set the user who implemented (or will implement) this block
 1214+ * @param $user User
 1215+ */
 1216+ public function setBlocker( User $user ){
 1217+ $this->blocker = $user;
 1218+
 1219+ $this->mBy = $user->getID();
 1220+ $this->mByName = $user->getName();
11081221 }
11091222 }
Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -298,21 +298,20 @@
299299 $expirestr = $u->getId() ? 'indefinite' : '1 week';
300300 $expiry = SpecialBlock::parseExpiryInput( $expirestr );
301301 $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0;
 302+
302303 // Create the block
303 - $block = new Block( $u->getName(), // victim
304 - $u->getId(), // uid
305 - $wgUser->getId(), // blocker
306 - $reason, // comment
307 - wfTimestampNow(), // block time
308 - 0, // auto ?
309 - $expiry, // duration
310 - $anonOnly, // anononly?
311 - 1, // block account creation?
312 - 1, // autoblocking?
313 - 0, // suppress name?
314 - 0 // block from sending email?
315 - );
316 - $oldblock = Block::newFromDB( $u->getName(), $u->getId() );
 304+ $block = new Block();
 305+ $block->setTarget( $u );
 306+ $block->setBlocker( $wgUser );
 307+ $block->mReason = $reason;
 308+ $block->mExpiry = $expiry;
 309+ $block->isHardblock( !IP::isIPAddress( $u->getName() ) );
 310+ $block->isAutoblocking( true );
 311+ $block->prevents( 'createaccount', true );
 312+ $block->prevents( 'sendemail', false );
 313+ $block->prevents( 'editownusertalk', false );
 314+
 315+ $oldblock = Block::newFromTarget( $u->getName() );
317316 if( !$oldblock ) {
318317 $block->insert();
319318 # Prepare log parameters
@@ -498,24 +497,30 @@
499498 }
500499
501500 protected function getIPBlockInfo( $ip ) {
502 - static $blocklist;
503 - $blocklist = SpecialPage::getTitleFor( 'BlockList' );
504 - $block = new Block();
505 - $block->fromMaster( false ); // use slaves
506 - if ( $block->load( $ip, 0 ) ) {
507 - if ( IP::isIPAddress( $block->mAddress ) && strpos( $block->mAddress, '/' ) ) {
508 - $userpage = Title::makeTitle( NS_USER, $block->mAddress );
509 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml( 'checkuser-blocked' ),
510 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
511 - return ' <strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
512 - } elseif ( $block->mAuto ) {
513 - $blocklog = $this->sk->makeKnownLinkObj( $blocklist, wfMsgHtml( 'checkuser-blocked' ),
514 - 'ip=' . urlencode( "#$block->mId" ) );
 501+ $block = Block::newFromTarget( null, $ip, false );
 502+ if ( $block instanceof Block ) {
 503+ if ( $block->getType() == Block::TYPE_RANGE ) {
 504+ $userpage = Title::makeTitle( NS_USER, $block->getTarget() );
 505+ $blocklog = $this->sk->makeKnownLinkObj(
 506+ SpecialPage::getTitleFor( 'Log' ),
 507+ wfMsgHtml( 'checkuser-blocked' ),
 508+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() )
 509+ );
 510+ return ' <strong>(' . $blocklog . ' - ' . $block->getTarget() . ')</strong>';
 511+ } elseif ( $block->getType() == Block::TYPE_AUTO ) {
 512+ $blocklog = $this->sk->makeKnownLinkObj(
 513+ SpecialPage::getTitleFor( 'BlockList' ),
 514+ wfMsgHtml( 'checkuser-blocked' ),
 515+ 'ip=' . urlencode( "#{$block->getId()}" )
 516+ );
515517 return ' <strong>(' . $blocklog . ')</strong>';
516518 } else {
517 - $userpage = Title::makeTitle( NS_USER, $ip );
518 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml( 'checkuser-blocked' ),
519 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 519+ $userpage = Title::makeTitle( NS_USER, $block->getTarget() );
 520+ $blocklog = $this->sk->makeKnownLinkObj(
 521+ SpecialPage::getTitleFor( 'Log' ),
 522+ wfMsgHtml( 'checkuser-blocked' ),
 523+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() )
 524+ );
520525 return ' <strong>(' . $blocklog . ')</strong>';
521526 }
522527 }
@@ -1033,25 +1038,33 @@
10341039 static $logs, $blocklist;
10351040 $logs = SpecialPage::getTitleFor( 'Log' );
10361041 $blocklist = SpecialPage::getTitleFor( 'BlockList' );
1037 - $block = new Block();
1038 - $block->fromMaster( false ); // use slaves
 1042+ $block = Block::newFromTarget( $user, $ip, false );
10391043 $flags = array();
1040 - if ( $block->load( $ip, $userId ) ) {
 1044+ if ( $block instanceof Block ) {
10411045 // Range blocked?
1042 - if ( IP::isIPAddress( $block->mAddress ) && strpos( $block->mAddress, '/' ) ) {
1043 - $userpage = Title::makeTitle( NS_USER, $block->mAddress );
1044 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml( 'checkuser-blocked' ),
1045 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
1046 - $flags[] = '<strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong>';
 1046+ if ( $block->getType == Block::TYPE_RANGE ) {
 1047+ $userpage = Title::makeTitle( NS_USER, $block->getTarget() );
 1048+ $blocklog = $this->sk->makeKnownLinkObj(
 1049+ $logs,
 1050+ wfMsgHtml( 'checkuser-blocked' ),
 1051+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() )
 1052+ );
 1053+ $flags[] = '<strong>(' . $blocklog . ' - ' . $block->getTarget() . ')</strong>';
10471054 // Auto blocked?
1048 - } elseif ( $block->mAuto ) {
1049 - $blocklog = $this->sk->makeKnownLinkObj( $blocklist,
1050 - wfMsgHtml( 'checkuser-blocked' ), 'ip=' . urlencode( "#{$block->mId}" ) );
 1055+ } elseif ( $block->getType() == Block::TYPE_AUTO ) {
 1056+ $blocklog = $this->sk->makeKnownLinkObj(
 1057+ $blocklist,
 1058+ wfMsgHtml( 'checkuser-blocked' ),
 1059+ 'ip=' . urlencode( "#{$block->getId()}" )
 1060+ );
10511061 $flags[] = '<strong>(' . $blocklog . ')</strong>';
10521062 } else {
10531063 $userpage = $user->getUserPage();
1054 - $blocklog = $this->sk->makeKnownLinkObj( $logs, wfMsgHtml( 'checkuser-blocked' ),
1055 - 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 1064+ $blocklog = $this->sk->makeKnownLinkObj(
 1065+ $logs,
 1066+ wfMsgHtml( 'checkuser-blocked' ),
 1067+ 'type=block&page=' . urlencode( $userpage->getPrefixedText() )
 1068+ );
10561069 $flags[] = '<strong>(' . $blocklog . ')</strong>';
10571070 }
10581071 // IP that is blocked on all wikis?
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -1007,12 +1007,9 @@
10081008
10091009 // Create a block.
10101010 $block = new Block;
1011 - $block->mAddress = $wgUser->getName();
1012 - $block->mUser = $wgUser->getId();
1013 - $block->mBy = $filterUser->getId();
1014 - $block->mByName = $filterUser->getName();
 1011+ $block->setTarget( $wgUser->getName() );
 1012+ $block->setBlocker( $filterUser );
10151013 $block->mReason = wfMsgForContent( 'abusefilter-blockreason', $rule_desc );
1016 - $block->mTimestamp = wfTimestampNow();
10171014 $block->isHardblock( false );
10181015 $block->prevents( 'createaccount', true );
10191016 $block->mExpiry = SpecialBlock::parseExpiryInput( $wgAbuseFilterBlockDuration );
@@ -1046,12 +1043,9 @@
10471044
10481045 // Create a block.
10491046 $block = new Block;
1050 - $block->mAddress = $range;
1051 - $block->mUser = 0;
1052 - $block->mBy = $filterUser->getId();
1053 - $block->mByName = $filterUser->getName();
 1047+ $block->setTarget( $range );
 1048+ $block->setBlocker( $filterUser );
10541049 $block->mReason = wfMsgForContent( 'abusefilter-blockreason', $rule_desc );
1055 - $block->mTimestamp = wfTimestampNow();
10561050 $block->isHardblock( false );
10571051 $block->prevents( 'createaccount', true );
10581052 $block->mExpiry = SpecialBlock::parseExpiryInput( '1 week' );
Index: trunk/extensions/regexBlock/regexBlockCore.php
@@ -578,10 +578,10 @@
579579 }
580580 /* set expiry information */
581581 if ( $user->mBlock ) {
582 - $user->mBlock->mId = $valid['blckid'];
 582+ # $user->mBlock->mId = $valid['blckid']; FIXME: why does this want to do this?
583583 $user->mBlock->mExpiry = $valid['expire'];
584584 $user->mBlock->mTimestamp = $valid['timestamp'];
585 - $user->mBlock->mAddress = ($valid['ip'] == 1) ? wfGetIP() : $user->getName();
 585+ $user->mBlock->setTarget( ($valid['ip'] == 1) ? wfGetIP() : $user->getName() );
586586 }
587587
588588 $result = self::updateStats( $user, $user_ip, $blocker, $valid['match'], $valid['blckid'] );

Follow-up revisions

RevisionCommit summaryAuthorDate
r84498Follow-up r84475: fixing the warning is easy enough... :D Also some random t...happy-melon23:03, 21 March 2011
r84499Follow-up r84475: what ever posessed me to get rid of this?happy-melon23:27, 21 March 2011
r84501'Fix' fatal in LiquidThreads from r84475. I say 'fixed' in the loosest possi...happy-melon23:47, 21 March 2011
r84522Follow-up r84475: fix notices.happy-melon11:14, 22 March 2011
r88663Follow-up r84475: update userBlockedMessage() caller.happy-melon18:49, 23 May 2011
r88664Follow-up r84475: Block::parseTarget() should always return an array.happy-melon18:52, 23 May 2011
r88738(bug 29116) follow-up r84475: normalise the empty string to null in Block::ne...happy-melon19:03, 24 May 2011
r88750* (bug 29116) Fix regression breaking CheckUser extension...brion21:04, 24 May 2011
r89668Fix (Api)BlockTest for Sqlite. getRangeStart()/getRangeEnd() were returning n...demon18:13, 7 June 2011
r90859Follow-up r84475 CR; and also documentation fixes; PhpStorm 2.1 is *even more...happy-melon23:01, 26 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84251First forays into the swamp of the Block.php backend:...happy-melon16:35, 18 March 2011

Comments

#Comment by Reedy (talk | contribs)   21:57, 21 March 2011

You do realise if you're fixing separate issues, you can commit separately? ;)

#Comment by Happy-melon (talk | contribs)   22:47, 21 March 2011

I had been doing that, arguably overdoing it. This one kinda spiralled out of control and I couldn't find a way to easily split it up... :D I've made so many overall changes to this area in the past fortnight that it will need to be reviewed with a wholistic eye anyway.

#Comment by Siebrand (talk | contribs)   22:53, 21 March 2011

This broke LiquidThreads, especially Special:NewMessages. Now getting:

[21-Mar-2011 22:48:59] PHP Notice: Use of Block::load is deprecated. [Called from Block::newFromDB in /www/w/includes/Block.php at line 98] for /wiki/Special:NewMessages

  • GlobalFunctions.php line 3129 calls wfBacktrace()
  • GlobalFunctions.php line 3097 calls wfWarn()
  • Block.php line 168 calls wfDeprecated()
  • Block.php line 98 calls Block::load()
  • Block.php line 714 calls Block::newFromDB()
  • User.php line 2727 calls Block::doAutoblock()
  • User.php line 1150 calls User::spreadBlock()
  • User.php line 1360 calls User::getBlockedStatus()
  • User.php line 1375 calls User::isBlocked()
  • Title.php line 1545 calls User::isBlockedFrom()
  • Title.php line 1612 calls Title::checkUserBlock()
  • Title.php line 1178 calls Title::getUserPermissionsErrorsInternal()
  • Thread.php line 1568 calls Title::userCan()
  • Thread.php line 1546 calls Thread::canUserCreateThreads()
  • View.php line 1153 calls Thread::canUserReply()
  • View.php line 1272 calls LqtV in /www/w/includes/GlobalFunctions.php on line 3134 [21-Mar-2011 22:48:59] PHP Fatal error: Call to a member function getTitle() on a non-object in /www/w/extensions/LiquidThreads/classes/Hooks.php on line 421
#Comment by Siebrand (talk | contribs)   23:15, 21 March 2011

r84498 indeed fixes the notice. Fatal still there.

#Comment by Aaron Schulz (talk | contribs)   08:47, 22 March 2011

Notice: Undefined index: DisableEmail in C:\wamp\www\MW_trunk\includes\specials\SpecialBlock.php on line 542

Notice: Undefined index: DisableEmail in C:\wamp\www\MW_trunk\includes\specials\SpecialBlock.php on line 749

#Comment by Happy-melon (talk | contribs)   12:20, 24 March 2011

These were fixed in r84522. I believe everything outstanding on this revision has been dealt with; including a mysterious bug on TWN which turned out to have been Siebrand merging a blocked user with himself (r84584).

#Comment by Reedy (talk | contribs)   23:01, 17 May 2011

You change the decleration of userBlockedMessage() in SpecialUserlogin, but didn't update its caller at line 714

#Comment by Happy-melon (talk | contribs)   18:50, 23 May 2011

Done in r88663. I think that codepath might be unreachable, or maybe only by spoofing forms.

#Comment by Bawolff (talk | contribs)   18:22, 23 May 2011

Block::parseTarget is supposed to return an array, I think this change made it not return an array in some cases, maybe causing bug 29032.

#Comment by Happy-melon (talk | contribs)   18:53, 23 May 2011

That's certainly not right. Fixed in r88664, don't know whether it fixes the bug you mentioned.

#Comment by Bawolff (talk | contribs)   21:20, 23 May 2011

Whoops, meant bug 29116.

#Comment by Brion VIBBER (talk | contribs)   00:11, 24 May 2011

Marking FIXME; problems that are still present implicated in bug 29116

#Comment by Happy-melon (talk | contribs)   18:11, 28 May 2011

Was this resolved by your r88750?

#Comment by Krinkle (talk | contribs)   01:09, 29 May 2011

Presumably this line (since it's the only core code-changing line in that revision):

-		} elseif( $target === null && $vagueTarget === null ){
+		} elseif( $target === null && $vagueTarget == '' ){
#Comment by Happy-melon (talk | contribs)   09:33, 7 June 2011

I'll assume so since the bug is marked FIXED. Resetting to new.

#Comment by Krinkle (talk | contribs)   16:40, 28 May 2011

I don't know if the reported PHP Notices were only triggered if certain extensions are installed, but if not already make sure you

  • test with both debug mode set to true and to false in your local trunk
  • and have error_reporting set to ALL( error_reporting(E_ALL);ini_set('display_errors', 1);), and verifying that there are none before committing.
#Comment by Aaron Schulz (talk | contribs)   23:06, 17 June 2011
+ if ( $block->getType == Block::TYPE_RANGE ) {

Typo, gives error message.

+ $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() );

Does this expect a Block input?

#Comment by Aaron Schulz (talk | contribs)   23:25, 17 June 2011

Nevermind, isBlockedFromCreateAccount() returns the right type here.

On the other hand, due to the static $accBlock var and the wfGetIP() call, calling isBlockedFromCreateAccount() only makes sense on wgUser. Maybe that should be enforced?

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

Are static variables in methods shared between separate instances of the same class, then? If so, that's definitely not the way to cache it :S

#Comment by Krinkle (talk | contribs)   22:33, 26 June 2011

Yes, that's what makes them static ;-). They're accessed through the class name, not from the instance (eg. SomeClass::staticMember

#Comment by Krinkle (talk | contribs)   22:36, 26 June 2011

Oh you meant a static variable within an public method. Hm.. that's interesting. Gonna try that one out.

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

Converted to a member variable in r90859

#Comment by Aaron Schulz (talk | contribs)   23:21, 17 June 2011
+ $this->mBlockedby = $this->mBlock->getBlocker()->getName();

Won't this fatal if there is no blocker? Maybe use Block::getBy() and such.

#Comment by Aaron Schulz (talk | contribs)   23:46, 17 June 2011
253 	# Don't use anon only blocks on users
254 	if( $this->type == self::TYPE_USER && !$block->isHardblock() ){
255 	continue;
256 	}

Can't you just add this to the query conds?

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

Trying to translate the "target is a user" condition into pure SQL would be difficult, and would introduce potential inconsistencies with the behaviour of Block::parseTarget().

#Comment by Aaron Schulz (talk | contribs)   22:37, 26 June 2011

Fair enough, I was getting hung up on the $block->isHardblock() part, which would be easy by itself.

#Comment by Johnduhart (talk | contribs)   20:09, 25 November 2011
+	 * @deprecated since 1.18

When you deprecate methods can you please explain why and/or what the new method is? Thank you.

Status & tagging log