Index: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php |
— | — | @@ -53,12 +53,12 @@ |
54 | 54 | 'user' => 'UTBlockee', |
55 | 55 | 'reason' => 'Some reason', |
56 | 56 | 'token' => $pageinfo['blocktoken'] ), $data ); |
| 57 | + |
| 58 | + $block = Block::newFromTarget('UTBlockee'); |
57 | 59 | |
58 | | - $block = Block::newFromDB('UTBlockee'); |
59 | | - |
60 | 60 | $this->assertTrue( !is_null( $block ), 'Block is valid' ); |
61 | 61 | |
62 | | - $this->assertEquals( 'UTBlockee', $block->mAddress ); |
| 62 | + $this->assertEquals( 'UTBlockee', (string)$block->getTarget() ); |
63 | 63 | $this->assertEquals( 'Some reason', $block->mReason ); |
64 | 64 | $this->assertEquals( 'infinity', $block->mExpiry ); |
65 | 65 | |
Index: trunk/phase3/includes/User.php |
— | — | @@ -1129,42 +1129,26 @@ |
1130 | 1130 | $this->mHideName = 0; |
1131 | 1131 | $this->mAllowUsertalk = 0; |
1132 | 1132 | |
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(); |
1139 | 1138 | } 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; |
1149 | 1140 | } |
1150 | 1141 | |
1151 | 1142 | # 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 ) { |
1155 | 1145 | 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(); |
1159 | 1147 | $this->mBlockreason = $this->mBlock->mReason; |
1160 | 1148 | $this->mHideName = $this->mBlock->mHideName; |
1161 | 1149 | $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' ); |
1162 | 1150 | if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) { |
1163 | 1151 | $this->spreadBlock(); |
1164 | 1152 | } |
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. |
1169 | 1153 | } |
1170 | 1154 | |
1171 | 1155 | # Proxy blocking |
— | — | @@ -1374,7 +1358,7 @@ |
1375 | 1359 | */ |
1376 | 1360 | function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site |
1377 | 1361 | $this->getBlockedStatus( $bFromSlave ); |
1378 | | - return $this->mBlockedby !== 0; |
| 1362 | + return $this->mBlock instanceof Block && $this->mBlock->prevents( 'edit' ); |
1379 | 1363 | } |
1380 | 1364 | |
1381 | 1365 | /** |
— | — | @@ -1427,7 +1411,7 @@ |
1428 | 1412 | */ |
1429 | 1413 | function getBlockId() { |
1430 | 1414 | $this->getBlockedStatus(); |
1431 | | - return ( $this->mBlock ? $this->mBlock->mId : false ); |
| 1415 | + return ( $this->mBlock ? $this->mBlock->getId() : false ); |
1432 | 1416 | } |
1433 | 1417 | |
1434 | 1418 | /** |
— | — | @@ -2735,7 +2719,7 @@ |
2736 | 2720 | return; |
2737 | 2721 | } |
2738 | 2722 | |
2739 | | - $userblock = Block::newFromDB( '', $this->mId ); |
| 2723 | + $userblock = Block::newFromTarget( $this->getName() ); |
2740 | 2724 | if ( !$userblock ) { |
2741 | 2725 | return; |
2742 | 2726 | } |
— | — | @@ -2797,11 +2781,24 @@ |
2798 | 2782 | |
2799 | 2783 | /** |
2800 | 2784 | * Get whether the user is explicitly blocked from account creation. |
2801 | | - * @return Bool |
| 2785 | + * @return Bool|Block |
2802 | 2786 | */ |
2803 | 2787 | function isBlockedFromCreateAccount() { |
2804 | 2788 | $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; |
2806 | 2803 | } |
2807 | 2804 | |
2808 | 2805 | /** |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -1115,8 +1115,7 @@ |
1116 | 1116 | if ( $ns == NS_USER || $ns == NS_USER_TALK ) { |
1117 | 1117 | # Don't index user and user talk pages for blocked users (bug 11443) |
1118 | 1118 | 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 ) { |
1121 | 1120 | return array( |
1122 | 1121 | 'index' => 'noindex', |
1123 | 1122 | 'follow' => 'nofollow' |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -1910,7 +1910,7 @@ |
1911 | 1911 | |
1912 | 1912 | $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; |
1913 | 1913 | |
1914 | | - $blockid = $wgUser->mBlock->mId; |
| 1914 | + $blockid = $wgUser->mBlock->getId(); |
1915 | 1915 | |
1916 | 1916 | $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry ); |
1917 | 1917 | |
— | — | @@ -1922,7 +1922,7 @@ |
1923 | 1923 | |
1924 | 1924 | /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked. |
1925 | 1925 | * This could be a username, an IP range, or a single IP. */ |
1926 | | - $intended = $wgUser->mBlock->mAddress; |
| 1926 | + $intended = $wgUser->mBlock->getTarget(); |
1927 | 1927 | |
1928 | 1928 | $this->addWikiMsg( |
1929 | 1929 | $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, |
Index: trunk/phase3/includes/api/ApiUnblock.php |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | $this->dieUsageMsg( $retval[0] ); |
84 | 84 | } |
85 | 85 | |
86 | | - $res['id'] = $block->mId; |
| 86 | + $res['id'] = $block->getId(); |
87 | 87 | $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); |
88 | 88 | $res['reason'] = $params['reason']; |
89 | 89 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
Index: trunk/phase3/includes/api/ApiBlock.php |
— | — | @@ -98,11 +98,11 @@ |
99 | 99 | $this->dieUsageMsg( $retval ); |
100 | 100 | } |
101 | 101 | |
102 | | - list( $target, $type ) = SpecialBlock::getTargetAndType( $params['user'] ); |
| 102 | + list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] ); |
103 | 103 | $res['user'] = $params['user']; |
104 | 104 | $res['userID'] = $target instanceof User ? $target->getId() : 0; |
105 | 105 | |
106 | | - $block = Block::newFromTargetAndType( $target, $type ); |
| 106 | + $block = Block::newFromTarget( $target ); |
107 | 107 | if( $block instanceof Block ){ |
108 | 108 | $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity() |
109 | 109 | ? 'infinite' |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1562,7 +1562,7 @@ |
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; |
1566 | | - $blockid = $block->mId; |
| 1566 | + $blockid = $block->getId(); |
1567 | 1567 | $blockExpiry = $user->mBlock->mExpiry; |
1568 | 1568 | $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); |
1569 | 1569 | if ( $blockExpiry == 'infinity' ) { |
— | — | @@ -1571,7 +1571,7 @@ |
1572 | 1572 | $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); |
1573 | 1573 | } |
1574 | 1574 | |
1575 | | - $intended = $user->mBlock->mAddress; |
| 1575 | + $intended = $user->mBlock->getTarget(); |
1576 | 1576 | |
1577 | 1577 | $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name, |
1578 | 1578 | $blockid, $blockExpiry, $intended, $blockTimestamp ); |
Index: trunk/phase3/includes/specials/SpecialUnblock.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | } |
51 | 51 | |
52 | 52 | 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 ); |
54 | 54 | |
55 | 55 | # bug 15810: blocked admins should have limited access here. This won't allow sysops |
56 | 56 | # to remove autoblocks on themselves, but they should have ipblock-exempt anyway |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | # unblock the whole range. |
170 | 170 | list( $target, $type ) = SpecialBlock::getTargetAndType( $target ); |
171 | 171 | if( $block->getType() == Block::TYPE_RANGE && $type == Block::TYPE_IP ) { |
172 | | - $range = $block->mAddress; |
| 172 | + $range = $block->getTarget(); |
173 | 173 | return array( array( 'ipb_blocked_as_range', $target, $range ) ); |
174 | 174 | } |
175 | 175 | |
— | — | @@ -185,7 +185,12 @@ |
186 | 186 | |
187 | 187 | # Unset _deleted fields as needed |
188 | 188 | 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 ); |
190 | 195 | } |
191 | 196 | |
192 | 197 | # Make log entry |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -304,7 +304,7 @@ |
305 | 305 | $wgOut->permissionRequired( 'createaccount' ); |
306 | 306 | return false; |
307 | 307 | } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
308 | | - $this->userBlockedMessage(); |
| 308 | + $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
309 | 309 | return false; |
310 | 310 | } |
311 | 311 | |
— | — | @@ -918,9 +918,15 @@ |
919 | 919 | } |
920 | 920 | } |
921 | 921 | |
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; |
925 | 931 | |
926 | 932 | # Let's be nice about this, it's likely that this feature will be used |
927 | 933 | # for blocking large numbers of innocent people, e.g. range blocks on |
— | — | @@ -932,14 +938,18 @@ |
933 | 939 | |
934 | 940 | $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) ); |
935 | 941 | |
936 | | - $ip = wfGetIP(); |
937 | | - $blocker = User::whoIs( $wgUser->mBlock->mBy ); |
938 | | - $block_reason = $wgUser->mBlock->mReason; |
939 | | - |
| 942 | + $block_reason = $block->mReason; |
940 | 943 | if ( strval( $block_reason ) === '' ) { |
941 | 944 | $block_reason = wfMsg( 'blockednoreason' ); |
942 | 945 | } |
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 | + |
944 | 954 | $wgOut->returnToMain( false ); |
945 | 955 | } |
946 | 956 | |
— | — | @@ -963,7 +973,7 @@ |
964 | 974 | $wgOut->readOnlyPage(); |
965 | 975 | return; |
966 | 976 | } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
967 | | - $this->userBlockedMessage(); |
| 977 | + $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
968 | 978 | return; |
969 | 979 | } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { |
970 | 980 | $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); |
Index: trunk/phase3/includes/specials/SpecialBlockme.php |
— | — | @@ -48,10 +48,12 @@ |
49 | 49 | if ( !$user->isLoggedIn() ) { |
50 | 50 | $user->addToDatabase(); |
51 | 51 | } |
52 | | - $id = $user->getId(); |
53 | | - $reason = wfMsg( 'proxyblockreason' ); |
54 | 52 | |
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 | + |
56 | 58 | $block->insert(); |
57 | 59 | |
58 | 60 | $wgOut->addWikiMsg( 'proxyblocksuccess' ); |
Index: trunk/phase3/includes/specials/SpecialBlock.php |
— | — | @@ -201,16 +201,16 @@ |
202 | 202 | protected function maybeAlterFormDefaults( &$fields ){ |
203 | 203 | $fields['Target']['default'] = (string)$this->target; |
204 | 204 | |
205 | | - $block = Block::newFromTargetAndType( $this->target, $this->type ); |
| 205 | + $block = Block::newFromTarget( $this->target ); |
206 | 206 | |
207 | 207 | if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock |
208 | 208 | && ( $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 |
210 | 210 | ) |
211 | 211 | { |
212 | 212 | $fields['HardBlock']['default'] = $block->isHardblock(); |
213 | 213 | $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' ); |
214 | | - $fields['AutoBlock']['default'] = $block->mEnableAutoblock; |
| 214 | + $fields['AutoBlock']['default'] = $block->isAutoblocking(); |
215 | 215 | if( isset( $fields['DisableEmail'] ) ){ |
216 | 216 | $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' ); |
217 | 217 | } |
— | — | @@ -531,24 +531,18 @@ |
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
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'] ); |
551 | 542 | $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) ); |
552 | 543 | $block->prevents( 'sendemail', $data['DisableEmail'] ); |
| 544 | + $block->isHardblock( $data['HardBlock'] ); |
| 545 | + $block->isAutoblocking( $data['AutoBlock'] ); |
| 546 | + $block->mHideName = $data['HideUser']; |
553 | 547 | |
554 | 548 | if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { |
555 | 549 | return array( 'hookaborted' ); |
— | — | @@ -566,7 +560,7 @@ |
567 | 561 | |
568 | 562 | # This returns direct blocks before autoblocks/rangeblocks, since we should |
569 | 563 | # 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 ); |
571 | 565 | |
572 | 566 | if( $block->equals( $currentBlock ) ) { |
573 | 567 | return array( 'ipb_already_blocked' ); |
— | — | @@ -611,7 +605,7 @@ |
612 | 606 | |
613 | 607 | # Block constructor sanitizes certain block options on insert |
614 | 608 | $data['BlockEmail'] = $block->prevents( 'sendemail' ); |
615 | | - $data['AutoBlock'] = $block->mEnableAutoblock; |
| 609 | + $data['AutoBlock'] = $block->isAutoblocking(); |
616 | 610 | |
617 | 611 | # Prepare log parameters |
618 | 612 | $logParams = array(); |
— | — | @@ -641,8 +635,8 @@ |
642 | 636 | public static function getSuggestedDurations( $lang = null ){ |
643 | 637 | $a = array(); |
644 | 638 | $msg = $lang === null |
645 | | - ? wfMessage( 'ipboptions' )->inContentLanguage() |
646 | | - : wfMessage( 'ipboptions' )->inLanguage( $lang ); |
| 639 | + ? wfMessage( 'ipboptions' )->inContentLanguage()->text() |
| 640 | + : wfMessage( 'ipboptions' )->inLanguage( $lang )->text(); |
647 | 641 | |
648 | 642 | if( $msg == '-' ){ |
649 | 643 | return array(); |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -15,18 +15,32 @@ |
16 | 16 | * FIXME: this whole class is a cesspit, needs a complete rewrite |
17 | 17 | */ |
18 | 18 | 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; |
22 | 22 | protected |
| 23 | + $mAddress, |
| 24 | + $mId, |
| 25 | + $mBy, |
| 26 | + $mByName, |
23 | 27 | $mFromMaster, |
24 | 28 | $mRangeStart, |
25 | 29 | $mRangeEnd, |
26 | 30 | $mAnonOnly, |
| 31 | + $mEnableAutoblock, |
27 | 32 | $mBlockEmail, |
28 | 33 | $mAllowUsertalk, |
29 | 34 | $mCreateAccount; |
30 | 35 | |
| 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 | + |
31 | 45 | # TYPE constants |
32 | 46 | const TYPE_USER = 1; |
33 | 47 | const TYPE_IP = 2; |
— | — | @@ -34,10 +48,19 @@ |
35 | 49 | const TYPE_AUTO = 4; |
36 | 50 | const TYPE_ID = 5; |
37 | 51 | |
| 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 | + */ |
38 | 57 | function __construct( $address = '', $user = 0, $by = 0, $reason = '', |
39 | 58 | $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0, |
40 | 59 | $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byName = false ) |
41 | 60 | { |
| 61 | + if( $timestamp === 0 ){ |
| 62 | + $timestamp = wfTimestampNow(); |
| 63 | + } |
| 64 | + |
42 | 65 | $this->mId = 0; |
43 | 66 | # Expand valid IPv6 addresses |
44 | 67 | $address = IP::sanitizeIP( $address ); |
— | — | @@ -139,99 +162,128 @@ |
140 | 163 | * @param $user int The user ID, or zero for anonymous users |
141 | 164 | * @param $killExpired bool Whether to delete expired rows while loading |
142 | 165 | * @return Boolean: the user is blocked from editing |
143 | | - * |
| 166 | + * @deprecated since 1.18 |
144 | 167 | */ |
145 | 168 | 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 | + } |
147 | 176 | |
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 { |
154 | 184 | return false; |
155 | 185 | } |
| 186 | + } |
156 | 187 | |
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 ); |
165 | 199 | |
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() ); |
169 | 206 | } |
170 | 207 | |
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; |
182 | 215 | |
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; |
191 | 221 | |
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" ); |
196 | 231 | } |
197 | 232 | } |
198 | 233 | |
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__ ); |
206 | 235 | |
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; |
212 | 239 | |
213 | | - # Try autoblock |
214 | | - if ( $address ) { |
215 | | - $conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 ); |
| 240 | + # Lower will be better |
| 241 | + $bestBlockScore = 100; |
216 | 242 | |
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; |
219 | 252 | } |
220 | 253 | |
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 | + } |
227 | 258 | |
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(); |
230 | 272 | } |
| 273 | + |
| 274 | + if( $score < $bestBlockScore ){ |
| 275 | + $bestBlockScore = $score; |
| 276 | + $bestRow = $row; |
| 277 | + $bestBlockPreventsEdit = $block->prevents( 'edit' ); |
| 278 | + } |
231 | 279 | } |
232 | 280 | |
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 | + } |
236 | 288 | } |
237 | 289 | |
238 | 290 | /** |
— | — | @@ -367,11 +419,13 @@ |
368 | 420 | * @param $row ResultWrapper: a row from the ipblocks table |
369 | 421 | */ |
370 | 422 | 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 | + |
372 | 428 | $this->mReason = $row->ipb_reason; |
373 | 429 | $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp ); |
374 | | - $this->mUser = $row->ipb_user; |
375 | | - $this->mBy = $row->ipb_by; |
376 | 430 | $this->mAuto = $row->ipb_auto; |
377 | 431 | $this->mAnonOnly = $row->ipb_anon_only; |
378 | 432 | $this->mCreateAccount = $row->ipb_create_account; |
— | — | @@ -381,18 +435,22 @@ |
382 | 436 | $this->mHideName = $row->ipb_deleted; |
383 | 437 | $this->mId = $row->ipb_id; |
384 | 438 | $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 | | - |
392 | 439 | $this->mRangeStart = $row->ipb_range_start; |
393 | 440 | $this->mRangeEnd = $row->ipb_range_end; |
394 | 441 | } |
395 | 442 | |
396 | 443 | /** |
| 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 | + /** |
397 | 455 | * Once $mAddress has been set, get the range they came from. |
398 | 456 | * Wrapper for IP::parseRange |
399 | 457 | */ |
— | — | @@ -813,6 +871,14 @@ |
814 | 872 | } |
815 | 873 | |
816 | 874 | /** |
| 875 | + * Get the block ID |
| 876 | + * @return int |
| 877 | + */ |
| 878 | + public function getId() { |
| 879 | + return $this->mId; |
| 880 | + } |
| 881 | + |
| 882 | + /** |
817 | 883 | * Get/set the SELECT ... FOR UPDATE flag |
818 | 884 | * @deprecated since 1.18 |
819 | 885 | */ |
— | — | @@ -840,6 +906,10 @@ |
841 | 907 | return !$y; |
842 | 908 | } |
843 | 909 | |
| 910 | + public function isAutoblocking( $x = null ) { |
| 911 | + return wfSetVar( $this->mEnableAutoblock, $x ); |
| 912 | + } |
| 913 | + |
844 | 914 | /** |
845 | 915 | * Get/set whether the Block prevents a given action |
846 | 916 | * @param $action String |
— | — | @@ -849,7 +919,7 @@ |
850 | 920 | public function prevents( $action, $x = null ) { |
851 | 921 | switch( $action ) { |
852 | 922 | case 'edit': |
853 | | - # TODO Not actually quite this simple (bug 13611 etc) |
| 923 | + # For now... <evil laugh> |
854 | 924 | return true; |
855 | 925 | |
856 | 926 | case 'createaccount': |
— | — | @@ -1000,46 +1070,47 @@ |
1001 | 1071 | |
1002 | 1072 | /** |
1003 | 1073 | * 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: |
1009 | 1075 | * * A user to block, in which case $target will be a User |
1010 | 1076 | * * An IP to block, in which case $target will be a User generated by using |
1011 | 1077 | * User::newFromName( $ip, false ) to turn off name validation |
1012 | 1078 | * * 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! |
1016 | 1091 | */ |
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; |
1023 | 1107 | } else { |
1024 | | - # Should be unreachable; |
1025 | 1108 | return null; |
1026 | 1109 | } |
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 | | - |
1034 | 1110 | } else { |
1035 | 1111 | return null; |
1036 | 1112 | } |
1037 | 1113 | } |
1038 | 1114 | |
1039 | | - public static function newFromTarget( $target ) { |
1040 | | - list( $target, $type ) = self::parseTarget( $target ); |
1041 | | - return self::newFromTargetAndType( $target, $type ); |
1042 | | - } |
1043 | | - |
1044 | 1115 | /** |
1045 | 1116 | * From an existing Block, get the target and the type of target. Note that it is |
1046 | 1117 | * always safe to treat the target as a string; for User objects this will return |
— | — | @@ -1049,6 +1120,17 @@ |
1050 | 1121 | public static function parseTarget( $target ) { |
1051 | 1122 | $target = trim( $target ); |
1052 | 1123 | |
| 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 | + |
1053 | 1135 | $userObj = User::newFromName( $target ); |
1054 | 1136 | if ( $userObj instanceof User ) { |
1055 | 1137 | # Note that since numbers are valid usernames, a $target of "12345" will be |
— | — | @@ -1079,30 +1161,61 @@ |
1080 | 1162 | } |
1081 | 1163 | |
1082 | 1164 | /** |
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, |
1084 | 1176 | * this returns the unredacted name; frontend functions need to call $block->getRedactedName() |
1085 | 1177 | * 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 |
1088 | 1179 | */ |
1089 | | - public function getTargetAndType() { |
1090 | | - list( $target, $type ) = self::parseTarget( $this->mAddress ); |
| 1180 | + public function getTarget() { |
| 1181 | + return $this->target; |
| 1182 | + } |
1091 | 1183 | |
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; |
1095 | 1201 | } |
1096 | | - |
1097 | | - return array( $target, $type ); |
1098 | 1202 | } |
1099 | 1203 | |
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; |
1103 | 1210 | } |
1104 | 1211 | |
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(); |
1108 | 1221 | } |
1109 | 1222 | } |
Index: trunk/extensions/CheckUser/CheckUser_body.php |
— | — | @@ -298,21 +298,20 @@ |
299 | 299 | $expirestr = $u->getId() ? 'indefinite' : '1 week'; |
300 | 300 | $expiry = SpecialBlock::parseExpiryInput( $expirestr ); |
301 | 301 | $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; |
| 302 | + |
302 | 303 | // 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() ); |
317 | 316 | if( !$oldblock ) { |
318 | 317 | $block->insert(); |
319 | 318 | # Prepare log parameters |
— | — | @@ -498,24 +497,30 @@ |
499 | 498 | } |
500 | 499 | |
501 | 500 | 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 | + ); |
515 | 517 | return ' <strong>(' . $blocklog . ')</strong>'; |
516 | 518 | } 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 | + ); |
520 | 525 | return ' <strong>(' . $blocklog . ')</strong>'; |
521 | 526 | } |
522 | 527 | } |
— | — | @@ -1033,25 +1038,33 @@ |
1034 | 1039 | static $logs, $blocklist; |
1035 | 1040 | $logs = SpecialPage::getTitleFor( 'Log' ); |
1036 | 1041 | $blocklist = SpecialPage::getTitleFor( 'BlockList' ); |
1037 | | - $block = new Block(); |
1038 | | - $block->fromMaster( false ); // use slaves |
| 1042 | + $block = Block::newFromTarget( $user, $ip, false ); |
1039 | 1043 | $flags = array(); |
1040 | | - if ( $block->load( $ip, $userId ) ) { |
| 1044 | + if ( $block instanceof Block ) { |
1041 | 1045 | // 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>'; |
1047 | 1054 | // 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 | + ); |
1051 | 1061 | $flags[] = '<strong>(' . $blocklog . ')</strong>'; |
1052 | 1062 | } else { |
1053 | 1063 | $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 | + ); |
1056 | 1069 | $flags[] = '<strong>(' . $blocklog . ')</strong>'; |
1057 | 1070 | } |
1058 | 1071 | // IP that is blocked on all wikis? |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -1007,12 +1007,9 @@ |
1008 | 1008 | |
1009 | 1009 | // Create a block. |
1010 | 1010 | $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 ); |
1015 | 1013 | $block->mReason = wfMsgForContent( 'abusefilter-blockreason', $rule_desc ); |
1016 | | - $block->mTimestamp = wfTimestampNow(); |
1017 | 1014 | $block->isHardblock( false ); |
1018 | 1015 | $block->prevents( 'createaccount', true ); |
1019 | 1016 | $block->mExpiry = SpecialBlock::parseExpiryInput( $wgAbuseFilterBlockDuration ); |
— | — | @@ -1046,12 +1043,9 @@ |
1047 | 1044 | |
1048 | 1045 | // Create a block. |
1049 | 1046 | $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 ); |
1054 | 1049 | $block->mReason = wfMsgForContent( 'abusefilter-blockreason', $rule_desc ); |
1055 | | - $block->mTimestamp = wfTimestampNow(); |
1056 | 1050 | $block->isHardblock( false ); |
1057 | 1051 | $block->prevents( 'createaccount', true ); |
1058 | 1052 | $block->mExpiry = SpecialBlock::parseExpiryInput( '1 week' ); |
Index: trunk/extensions/regexBlock/regexBlockCore.php |
— | — | @@ -578,10 +578,10 @@ |
579 | 579 | } |
580 | 580 | /* set expiry information */ |
581 | 581 | if ( $user->mBlock ) { |
582 | | - $user->mBlock->mId = $valid['blckid']; |
| 582 | + # $user->mBlock->mId = $valid['blckid']; FIXME: why does this want to do this? |
583 | 583 | $user->mBlock->mExpiry = $valid['expire']; |
584 | 584 | $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() ); |
586 | 586 | } |
587 | 587 | |
588 | 588 | $result = self::updateStats( $user, $user_ip, $blocker, $valid['match'], $valid['blckid'] ); |