From 092597b8e333279cf7db96a711609279819297df Mon Sep 17 00:00:00 2001 From: Jack Phoenix Date: Mon, 19 Oct 2009 11:15:51 +0000 Subject: [PATCH] coding style tweaks --- includes/Block.php | 98 +++++++++-------- includes/Revision.php | 51 ++++----- includes/specials/SpecialBlockip.php | 153 ++++++++++++++------------- 3 files changed, 151 insertions(+), 151 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 5c2b52ff7f..7aa3065efb 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -87,14 +87,14 @@ class Block { return null; } } - + /** * Check if two blocks are effectively equal * * @return Boolean */ public function equals( Block $block ) { - return ( + return ( $this->mAddress == $block->mAddress && $this->mUser == $block->mUser && $this->mAuto == $block->mAuto @@ -132,7 +132,7 @@ class Block { global $wgAntiLockFlags; if ( $this->mForUpdate || $this->mFromMaster ) { $db = wfGetDB( DB_MASTER ); - if ( !$this->mForUpdate || ($wgAntiLockFlags & ALF_NO_BLOCK_LOCK) ) { + if ( !$this->mForUpdate || ( $wgAntiLockFlags & ALF_NO_BLOCK_LOCK ) ) { $options = array(); } else { $options = array( 'FOR UPDATE' ); @@ -401,7 +401,7 @@ class Block { ); $affected = $dbw->affectedRows(); - if ($affected) + if ( $affected ) $this->doRetroactiveAutoblock(); return (bool)$affected; @@ -453,8 +453,8 @@ class Block { # Unset ipb_enable_autoblock for IP blocks, makes no sense if ( !$this->mUser ) { $this->mEnableAutoblock = 0; - } + # bug 18860: non-anon-only IP blocks should be allowed to block email if ( !$this->mUser && $this->mAnonOnly ) { $this->mBlockEmail = 0; @@ -468,28 +468,27 @@ class Block { } } } - - + /** - * Retroactively autoblocks the last IP used by the user (if it is a user) - * blocked by this Block. - * - * @return Boolean: whether or not a retroactive autoblock was made. - */ + * Retroactively autoblocks the last IP used by the user (if it is a user) + * blocked by this Block. + * + * @return Boolean: whether or not a retroactive autoblock was made. + */ public function doRetroactiveAutoblock() { $dbr = wfGetDB( DB_SLAVE ); - #If autoblock is enabled, autoblock the LAST IP used + # If autoblock is enabled, autoblock the LAST IP used # - stolen shamelessly from CheckUser_body.php - if ($this->mEnableAutoblock && $this->mUser) { + if ( $this->mEnableAutoblock && $this->mUser ) { wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n"); - + $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); $conds = array( 'rc_user_text' => $this->mAddress ); - - if ($this->mAngryAutoblock) { + + if ( $this->mAngryAutoblock ) { // Block any IP used in the last 7 days. Up to five IPs. - $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - (7*86400) ) ); + $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - ( 7 * 86400 ) ) ); $options['LIMIT'] = 5; } else { // Just the last IP used. @@ -497,10 +496,10 @@ class Block { } $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds, - __METHOD__ , $options); + __METHOD__ , $options ); if ( !$dbr->numRows( $res ) ) { - #No results, don't autoblock anything + # No results, don't autoblock anything wfDebug("No IP found to retroactively autoblock\n"); } else { while ( $row = $dbr->fetchObject( $res ) ) { @@ -510,7 +509,7 @@ class Block { } } } - + /** * Checks whether a given IP is on the autoblock whitelist. * @@ -519,7 +518,7 @@ class Block { */ public static function isWhitelistedFromAutoblocks( $ip ) { global $wgMemc; - + // Try to get the autoblock_whitelist from the cache, as it's faster // than getting the msg raw and explode()'ing it. $key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' ); @@ -537,20 +536,20 @@ class Block { continue; } - $wlEntry = substr($line, 1); - $wlEntry = trim($wlEntry); + $wlEntry = substr( $line, 1 ); + $wlEntry = trim( $wlEntry ); wfDebug("Checking $ip against $wlEntry..."); # Is the IP in this range? - if (IP::isInRange( $ip, $wlEntry )) { + if ( IP::isInRange( $ip, $wlEntry ) ) { wfDebug(" IP $ip matches $wlEntry, not autoblocking\n"); return true; } else { wfDebug( " No match\n" ); } } - + return false; } @@ -568,12 +567,12 @@ class Block { } # Check for presence on the autoblock whitelist - if (Block::isWhitelistedFromAutoblocks($autoblockIP)) { + if ( Block::isWhitelistedFromAutoblocks( $autoblockIP ) ) { return; } ## Allow hooks to cancel the autoblock. - if (!wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) )) { + if ( !wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) { wfDebug( "Autoblock aborted by hook.\n" ); return false; } @@ -585,8 +584,8 @@ class Block { # If the user is already blocked. Then check if the autoblock would # exceed the user block. If it would exceed, then do nothing, else # prolong block time - if ($this->mExpiry && - ($this->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp))) { + if ( $this->mExpiry && + ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) ) { return; } # Just update the timestamp @@ -613,8 +612,8 @@ class Block { $ipblock->mAllowUsertalk = $this->mAllowUsertalk; # If the user is already blocked with an expiry date, we don't # want to pile on top of that! - if($this->mExpiry) { - $ipblock->mExpiry = min ( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp )); + if( $this->mExpiry ) { + $ipblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp ) ); } else { $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp ); } @@ -627,8 +626,7 @@ class Block { * @return Boolean */ public function deleteIfExpired() { - $fname = 'Block::deleteIfExpired'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); if ( $this->isExpired() ) { wfDebug( "Block::deleteIfExpired() -- deleting\n" ); $this->delete(); @@ -637,7 +635,7 @@ class Block { wfDebug( "Block::deleteIfExpired() -- not expired\n" ); $retVal = false; } - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $retVal; } @@ -673,8 +671,8 @@ class Block { $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'ipblocks', array( /* SET */ - 'ipb_timestamp' => $dbw->timestamp($this->mTimestamp), - 'ipb_expiry' => $dbw->timestamp($this->mExpiry), + 'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ), + 'ipb_expiry' => $dbw->timestamp( $this->mExpiry ), ), array( /* WHERE */ 'ipb_address' => $this->mAddress ), 'Block::updateTimestamp' @@ -703,14 +701,14 @@ class Block { /** * Get/set the SELECT ... FOR UPDATE flag */ - public function forUpdate( $x = NULL ) { + public function forUpdate( $x = null ) { return wfSetVar( $this->mForUpdate, $x ); } /** * Get/set a flag determining whether the master is used for reads */ - public function fromMaster( $x = NULL ) { + public function fromMaster( $x = null ) { return wfSetVar( $this->mFromMaster, $x ); } @@ -776,10 +774,10 @@ class Block { $parts = explode( '/', $range ); if ( count( $parts ) == 2 ) { // IPv6 - if ( IP::isIPv6($range) && $parts[1] >= 64 && $parts[1] <= 128 ) { + if ( IP::isIPv6( $range ) && $parts[1] >= 64 && $parts[1] <= 128 ) { $bits = $parts[1]; $ipint = IP::toUnsigned6( $parts[0] ); - # Native 32 bit functions WONT work here!!! + # Native 32 bit functions WON'T work here!!! # Convert to a padded binary number $network = wfBaseConvert( $ipint, 10, 2, 128 ); # Truncate the last (128-$bits) bits and replace them with zeros @@ -790,7 +788,7 @@ class Block { $newip = IP::toOctet( $network ); $range = "$newip/{$parts[1]}"; } // IPv4 - else if ( IP::isIPv4($range) && $parts[1] >= 16 && $parts[1] <= 32 ) { + elseif ( IP::isIPv4( $range ) && $parts[1] >= 16 && $parts[1] <= 32 ) { $shift = 32 - $parts[1]; $ipint = IP::toUnsigned( $parts[0] ); $ipint = $ipint >> $shift << $shift; @@ -821,7 +819,7 @@ class Block { # works with CHAR(14) as well because "i" sorts after all numbers. return 'infinity'; } - + /** * Convert a DB-encoded expiry into a real string that humans can read. * @@ -830,7 +828,7 @@ class Block { */ public static function formatExpiry( $encoded_expiry ) { static $msg = null; - + if( is_null( $msg ) ) { $msg = array(); $keys = array( 'infiniteblock', 'expiringblock' ); @@ -838,19 +836,19 @@ class Block { $msg[$key] = wfMsgHtml( $key ); } } - + $expiry = Block::decodeExpiry( $encoded_expiry ); - if ($expiry == 'infinity') { + if ( $expiry == 'infinity' ) { $expirystr = $msg['infiniteblock']; } else { global $wgLang; - $expiredatestr = htmlspecialchars($wgLang->date( $expiry, true )); - $expiretimestr = htmlspecialchars($wgLang->time( $expiry, true )); + $expiredatestr = htmlspecialchars( $wgLang->date( $expiry, true ) ); + $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) ); $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) ); } return $expirystr; } - + /** * Convert a typed-in expiry time into something we can put into the database. * @param $expiry_input String: whatever was typed into the form @@ -861,7 +859,7 @@ class Block { $expiry = 'infinity'; } else { $expiry = strtotime( $expiry_input ); - if ($expiry < 0 || $expiry === false) { + if ( $expiry < 0 || $expiry === false ) { return false; } } diff --git a/includes/Revision.php b/includes/Revision.php index c4f8d617a1..afa273c7cc 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -119,11 +119,11 @@ class Revision { * @static */ public static function loadFromPageId( $db, $pageid, $id = 0 ) { - $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid )); + $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) ); if( $id ) { - $conds['rev_id']=intval($id); + $conds['rev_id'] = intval( $id ); } else { - $conds[]='rev_id=page_latest'; + $conds[] = 'rev_id=page_latest'; } return Revision::loadFromConds( $db, $conds ); } @@ -292,6 +292,7 @@ class Revision { 'old_flags' ); } + /** * Return the list of page fields that should be selected from page table */ @@ -370,11 +371,11 @@ class Revision { $this->mCurrent = false; # If we still have no len_size, see it we have the text to figure it out if ( !$this->mSize ) - $this->mSize = is_null($this->mText) ? null : strlen($this->mText); + $this->mSize = is_null( $this->mText ) ? null : strlen( $this->mText ); } else { throw new MWException( 'Revision constructor passed invalid row format.' ); } - $this->mUnpatrolled = NULL; + $this->mUnpatrolled = null; } /**#@+ @@ -496,9 +497,9 @@ class Revision { */ public function getUserText( $audience = self::FOR_PUBLIC ) { if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) { - return ""; + return ''; } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER ) ) { - return ""; + return ''; } else { return $this->mUserText; } @@ -526,9 +527,9 @@ class Revision { */ function getComment( $audience = self::FOR_PUBLIC ) { if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) { - return ""; + return ''; } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_COMMENT ) ) { - return ""; + return ''; } else { return $this->mComment; } @@ -553,7 +554,7 @@ class Revision { * @return int rcid of the unpatrolled row, zero if there isn't one */ public function isUnpatrolled() { - if( $this->mUnpatrolled !== NULL ) { + if( $this->mUnpatrolled !== null ) { return $this->mUnpatrolled; } $dbr = wfGetDB( DB_SLAVE ); @@ -575,9 +576,9 @@ class Revision { * @return bool */ public function isDeleted( $field ) { - return ($this->mDeleted & $field) == $field; + return ( $this->mDeleted & $field ) == $field; } - + /** * Get the deletion bitfield of the revision */ @@ -600,9 +601,9 @@ class Revision { */ public function getText( $audience = self::FOR_PUBLIC ) { if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_TEXT ) ) { - return ""; + return ''; } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_TEXT ) ) { - return ""; + return ''; } else { return $this->getRawText(); } @@ -675,7 +676,7 @@ class Revision { * @return int */ private function getPreviousRevisionId( $db ) { - if( is_null($this->mPage) ) { + if( is_null( $this->mPage ) ) { return 0; } # Use page_latest if ID is not given @@ -689,7 +690,7 @@ class Revision { __METHOD__, array( 'ORDER BY' => 'rev_id DESC' ) ); } - return intval($prevId); + return intval( $prevId ); } /** @@ -723,13 +724,13 @@ class Revision { # Use external methods for external objects, text in table is URL-only then if ( in_array( 'external', $flags ) ) { - $url=$text; - @list(/* $proto */,$path)=explode('://',$url,2); - if ($path=="") { + $url = $text; + @list(/* $proto */, $path ) = explode( '://', $url, 2 ); + if( $path == '' ) { wfProfileOut( __METHOD__ ); return false; } - $text=ExternalStore::fetchFromURL($url); + $text = ExternalStore::fetchFromURL( $url ); } // If the text was fetched without an error, convert it @@ -857,10 +858,10 @@ class Revision { ), __METHOD__ ); - $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId(); - + $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId(); + wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) ); - + wfProfileOut( __METHOD__ ); return $this->mId; } @@ -881,7 +882,7 @@ class Revision { if( $wgRevisionCacheExpiry ) { $text = $wgMemc->get( $key ); if( is_string( $text ) ) { - wfDebug( __METHOD__. ": got id $textId from cache\n" ); + wfDebug( __METHOD__ . ": got id $textId from cache\n" ); wfProfileOut( __METHOD__ ); return $text; } @@ -1016,7 +1017,7 @@ class Revision { static function getTimestampFromId( $title, $id ) { $dbr = wfGetDB( DB_SLAVE ); // Casting fix for DB2 - if ($id == '') { + if ( $id == '' ) { $id = 0; } $conds = array( 'rev_id' => $id ); diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index 54b96fe257..09bf84deeb 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -11,6 +11,7 @@ */ function wfSpecialBlockip( $par ) { global $wgUser, $wgOut, $wgRequest; + # Can't block when the database is locked if( wfReadOnly() ) { $wgOut->readOnlyPage(); @@ -27,7 +28,7 @@ function wfSpecialBlockip( $par ) { $action = $wgRequest->getVal( 'action' ); if( 'success' == $action ) { $ipb->showSuccess(); - } else if( $wgRequest->wasPosted() && 'submit' == $action && + } elseif( $wgRequest->wasPosted() && 'submit' == $action && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { $ipb->doSubmit(); } else { @@ -52,7 +53,7 @@ class IPBlockForm { $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' ); $this->BlockReason = $wgRequest->getText( 'wpBlockReason' ); $this->BlockReasonList = $wgRequest->getText( 'wpBlockReasonList' ); - $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg('ipbotheroption') ); + $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry', wfMsg( 'ipbotheroption' ) ); $this->BlockOther = $wgRequest->getVal( 'wpBlockOther', '' ); # Unchecked checkboxes are not included in the form data at all, so having one @@ -75,10 +76,10 @@ class IPBlockForm { public function showForm( $err ) { global $wgOut, $wgUser, $wgSysopUserBans; - $wgOut->setPagetitle( wfMsg( 'blockip' ) ); + $wgOut->setPageTitle( wfMsg( 'blockip' ) ); $wgOut->addWikiMsg( 'blockiptext' ); - if($wgSysopUserBans) { + if( $wgSysopUserBans ) { $mIpaddress = Xml::label( wfMsg( 'ipadressorusername' ), 'mw-bi-target' ); } else { $mIpaddress = Xml::label( wfMsg( 'ipaddress' ), 'mw-bi-target' ); @@ -90,11 +91,11 @@ class IPBlockForm { $titleObj = SpecialPage::getTitleFor( 'Blockip' ); $user = User::newFromName( $this->BlockAddress ); - + $alreadyBlocked = false; if( $err && $err[0] != 'ipb_already_blocked' ) { - $key = array_shift($err); - $msg = wfMsgReal($key, $err); + $key = array_shift( $err ); + $msg = wfMsgReal( $key, $err ); $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) ); } elseif( $this->BlockAddress ) { @@ -102,7 +103,7 @@ class IPBlockForm { if( is_object( $user ) ) $userId = $user->getId(); $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); - if( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock + if( !is_null( $currentBlock ) && !$currentBlock->mAuto && # The block exists and isn't an autoblock ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock # or if it is, the range is what we're about to block ( $currentBlock->mAddress == $this->BlockAddress ) ) ) { @@ -130,11 +131,11 @@ class IPBlockForm { if( !$showblockoptions ) $mIpbother = $mIpbexpiry; $blockExpiryFormOptions = Xml::option( wfMsg( 'ipbotheroption' ), 'other' ); - foreach (explode(',', $scBlockExpiryOptions) as $option) { - if( strpos($option, ":") === false ) $option = "$option:$option"; - list($show, $value) = explode(":", $option); - $show = htmlspecialchars($show); - $value = htmlspecialchars($value); + foreach( explode( ',', $scBlockExpiryOptions ) as $option ) { + if( strpos( $option, ':' ) === false ) $option = "$option:$option"; + list( $show, $value ) = explode( ':', $option ); + $show = htmlspecialchars( $show ); + $value = htmlspecialchars( $value ); $blockExpiryFormOptions .= Xml::option( $show, $value, $this->BlockExpiry === $value ? true : false ) . "\n"; } @@ -145,10 +146,10 @@ class IPBlockForm { global $wgStylePath, $wgStyleVersion; $wgOut->addHTML( Xml::tags( 'script', array( 'type' => 'text/javascript', 'src' => "$wgStylePath/common/block.js?$wgStyleVersion" ), '' ) . - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( "action=submit" ), 'id' => 'blockip' ) ) . + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'blockip-legend' ) ) . - Xml::openElement( 'table', array ( 'border' => '0', 'id' => 'mw-blockip-table' ) ) . + Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-blockip-table' ) ) . " {$mIpaddress} @@ -246,7 +247,7 @@ class IPBlockForm { " . Xml::checkLabel( wfMsg( 'ipbemailban' ), 'wpEmailBan', 'wpEmailBan', $this->BlockEmail, - array( 'tabindex' => '9' )) . " + array( 'tabindex' => '9' ) ) . " " ); @@ -265,7 +266,7 @@ class IPBlockForm { " ); } - + # Watchlist their user page? $wgOut->addHTML(" @@ -277,7 +278,7 @@ class IPBlockForm { " ); - + # Can we explicitly disallow the use of user_talk? global $wgBlockAllowsUTEdit; if( $wgBlockAllowsUTEdit ){ @@ -319,7 +320,7 @@ class IPBlockForm { $this->showLogFragment( $wgOut, Title::makeTitle( NS_USER, $this->BlockAddress ) ); } } - + /** * Can we do an email block? * @param User $user The sysop wanting to make a block @@ -327,7 +328,7 @@ class IPBlockForm { */ public static function canBlockEmail( $user ) { global $wgEnableUserEmail, $wgSysopEmailBans; - return ($wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' )); + return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) ); } /** @@ -353,18 +354,18 @@ class IPBlockForm { # IPv4 if( $wgSysopRangeBans ) { if( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) { - return array('ip_range_invalid'); + return array( 'ip_range_invalid' ); } $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); } else { # Range block illegal - return array('range_block_disabled'); + return array( 'range_block_disabled' ); } - } else if( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { + } elseif( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) { # IPv6 if( $wgSysopRangeBans ) { if( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) { - return array('ip_range_invalid'); + return array( 'ip_range_invalid' ); } $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); } else { @@ -380,10 +381,10 @@ class IPBlockForm { $userId = $user->getId(); $this->BlockAddress = $user->getName(); } else { - return array('nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) ); + return array( 'nosuchusershort', htmlspecialchars( $user ? $user->getName() : $this->BlockAddress ) ); } } else { - return array('badipaddress'); + return array( 'badipaddress' ); } } } @@ -404,26 +405,26 @@ class IPBlockForm { if( $expirestr == 'other' ) $expirestr = $this->BlockOther; - if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) { - return array('ipb_expiry_invalid'); + if( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50 ) ) { + return array( 'ipb_expiry_invalid' ); } - if( false === ($expiry = Block::parseExpiryInput( $expirestr )) ) { + if( false === ( $expiry = Block::parseExpiryInput( $expirestr ) ) ) { // Bad expiry. - return array('ipb_expiry_invalid'); + return array( 'ipb_expiry_invalid' ); } - + if( $this->BlockHideName ) { // Recheck params here... if( !$userId || !$wgUser->isAllowed('hideuser') ) { $this->BlockHideName = false; // IP users should not be hidden - } else if( $expiry !== 'infinity' ) { + } elseif( $expiry !== 'infinity' ) { // Bad expiry. - return array('ipb_expiry_temp'); - } else if( User::edits($userId) > self::HIDEUSER_CONTRIBLIMIT ) { + return array( 'ipb_expiry_temp' ); + } elseif( User::edits( $userId ) > self::HIDEUSER_CONTRIBLIMIT ) { // Typically, the user should have a handful of edits. // Disallow hiding users with many edits for performance. - return array('ipb_hide_invalid'); + return array( 'ipb_hide_invalid' ); } } @@ -437,7 +438,7 @@ class IPBlockForm { # Should this be privately logged? $suppressLog = (bool)$this->BlockHideName; - if( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) { + if( wfRunHooks( 'BlockIp', array( &$block, &$wgUser ) ) ) { # Try to insert block. Is there a conflicting block? if( !$block->insert() ) { # Show form unless the user is already aware of this... @@ -453,7 +454,7 @@ class IPBlockForm { } # If the name was hidden and the blocking user cannot hide # names, then don't allow any block changes... - if( $currentBlock->mHideName && !$wgUser->isAllowed('hideuser') ) { + if( $currentBlock->mHideName && !$wgUser->isAllowed( 'hideuser' ) ) { return array( 'cant-see-hidden-user' ); } $currentBlock->delete(); @@ -469,7 +470,7 @@ class IPBlockForm { } else { $log_action = 'block'; } - wfRunHooks('BlockIpComplete', array($block, $wgUser)); + wfRunHooks( 'BlockIpComplete', array( $block, $wgUser ) ); # Set *_deleted fields if requested if( $this->BlockHideName ) { @@ -480,7 +481,7 @@ class IPBlockForm { if( $this->BlockWatchUser && $block->mRangeStart == $block->mRangeEnd ) { $wgUser->addWatch( Title::makeTitle( NS_USER, $this->BlockAddress ) ); } - + # Block constructor sanitizes certain block options on insert $this->BlockEmail = $block->mBlockEmail; $this->BlockEnableAutoblock = $block->mEnableAutoblock; @@ -499,20 +500,20 @@ class IPBlockForm { # Report to the user return array(); } else { - return array('hookaborted'); + return array( 'hookaborted' ); } } - + public static function suppressUserName( $name, $userId ) { $op = '|'; // bitwise OR return self::setUsernameBitfields( $name, $userId, $op ); } - + public static function unsuppressUserName( $name, $userId ) { $op = '&'; // bitwise AND return self::setUsernameBitfields( $name, $userId, $op ); } - + private static function setUsernameBitfields( $name, $userId, $op ) { if( $op !== '|' && $op !== '&' ) return false; // sanity check $dbw = wfGetDB( DB_MASTER ); @@ -531,29 +532,29 @@ class IPBlockForm { $delAction = "~{$delAction}"; } # Hide name from live edits - $dbw->update( 'revision', array("rev_deleted = rev_deleted $op $delUser"), - array('rev_user' => $userId), __METHOD__ ); + $dbw->update( 'revision', array( "rev_deleted = rev_deleted $op $delUser" ), + array( 'rev_user' => $userId ), __METHOD__ ); # Hide name from deleted edits - $dbw->update( 'archive', array("ar_deleted = ar_deleted $op $delUser"), - array('ar_user_text' => $name), __METHOD__ ); + $dbw->update( 'archive', array( "ar_deleted = ar_deleted $op $delUser" ), + array( 'ar_user_text' => $name ), __METHOD__ ); # Hide name from logs - $dbw->update( 'logging', array("log_deleted = log_deleted $op $delUser"), - array('log_user' => $userId, "log_type != 'suppress'"), __METHOD__ ); - $dbw->update( 'logging', array("log_deleted = log_deleted $op $delAction"), - array('log_namespace' => NS_USER, 'log_title' => $userDbKey, - "log_type != 'suppress'"), __METHOD__ ); + $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delUser" ), + array( 'log_user' => $userId, "log_type != 'suppress'" ), __METHOD__ ); + $dbw->update( 'logging', array( "log_deleted = log_deleted $op $delAction" ), + array( 'log_namespace' => NS_USER, 'log_title' => $userDbKey, + "log_type != 'suppress'" ), __METHOD__ ); # Hide name from RC - $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delUser"), - array('rc_user_text' => $name), __METHOD__ ); - $dbw->update( 'recentchanges', array("rc_deleted = rc_deleted $op $delAction"), - array('rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0'), __METHOD__ ); + $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delUser" ), + array( 'rc_user_text' => $name ), __METHOD__ ); + $dbw->update( 'recentchanges', array( "rc_deleted = rc_deleted $op $delAction" ), + array( 'rc_namespace' => NS_USER, 'rc_title' => $userDbKey, 'rc_logid > 0' ), __METHOD__ ); # Hide name from live images - $dbw->update( 'oldimage', array("oi_deleted = oi_deleted $op $delUser"), - array('oi_user_text' => $name), __METHOD__ ); + $dbw->update( 'oldimage', array( "oi_deleted = oi_deleted $op $delUser" ), + array( 'oi_user_text' => $name ), __METHOD__ ); # Hide name from deleted images # WMF - schema change pending - # $dbw->update( 'filearchive', array("fa_deleted = fa_deleted $op $delUser"), - # array('fa_user_text' => $name), __METHOD__ ); + # $dbw->update( 'filearchive', array( "fa_deleted = fa_deleted $op $delUser" ), + # array( 'fa_user_text' => $name ), __METHOD__ ); # Done! return true; } @@ -565,7 +566,7 @@ class IPBlockForm { public function doSubmit() { global $wgOut; $retval = $this->doBlock(); - if( empty($retval) ) { + if( empty( $retval ) ) { $titleObj = SpecialPage::getTitleFor( 'Blockip' ); $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' . urlencode( $this->BlockAddress ) ) ); @@ -577,7 +578,7 @@ class IPBlockForm { public function showSuccess() { global $wgOut; - $wgOut->setPagetitle( wfMsg( 'blockip' ) ); + $wgOut->setPageTitle( wfMsg( 'blockip' ) ); $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress ); $wgOut->addHTML( $text ); @@ -673,7 +674,7 @@ class IPBlockForm { ); return ''; } - + /** * Build a convenient link to a user or IP's contribs * form @@ -707,7 +708,7 @@ class IPBlockForm { } return $skin->linkKnown( $list, - htmlspecialchars($message), + htmlspecialchars( $message ), array(), $query ); @@ -733,20 +734,20 @@ class IPBlockForm { return $skin->linkKnown( $list, - htmlspecialchars($message), + htmlspecialchars( $message ), array(), $query ); } - + /** - * Block a list of selected users - * @param array $users - * @param string $reason - * @param string $tag replaces user pages - * @param string $talkTag replaces user talk pages - * @returns array, list of html-safe usernames - */ + * Block a list of selected users + * @param array $users + * @param string $reason + * @param string $tag replaces user pages + * @param string $talkTag replaces user talk pages + * @returns array, list of html-safe usernames + */ public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) { global $wgUser; $counter = $blockSize = 0; @@ -763,7 +764,7 @@ class IPBlockForm { } $u = User::newFromName( $name, false ); // If user doesn't exist, it ought to be an IP then - if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) { + if( is_null( $u ) || ( !$u->getId() && !IP::isIPAddress( $u->getName() ) ) ) { continue; } $userTitle = $u->getUserPage(); @@ -802,10 +803,10 @@ class IPBlockForm { $log->addEntry( 'block', $userTitle, $reason, $logParams ); } # Tag userpage! (check length to avoid mistakes) - if( strlen($tag) > 2 ) { + if( strlen( $tag ) > 2 ) { $userpage->doEdit( $tag, $reason, EDIT_MINOR ); } - if( strlen($talkTag) > 2 ) { + if( strlen( $talkTag ) > 2 ) { $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR ); } } -- 2.20.1