r93237 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93236‎ | r93237 | r93238 >
Date:19:58, 26 July 2011
Author:happy-melon
Status:reverted (Comments)
Tags:
Comment:
Follow-up r93234: use User::getBlock() accessor rather than accessing $mBlock directly. Also fixes r85951 CR, and remove code duplication in Title::checkUserBlock().
Modified paths:
  • /trunk/extensions/DynamicPageList/DPLMain.php (modified) (history)
  • /trunk/extensions/TorBlock/TorBlock.class.php (modified) (history)
  • /trunk/extensions/regexBlock/regexBlockCore.php (modified) (history)
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialEmailuser.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -1265,13 +1265,14 @@
12661266 }
12671267
12681268 # User/IP blocking
1269 - $this->mBlock = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
1270 - if ( $this->mBlock instanceof Block ) {
 1269+ $block = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
 1270+ if ( $block instanceof Block ) {
12711271 wfDebug( __METHOD__ . ": Found block.\n" );
1272 - $this->mBlockedby = $this->mBlock->getByName();
1273 - $this->mBlockreason = $this->mBlock->mReason;
1274 - $this->mHideName = $this->mBlock->mHideName;
1275 - $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' );
 1272+ $this->mBlock = $block;
 1273+ $this->mBlockedby = $block->getByName();
 1274+ $this->mBlockreason = $block->mReason;
 1275+ $this->mHideName = $block->mHideName;
 1276+ $this->mAllowUsertalk = !$block->prevents( 'editownusertalk' );
12761277 if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) {
12771278 $this->spreadBlock();
12781279 }
Index: trunk/phase3/includes/OutputPage.php
@@ -1934,7 +1934,7 @@
19351935 * @deprecated since 1.18
19361936 */
19371937 function blockedPage() {
1938 - throw new UserBlockedError( $this->getUser()->mBlock );
 1938+ throw new UserBlockedError( $this->getUser()->getBlock() );
19391939 }
19401940
19411941 /**
Index: trunk/phase3/includes/Title.php
@@ -1565,39 +1565,11 @@
15661566 } elseif( ( $action == 'edit' || $action == 'create' ) && !$user->isBlockedFrom( $this ) ){
15671567 // Don't block the user from editing their own talk page unless they've been
15681568 // explicitly blocked from that too.
1569 - } elseif( $user->isBlocked() && $user->mBlock->prevents( $action ) !== false ) {
1570 - $block = $user->mBlock;
1571 -
1572 - // This is from OutputPage::blockedPage
1573 - // Copied at r23888 by werdna
1574 -
1575 - $id = $user->blockedBy();
1576 - $reason = $user->blockedFor();
1577 - if ( $reason == '' ) {
1578 - $reason = wfMsg( 'blockednoreason' );
1579 - }
1580 - $ip = wfGetIP();
1581 -
1582 - if ( is_numeric( $id ) ) {
1583 - $name = User::whoIs( $id );
1584 - } else {
1585 - $name = $id;
1586 - }
1587 -
1588 - $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1589 - $blockid = $block->getId();
1590 - $blockExpiry = $user->mBlock->mExpiry;
1591 - $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
1592 - if ( $blockExpiry == 'infinity' ) {
1593 - $blockExpiry = wfMessage( 'infiniteblock' )->text();
1594 - } else {
1595 - $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
1596 - }
1597 -
1598 - $intended = strval( $user->mBlock->getTarget() );
1599 -
1600 - $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name,
1601 - $blockid, $blockExpiry, $intended, $blockTimestamp );
 1569+ } elseif( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) {
 1570+ $e = new UserBlockedError( $user->getBlock() );
 1571+ $params = $e->params;
 1572+ array_unshift( $params, $e->msg );
 1573+ $errors[] = $params;
16021574 }
16031575
16041576 return $errors;
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -746,7 +746,7 @@
747747 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
748748 break;
749749 case self::CREATE_BLOCKED:
750 - $this->userBlockedMessage( $wgUser->mBlock );
 750+ $this->userBlockedMessage( $wgUser->getBlock() );
751751 break;
752752 case self::THROTTLED:
753753 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
Index: trunk/phase3/includes/specials/SpecialEmailuser.php
@@ -99,7 +99,7 @@
100100 case 'badaccess':
101101 throw new PermissionsError( 'sendemail' );
102102 case 'blockedemailuser':
103 - throw new UserBlockedError( $this->getUser()->mBlock );
 103+ throw new UserBlockedError( $this->getUser()->getBlock() );
104104 case 'actionthrottledtext':
105105 throw new ThrottledError;
106106 case 'mailnologin':
Index: trunk/phase3/includes/SpecialPage.php
@@ -825,8 +825,7 @@
826826 }
827827
828828 if ( $this->requiresUnblock() && $user->isBlocked() ) {
829 - $block = $user->mBlock;
830 - throw new UserBlockedError( $block );
 829+ throw new UserBlockedError( $user->getBlock() );
831830 }
832831
833832 return true;
Index: trunk/phase3/includes/Action.php
@@ -198,8 +198,7 @@
199199 }
200200
201201 if ( $this->requiresUnblock() && $user->isBlocked() ) {
202 - $block = $user->mBlock;
203 - throw new UserBlockedError( $block );
 202+ throw new UserBlockedError( $user->getBlock() );
204203 }
205204 }
206205
Index: trunk/extensions/TorBlock/TorBlock.class.php
@@ -200,7 +200,7 @@
201201 */
202202 public static function onGetBlockedStatus( &$user ) {
203203 global $wgTorDisableAdminBlocks;
204 - if ( $wgTorDisableAdminBlocks && self::isExitNode() && $user->mBlock && $user->mBlock->getType() != Block::TYPE_USER ) {
 204+ if ( $wgTorDisableAdminBlocks && self::isExitNode() && $user->isBlocked() && $user->getBlock()->getType() != Block::TYPE_USER ) {
205205 wfDebug( "User using Tor node. Disabling IP block as it was probably targetted at the tor node." );
206206
207207 // Node is probably blocked for being a Tor node. Remove block.
Index: trunk/extensions/regexBlock/regexBlockCore.php
@@ -570,16 +570,16 @@
571571 }
572572 /* account creation check goes through the same hook... */
573573 if ( $valid['create'] == 1 ) {
574 - if ( $user->mBlock ) {
575 - $user->mBlock->prevents( 'createaccount', true );
 574+ if ( $user->isBlocked() ) {
 575+ $user->getBlock()->prevents( 'createaccount', true );
576576 }
577577 }
578578 /* set expiry information */
579 - if ( $user->mBlock ) {
 579+ if ( $user->isBlocked() ) {
580580 # $user->mBlock->mId = $valid['blckid']; FIXME: why does this want to do this?
581 - $user->mBlock->mExpiry = $valid['expire'];
582 - $user->mBlock->mTimestamp = $valid['timestamp'];
583 - $user->mBlock->setTarget( ($valid['ip'] == 1) ? wfGetIP() : $user->getName() );
 581+ $user->getBlock()->mExpiry = $valid['expire'];
 582+ $user->getBlock()->mTimestamp = $valid['timestamp'];
 583+ $user->getBlock()->setTarget( ($valid['ip'] == 1) ? wfGetIP() : $user->getName() );
584584 }
585585
586586 $result = self::updateStats( $user, $user_ip, $blocker, $valid['match'], $valid['blckid'] );
Index: trunk/extensions/DynamicPageList/DPLMain.php
@@ -2995,6 +2995,7 @@
29962996 if ( isset( $iTitleMaxLen ) && ( strlen( $sTitleText ) > $iTitleMaxLen ) ) {
29972997 $sTitleText = substr( $sTitleText, 0, $iTitleMaxLen ) . '...';
29982998 }
 2999+
29993000 if ( $bShowCurID && isset( $row->page_id ) ) {
30003001 $articleLink = '<html>' . $sk->makeKnownLinkObj( $title, htmlspecialchars( $sTitleText ), 'curid=' . $row->page_id ) . '</html>';
30013002 } elseif ( !$bEscapeLinks && ( $pageNamespace == 14 || $pageNamespace == 6 ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r93321Revert r93237 ("use User::getBlock() accessor rather than accessing $mBlock d...catrope22:28, 27 July 2011
r93325Followup r93321: revert r93237 for extensions toocatrope22:34, 27 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85951Implement user-is-blocked and wiki-is-read-only as exceptions.happy-melon14:30, 13 April 2011
r93234Implement an accessor for User->mBlock. Doing this separately as it would be...happy-melon19:27, 26 July 2011

Comments

#Comment by Hashar (talk | contribs)   22:34, 26 July 2011

Breaks cruisecontrol TitlePermissionTest::testUserBlock()

Quick way to verify: $ svn up -r 93237 $ cd tests/phpunit ./phpunit.php --filter TitlePermissionTest

Maybe the test requires an update.

Status & tagging log