r84406 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84405‎ | r84406 | r84407 >
Date:17:43, 20 March 2011
Author:happy-melon
Status:ok
Tags:
Comment:
Follow-up r84358 CR: rename 'editusertalk' to 'editownusertalk', private --> protected, and run stylize.php over Block.php
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -1157,7 +1157,7 @@
11581158 $this->mBlockedby = $this->mBlock->mByName;
11591159 $this->mBlockreason = $this->mBlock->mReason;
11601160 $this->mHideName = $this->mBlock->mHideName;
1161 - $this->mAllowUsertalk = !$this->mBlock->prevents( 'editusertalk' );
 1161+ $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' );
11621162 if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) {
11631163 $this->spreadBlock();
11641164 }
Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -218,7 +218,7 @@
219219 $fields['HideUser']['default'] = $block->mHideName;
220220 }
221221 if( isset( $fields['DisableUTEdit'] ) ){
222 - $fields['DisableUTEdit']['default'] = $block->prevents( 'editusertalk' );
 222+ $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
223223 }
224224 $fields['Reason']['default'] = $block->mReason;
225225 $fields['AlreadyBlocked']['default'] = true;
@@ -547,7 +547,7 @@
548548 $data['HideUser']
549549 );
550550
551 - $block->prevents( 'editusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
 551+ $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
552552 $block->prevents( 'sendemail', $data['DisableEmail'] );
553553
554554 if( !wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) {
Index: trunk/phase3/includes/Block.php
@@ -18,7 +18,7 @@
1919 /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
2020 $mEnableAutoblock, $mHideName,
2121 $mByName, $mAngryAutoblock;
22 - private
 22+ protected
2323 $mFromMaster,
2424 $mRangeStart,
2525 $mRangeEnd,
@@ -27,7 +27,7 @@
2828 $mAllowUsertalk,
2929 $mCreateAccount;
3030
31 - /// TYPE constants
 31+ # TYPE constants
3232 const TYPE_USER = 1;
3333 const TYPE_IP = 2;
3434 const TYPE_RANGE = 3;
@@ -240,8 +240,8 @@
241241 * @param $end String Hexadecimal IP represenation, or null to use $start = $end
242242 * @return String
243243 */
244 - public static function getRangeCond( $start, $end = null ){
245 - if( $end === null ){
 244+ public static function getRangeCond( $start, $end = null ) {
 245+ if ( $end === null ) {
246246 $end = $start;
247247 }
248248 # Per bug 14634, we want to include relevant active rangeblocks; for
@@ -273,9 +273,9 @@
274274 * @param $hex String Hexadecimal IP representation
275275 * @return String
276276 */
277 - protected static function getIpFragment( $hex ){
 277+ protected static function getIpFragment( $hex ) {
278278 global $wgBlockCIDRLimit;
279 - if( substr( $hex, 0, 3 ) == 'v6-' ){
 279+ if ( substr( $hex, 0, 3 ) == 'v6-' ) {
280280 return 'v6-' . substr( substr( $hex, 3 ), 0, floor( $wgBlockCIDRLimit['IPv6'] / 4 ) );
281281 } else {
282282 return substr( $hex, 0, floor( $wgBlockCIDRLimit['IPv4'] / 4 ) );
@@ -766,8 +766,8 @@
767767 * Get the IP address at the start of the range in Hex form
768768 * @return String IP in Hex form
769769 */
770 - public function getRangeStart(){
771 - switch( $this->type ){
 770+ public function getRangeStart() {
 771+ switch( $this->type ) {
772772 case self::TYPE_USER:
773773 return null;
774774 case self::TYPE_IP:
@@ -782,8 +782,8 @@
783783 * Get the IP address at the start of the range in Hex form
784784 * @return String IP in Hex form
785785 */
786 - public function getRangeEnd(){
787 - switch( $this->type ){
 786+ public function getRangeEnd() {
 787+ switch( $this->type ) {
788788 case self::TYPE_USER:
789789 return null;
790790 case self::TYPE_IP:
@@ -832,9 +832,9 @@
833833 * @param $x Bool
834834 * @return Bool
835835 */
836 - public function isHardblock( $x = null ){
 836+ public function isHardblock( $x = null ) {
837837 $y = $this->mAnonOnly;
838 - if( $x !== null){
 838+ if ( $x !== null ) {
839839 $this->mAnonOnly = !$x;
840840 }
841841 return !$y;
@@ -846,8 +846,8 @@
847847 * @param $x Bool
848848 * @return Bool
849849 */
850 - public function prevents( $action, $x = null ){
851 - switch( $action ){
 850+ public function prevents( $action, $x = null ) {
 851+ switch( $action ) {
852852 case 'edit':
853853 # TODO Not actually quite this simple (bug 13611 etc)
854854 return true;
@@ -858,9 +858,9 @@
859859 case 'sendemail':
860860 return wfSetVar( $this->mBlockEmail, $x );
861861
862 - case 'editusertalk':
 862+ case 'editownusertalk':
863863 $y = $this->mAllowUsertalk;
864 - if( $x !== null){
 864+ if ( $x !== null ) {
865865 $this->mAllowUsertalk = !$x;
866866 }
867867 return !$y;
@@ -1013,21 +1013,21 @@
10141014 * @param $type Block::TYPE_ constant the type of block as described above
10151015 * @return Block|null (null if the target is not blocked)
10161016 */
1017 - public static function newFromTargetAndType( $target, $type ){
1018 - if( $target instanceof User ){
1019 - if( $type == Block::TYPE_IP ){
 1017+ public static function newFromTargetAndType( $target, $type ) {
 1018+ if ( $target instanceof User ) {
 1019+ if ( $type == Block::TYPE_IP ) {
10201020 return Block::newFromDB( $target->getName(), 0 );
1021 - } elseif( $type == Block::TYPE_USER ) {
 1021+ } elseif ( $type == Block::TYPE_USER ) {
10221022 return Block::newFromDB( '', $target->getId() );
10231023 } else {
10241024 # Should be unreachable;
10251025 return null;
10261026 }
10271027
1028 - } elseif( $type == Block::TYPE_RANGE ){
 1028+ } elseif ( $type == Block::TYPE_RANGE ) {
10291029 return Block::newFromDB( $target, 0 );
10301030
1031 - } elseif( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ){
 1031+ } elseif ( $type == Block::TYPE_ID || $type == Block::TYPE_AUTO ) {
10321032 return Block::newFromID( $target );
10331033
10341034 } else {
@@ -1035,7 +1035,7 @@
10361036 }
10371037 }
10381038
1039 - public static function newFromTarget( $target ){
 1039+ public static function newFromTarget( $target ) {
10401040 list( $target, $type ) = self::parseTarget( $target );
10411041 return self::newFromTargetAndType( $target, $type );
10421042 }
@@ -1046,17 +1046,17 @@
10471047 * User::__toString() which in turn gives User::getName().
10481048 * @return array( User|String, Block::TYPE_ constant )
10491049 */
1050 - public static function parseTarget( $target ){
 1050+ public static function parseTarget( $target ) {
10511051 $target = trim( $target );
10521052
10531053 $userObj = User::newFromName( $target );
1054 - if( $userObj instanceof User ){
 1054+ if ( $userObj instanceof User ) {
10551055 # Note that since numbers are valid usernames, a $target of "12345" will be
10561056 # considered a User. If you want to pass a block ID, prepend a hash "#12345",
10571057 # since hash characters are not valid in usernames or titles generally.
10581058 return array( $userObj, Block::TYPE_USER );
10591059
1060 - } elseif( IP::isValid( $target ) ){
 1060+ } elseif ( IP::isValid( $target ) ) {
10611061 # We can still create a User if it's an IP address, but we need to turn
10621062 # off validation checking (which would exclude IP addresses)
10631063 return array(
@@ -1064,11 +1064,11 @@
10651065 Block::TYPE_IP
10661066 );
10671067
1068 - } elseif( IP::isValidBlock( $target ) ){
 1068+ } elseif ( IP::isValidBlock( $target ) ) {
10691069 # Can't create a User from an IP range
1070 - return array( Block::normaliseRange( $target ), Block::TYPE_RANGE );
 1070+ return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
10711071
1072 - } elseif( preg_match( '/^#\d+$/', $target ) ){
 1072+ } elseif ( preg_match( '/^#\d+$/', $target ) ) {
10731073 # Autoblock reference in the form "#12345"
10741074 return array( substr( $target, 1 ), Block::TYPE_AUTO );
10751075
@@ -1085,23 +1085,23 @@
10861086 * @return array( User|String, Block::TYPE_ constant )
10871087 * FIXME: this should be an integral part of the Block member variables
10881088 */
1089 - public function getTargetAndType(){
 1089+ public function getTargetAndType() {
10901090 list( $target, $type ) = self::parseTarget( $this->mAddress );
10911091
10921092 # Check whether it's an autoblock
1093 - if( $this->mAuto ){
 1093+ if ( $this->mAuto ) {
10941094 $type = self::TYPE_AUTO;
10951095 }
10961096
10971097 return array( $target, $type );
10981098 }
10991099
1100 - public function getType(){
 1100+ public function getType() {
11011101 list( /*...*/, $type ) = $this->getTargetAndType();
11021102 return $type;
11031103 }
11041104
1105 - public function getTarget(){
 1105+ public function getTarget() {
11061106 list( $target, /*...*/ ) = $this->getTargetAndType();
11071107 return $target;
11081108 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84358* Implement an extensible Block::prevents( <action> ) function to replace the...happy-melon23:47, 19 March 2011

Status & tagging log