From 2daa1fab7a200ac2045e1e03e17a19fea1792afe Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 11 May 2014 17:34:14 +0200 Subject: [PATCH] Make phpcs-strict pass on includes/ (3/~10) Change-Id: Ibf86d03b5479c47ee72c0dafea6777ef8178fe68 --- includes/SquidPurgeClient.php | 44 +++-- includes/StatCounter.php | 3 +- includes/StreamFile.php | 12 +- includes/StubObject.php | 15 +- includes/TimestampException.php | 3 +- includes/Title.php | 261 ++++++++++++++++++++++-------- includes/TitleArrayFromResult.php | 10 +- includes/User.php | 194 +++++++++++++++------- includes/UserArrayFromResult.php | 12 +- includes/UserMailer.php | 56 +++++-- 10 files changed, 440 insertions(+), 170 deletions(-) diff --git a/includes/SquidPurgeClient.php b/includes/SquidPurgeClient.php index 6cd7828dc7..c790bb7f90 100644 --- a/includes/SquidPurgeClient.php +++ b/includes/SquidPurgeClient.php @@ -28,12 +28,26 @@ * Could be replaced by curl_multi_exec() or some such. */ class SquidPurgeClient { - var $host, $port, $ip; + /** @var string */ + protected $host; - var $readState = 'idle'; - var $writeBuffer = ''; - var $requests = array(); - var $currentRequestIndex; + /** @var int */ + protected $port; + + /** @var string|bool */ + protected $ip; + + /** @var string */ + protected $readState = 'idle'; + + /** @var string */ + protected $writeBuffer = ''; + + /** @var array */ + protected $requests = array(); + + /** @var mixed */ + protected $currentRequestIndex; const EINTR = 4; const EAGAIN = 11; @@ -41,13 +55,16 @@ class SquidPurgeClient { const BUFFER_SIZE = 8192; /** - * The socket resource, or null for unconnected, or false for disabled due to error + * @var resource|null The socket resource, or null for unconnected, or false + * for disabled due to error. */ - var $socket; + protected $socket; - var $readBuffer; + /** @var string */ + protected $readBuffer; - var $bodyRemaining; + /** @var int */ + protected $bodyRemaining; /** * @param string $server @@ -380,12 +397,11 @@ class SquidPurgeClient { } class SquidPurgeClientPool { + /** @var array of SquidPurgeClient */ + protected $clients = array(); - /** - * @var array of SquidPurgeClient - */ - var $clients = array(); - var $timeout = 5; + /** @var int */ + protected $timeout = 5; /** * @param array $options diff --git a/includes/StatCounter.php b/includes/StatCounter.php index a429c3675e..102fffd0d9 100644 --- a/includes/StatCounter.php +++ b/includes/StatCounter.php @@ -39,7 +39,8 @@ class StatCounter { /** @var array */ protected $deltas = array(); // (key => count) - protected function __construct() {} + protected function __construct() { + } /** * @return StatCounter diff --git a/includes/StreamFile.php b/includes/StreamFile.php index ef82705988..2503150129 100644 --- a/includes/StreamFile.php +++ b/includes/StreamFile.php @@ -158,10 +158,14 @@ class StreamFile { # used for thumbnails (thumb.php) if ( $wgTrivialMimeDetection ) { switch ( $ext ) { - case 'gif': return 'image/gif'; - case 'png': return 'image/png'; - case 'jpg': return 'image/jpeg'; - case 'jpeg': return 'image/jpeg'; + case 'gif': + return 'image/gif'; + case 'png': + return 'image/png'; + case 'jpg': + return 'image/jpeg'; + case 'jpeg': + return 'image/jpeg'; } return 'unknown/unknown'; diff --git a/includes/StubObject.php b/includes/StubObject.php index bb173e7c71..64df81b2c3 100644 --- a/includes/StubObject.php +++ b/includes/StubObject.php @@ -42,7 +42,14 @@ * which refers to it should be kept to a minimum. */ class StubObject { - var $mGlobal, $mClass, $mParams; + /** @var null|string */ + protected $mGlobal; + + /** @var null|string */ + protected $mClass; + + /** @var array */ + protected $mParams; /** * Constructor. @@ -142,9 +149,11 @@ class StubObject { $caller = wfGetCaller( $level ); if ( ++$recursionLevel > 2 ) { wfProfileOut( $fname ); - throw new MWException( "Unstub loop detected on call of \${$this->mGlobal}->$name from $caller\n" ); + throw new MWException( "Unstub loop detected on call of " + . "\${$this->mGlobal}->$name from $caller\n" ); } - wfDebug( "Unstubbing \${$this->mGlobal} on call of \${$this->mGlobal}::$name from $caller\n" ); + wfDebug( "Unstubbing \${$this->mGlobal} on call of " + . "\${$this->mGlobal}::$name from $caller\n" ); $GLOBALS[$this->mGlobal] = $this->_newObject(); --$recursionLevel; wfProfileOut( $fname ); diff --git a/includes/TimestampException.php b/includes/TimestampException.php index 4345a73a6c..b9c0c35c71 100644 --- a/includes/TimestampException.php +++ b/includes/TimestampException.php @@ -3,4 +3,5 @@ /** * @since 1.20 */ -class TimestampException extends MWException {} +class TimestampException extends MWException { +} diff --git a/includes/Title.php b/includes/Title.php index 3933ba06e8..065a488b73 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -56,38 +56,102 @@ class Title { */ // @{ - var $mTextform = ''; // /< Text form (spaces not underscores) of the main part - var $mUrlform = ''; // /< URL-encoded form of the main part - var $mDbkeyform = ''; // /< Main part with underscores - var $mUserCaseDBKey; // /< DB key with the initial letter in the case specified by the user - var $mNamespace = NS_MAIN; // /< Namespace index, i.e. one of the NS_xxxx constants - var $mInterwiki = ''; // /< Interwiki prefix - var $mFragment = ''; // /< Title fragment (i.e. the bit after the #) - var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand - var $mLatestID = false; // /< ID of most recent revision - var $mContentModel = false; // /< ID of the page's content model, i.e. one of the CONTENT_MODEL_XXX constants - private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded - var $mRestrictions = array(); // /< Array of groups allowed to edit this article - var $mOldRestrictions = false; - var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images? - var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources - var $mRestrictionsExpiry = array(); ///< When do the restrictions on this page expire? - var $mHasCascadingRestrictions; ///< Are cascading restrictions in effect on this page? - var $mCascadeSources; ///< Where are the cascading restrictions coming from on this page? - var $mRestrictionsLoaded = false; ///< Boolean for initialisation on demand - var $mPrefixedText = null; ///< Text form including namespace/interwiki, initialised on demand - var $mTitleProtection; ///< Cached value for getTitleProtection (create protection) - # Don't change the following default, NS_MAIN is hardcoded in several - # places. See bug 696. - # Zero except in {{transclusion}} tags - var $mDefaultNamespace = NS_MAIN; // /< Namespace index when there is no namespace - var $mWatched = null; // /< Is $wgUser watching this page? null if unfilled, accessed through userIsWatching() - var $mLength = -1; // /< The page length, 0 for special pages - var $mRedirect = null; // /< Is the article at this title a redirect? - var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false - var $mHasSubpage; // /< Whether a page has any subpages - private $mPageLanguage = false; // /< The (string) language code of the page's language and content code. - private $mTitleValue = null; // /< A corresponding TitleValue object + /** @var string Text form (spaces not underscores) of the main part */ + public $mTextform = ''; + + /** @var string URL-encoded form of the main part */ + public $mUrlform = ''; + + /** @var string Main part with underscores */ + public $mDbkeyform = ''; + + /** @var string Database key with the initial letter in the case specified by the user */ + protected $mUserCaseDBKey; + + /** @var int Namespace index, i.e. one of the NS_xxxx constants */ + public $mNamespace = NS_MAIN; + + /** @var string Interwiki prefix */ + public $mInterwiki = ''; + + /** @var string Title fragment (i.e. the bit after the #) */ + public $mFragment = ''; + + /** @var int Article ID, fetched from the link cache on demand */ + public $mArticleID = -1; + + /** @var bool|int ID of most recent revision */ + protected $mLatestID = false; + + /** + * @var bool|string ID of the page's content model, i.e. one of the + * CONTENT_MODEL_XXX constants + */ + public $mContentModel = false; + + /** @var int Estimated number of revisions; null of not loaded */ + private $mEstimateRevisions; + + /** @var array Array of groups allowed to edit this article */ + public $mRestrictions = array(); + + /** @var bool */ + protected $mOldRestrictions = false; + + /** @var bool Cascade restrictions on this page to included templates and images? */ + public $mCascadeRestriction; + + /** Caching the results of getCascadeProtectionSources */ + public $mCascadingRestrictions; + + /** @var array When do the restrictions on this page expire? */ + protected $mRestrictionsExpiry = array(); + + /** @var bool Are cascading restrictions in effect on this page? */ + protected $mHasCascadingRestrictions; + + /** @var array Where are the cascading restrictions coming from on this page? */ + public $mCascadeSources; + + /** @var bool Boolean for initialisation on demand */ + public $mRestrictionsLoaded = false; + + /** @var string Text form including namespace/interwiki, initialised on demand */ + protected $mPrefixedText = null; + + /** @var mixed Cached value for getTitleProtection (create protection) */ + public $mTitleProtection; + + /** + * @var int Namespace index when there is no namespace. Don't change the + * following default, NS_MAIN is hardcoded in several places. See bug 696. + * Zero except in {{transclusion}} tags. + */ + public $mDefaultNamespace = NS_MAIN; + + /** + * @var bool Is $wgUser watching this page? null if unfilled, accessed + * through userIsWatching() + */ + protected $mWatched = null; + + /** @var int The page length, 0 for special pages */ + protected $mLength = -1; + + /** @var null Is the article at this title a redirect? */ + public $mRedirect = null; + + /** @var array Associative array of user ID -> timestamp/false */ + private $mNotificationTimestamp = array(); + + /** @var bool Whether a page has any subpages */ + var $mHasSubpages; + + /** @var bool The (string) language code of the page's language and content code. */ + private $mPageLanguage = false; + + /** @var TitleValue A corresponding TitleValue object */ + private $mTitleValue = null; // @} /** @@ -115,7 +179,11 @@ class Title { } if ( !$titleCodec ) { - $titleCodec = new MediaWikiTitleCodec( $wgContLang, GenderCache::singleton(), $wgLocalInterwikis ); + $titleCodec = new MediaWikiTitleCodec( + $wgContLang, + GenderCache::singleton(), + $wgLocalInterwikis + ); $titleCodecFingerprint = $fingerprint; } @@ -136,10 +204,8 @@ class Title { return self::getTitleParser(); } - /** - * Constructor - */ - /*protected*/ function __construct() { } + function __construct() { + } /** * Create a new Title from a prefixed DB key @@ -266,8 +332,9 @@ class Title { } /** - * Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries. - * Uses $wgContentHandlerUseDB to determine whether to include page_content_model. + * Returns a list of fields that are to be selected for initializing Title + * objects or LinkCache entries. Uses $wgContentHandlerUseDB to determine + * whether to include page_content_model. * * @return array */ @@ -1136,9 +1203,11 @@ class Title { * This is generally true for pages in the MediaWiki namespace having CONTENT_MODEL_CSS * or CONTENT_MODEL_JAVASCRIPT. * - * This method does *not* return true for per-user JS/CSS. Use isCssJsSubpage() for that! + * This method does *not* return true for per-user JS/CSS. Use isCssJsSubpage() + * for that! * - * Note that this method should not return true for pages that contain and show "inactive" CSS or JS. + * Note that this method should not return true for pages that contain and + * show "inactive" CSS or JS. * * @return bool */ @@ -1147,8 +1216,9 @@ class Title { && ( $this->hasContentModel( CONTENT_MODEL_CSS ) || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ); - #NOTE: this hook is also called in ContentHandler::getDefaultModel. It's called here again to make sure - # hook functions can force this method to return true even outside the mediawiki namespace. + # @note This hook is also called in ContentHandler::getDefaultModel. + # It's called here again to make sure hook functions can force this + # method to return true even outside the mediawiki namespace. wfRunHooks( 'TitleIsCssOrJsPage', array( $this, &$isCssOrJsPage ) ); @@ -1857,7 +1927,9 @@ class Title { global $wgUser; $user = $wgUser; } - return !count( $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries, true ) ); + + return !count( $this->getUserPermissionsErrorsInternal( + $action, $user, $doExpensiveQueries, true ) ); } /** @@ -1873,7 +1945,9 @@ class Title { * whose corresponding errors may be ignored. * @return array Array of arguments to wfMessage to explain permissions problems. */ - public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) { + public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, + $ignoreErrors = array() + ) { $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ); // Remove the errors being ignored. @@ -1899,8 +1973,12 @@ class Title { * * @return array List of errors */ - private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { - if ( !wfRunHooks( 'TitleQuickPermissions', array( $this, $user, $action, &$errors, $doExpensiveQueries, $short ) ) ) { + private function checkQuickPermissions( $action, $user, $errors, + $doExpensiveQueries, $short + ) { + if ( !wfRunHooks( 'TitleQuickPermissions', + array( $this, $user, $action, &$errors, $doExpensiveQueries, $short ) ) + ) { return $errors; } @@ -2028,7 +2106,9 @@ class Title { * * @return array List of errors */ - private function checkSpecialsAndNSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { + private function checkSpecialsAndNSPermissions( $action, $user, $errors, + $doExpensiveQueries, $short + ) { # Only 'createaccount' can be performed on special pages, # which don't actually exist in the DB. if ( NS_SPECIAL == $this->mNamespace && $action !== 'createaccount' ) { @@ -2127,7 +2207,9 @@ class Title { * * @return array List of errors */ - private function checkCascadingSourcesRestrictions( $action, $user, $errors, $doExpensiveQueries, $short ) { + private function checkCascadingSourcesRestrictions( $action, $user, $errors, + $doExpensiveQueries, $short + ) { if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) { # We /could/ use the protection level on the source page, but it's # fairly ugly as we have to establish a precedence hierarchy for pages @@ -2174,11 +2256,15 @@ class Title { * * @return array List of errors */ - private function checkActionPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { + private function checkActionPermissions( $action, $user, $errors, + $doExpensiveQueries, $short + ) { global $wgDeleteRevisionsLimit, $wgLang; if ( $action == 'protect' ) { - if ( count( $this->getUserPermissionsErrorsInternal( 'edit', $user, $doExpensiveQueries, true ) ) ) { + if ( count( $this->getUserPermissionsErrorsInternal( 'edit', + $user, $doExpensiveQueries, true ) ) + ) { // If they can't edit, they shouldn't protect. $errors[] = array( 'protect-cantedit' ); } @@ -2194,7 +2280,11 @@ class Title { if ( $title_protection['pt_create_perm'] == '' || !$user->isAllowed( $title_protection['pt_create_perm'] ) ) { - $errors[] = array( 'titleprotected', User::whoIs( $title_protection['pt_user'] ), $title_protection['pt_reason'] ); + $errors[] = array( + 'titleprotected', + User::whoIs( $title_protection['pt_user'] ), + $title_protection['pt_reason'] + ); } } } elseif ( $action == 'move' ) { @@ -2375,7 +2465,9 @@ class Title { * @param bool $short Set this to true to stop after the first permission error. * @return array Array of arrays of the arguments to wfMessage to explain permissions problems. */ - protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) { + protected function getUserPermissionsErrorsInternal( $action, $user, + $doExpensiveQueries = true, $short = false + ) { wfProfileIn( __METHOD__ ); # Read has special handling @@ -3380,7 +3472,15 @@ class Title { $namespaceFiled = "{$prefix}_namespace"; $titleField = "{$prefix}_title"; - $fields = array( $namespaceFiled, $titleField, 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ); + $fields = array( + $namespaceFiled, + $titleField, + 'page_id', + 'page_len', + 'page_is_redirect', + 'page_latest' + ); + if ( $wgContentHandlerUseDB ) { $fields[] = 'page_content_model'; } @@ -3391,7 +3491,10 @@ class Title { array( "{$prefix}_from" => $id ), __METHOD__, $options, - array( 'page' => array( 'LEFT JOIN', array( "page_namespace=$namespaceFiled", "page_title=$titleField" ) ) ) + array( 'page' => array( + 'LEFT JOIN', + array( "page_namespace=$namespaceFiled", "page_title=$titleField" ) + ) ) ); $retVal = array(); @@ -3427,9 +3530,11 @@ class Title { } /** - * Get an array of Title objects referring to non-existent articles linked from this page + * Get an array of Title objects referring to non-existent articles linked + * from this page. * - * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case) + * @todo check if needed (used only in SpecialBrokenRedirects.php, and + * should use redirect table in this case). * @return Title[] Array of Title the Title objects */ public function getBrokenLinksFrom() { @@ -3766,7 +3871,13 @@ class Title { $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason; } // @todo FIXME: $params? - $logId = $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ), $wgUser ); + $logId = $log->addEntry( + 'move_prot', + $nt, + $comment, + array( $this->getPrefixedText() ), + $wgUser + ); // reread inserted pr_ids for log relation $insertedPrIds = $dbw->select( @@ -3820,9 +3931,12 @@ class Title { } if ( $createRedirect ) { - if ( $this->getNamespace() == NS_CATEGORY && !wfMessage( 'category-move-redirect-override' )->isDisabled() ) { + if ( $this->getNamespace() == NS_CATEGORY + && !wfMessage( 'category-move-redirect-override' )->isDisabled() + ) { $redirectContent = new WikitextContent( - wfMessage( 'category-move-redirect-override' )->params( $nt->getPrefixedText() )->inContentLanguage()->plain() ); + wfMessage( 'category-move-redirect-override' ) + ->params( $nt->getPrefixedText() )->inContentLanguage()->plain() ); } else { $contentHandler = ContentHandler::getForTitle( $this ); $redirectContent = $contentHandler->makeRedirectContent( $nt, @@ -4038,7 +4152,10 @@ class Title { $this->mArticleID = $row ? intval( $row->page_id ) : 0; $this->mRedirect = $row ? (bool)$row->page_is_redirect : false; $this->mLatestID = $row ? intval( $row->page_latest ) : false; - $this->mContentModel = $row && isset( $row->page_content_model ) ? strval( $row->page_content_model ) : false; + $this->mContentModel = $row && isset( $row->page_content_model ) + ? strval( $row->page_content_model ) + : false; + if ( !$this->mRedirect ) { return false; } @@ -4567,7 +4684,9 @@ class Title { // Use always content language to avoid loading hundreds of languages // to get the link color. global $wgContLang; - list( $name, ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) ); + list( $name, ) = MessageCache::singleton()->figureMessage( + $wgContLang->lcfirst( $this->getText() ) + ); $message = wfMessage( $name )->inLanguage( $wgContLang )->useDatabase( false ); return $message->exists(); } @@ -4587,7 +4706,9 @@ class Title { return false; } - list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) ); + list( $name, $lang ) = MessageCache::singleton()->figureMessage( + $wgContLang->lcfirst( $this->getText() ) + ); $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false ); if ( $message->exists() ) { @@ -4850,9 +4971,12 @@ class Title { } if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) { - // Note that this may depend on user settings, so the cache should be only per-request. - // NOTE: ContentHandler::getPageLanguage() may need to load the content to determine the page language! - // Checking $wgLanguageCode hasn't changed for the benefit of unit tests. + // Note that this may depend on user settings, so the cache should + // be only per-request. + // NOTE: ContentHandler::getPageLanguage() may need to load the + // content to determine the page language! + // Checking $wgLanguageCode hasn't changed for the benefit of unit + // tests. $contentHandler = ContentHandler::getForTitle( $this ); $langObj = wfGetLangObj( $contentHandler->getPageLanguage( $this ) ); $this->mPageLanguage = array( $langObj->getCode(), $wgLanguageCode ); @@ -4885,8 +5009,9 @@ class Title { return $wgLang; } - //NOTE: can't be cached persistently, depends on user settings - //NOTE: ContentHandler::getPageViewLanguage() may need to load the content to determine the page language! + // @note Can't be cached persistently, depends on user settings. + // @note ContentHandler::getPageViewLanguage() may need to load the + // content to determine the page language! $contentHandler = ContentHandler::getForTitle( $this ); $pageLang = $contentHandler->getPageViewLanguage( $this ); return $pageLang; diff --git a/includes/TitleArrayFromResult.php b/includes/TitleArrayFromResult.php index 4fcb2eb16f..668ea54b91 100644 --- a/includes/TitleArrayFromResult.php +++ b/includes/TitleArrayFromResult.php @@ -25,12 +25,12 @@ */ class TitleArrayFromResult extends TitleArray implements Countable { + /** @var ResultWrapper */ + public $res; - /** - * @var ResultWrapper - */ - var $res; - var $key, $current; + public $key; + + public $current; function __construct( $res ) { $this->res = $res; diff --git a/includes/User.php b/includes/User.php index 8228f1c207..8198282e22 100644 --- a/includes/User.php +++ b/includes/User.php @@ -76,7 +76,7 @@ class User { * corresponding database fields must call a cache-clearing function. * @showinitializer */ - static $mCacheVars = array( + protected static $mCacheVars = array( // user table 'mId', 'mName', @@ -105,7 +105,7 @@ class User { * "right-$right". * @showinitializer */ - static $mCoreRights = array( + protected static $mCoreRights = array( 'apihighlimits', 'autoconfirmed', 'autopatrol', @@ -176,17 +176,45 @@ class User { 'viewmywatchlist', 'writeapi', ); + /** * String Cached results of getAllRights() */ - static $mAllRights = false; + protected static $mAllRights = false; /** @name Cache variables */ //@{ - var $mId, $mName, $mRealName, $mPassword, $mNewpassword, $mNewpassTime, - $mEmail, $mTouched, $mToken, $mEmailAuthenticated, - $mEmailToken, $mEmailTokenExpires, $mRegistration, $mEditCount, - $mGroups, $mOptionOverrides; + public $mId; + + public $mName; + + public $mRealName; + + public $mPassword; + + public $mNewpassword; + + public $mNewpassTime; + + public $mEmail; + + public $mTouched; + + protected $mToken; + + public $mEmailAuthenticated; + + protected $mEmailToken; + + protected $mEmailTokenExpires; + + protected $mRegistration; + + protected $mEditCount; + + public $mGroups; + + protected $mOptionOverrides; protected $mPasswordExpires; //@} @@ -195,12 +223,12 @@ class User { * Bool Whether the cache variables have been loaded. */ //@{ - var $mOptionsLoaded; + public $mOptionsLoaded; /** * Array with already loaded items or true if all items have been loaded. */ - private $mLoadedItems = array(); + protected $mLoadedItems = array(); //@} /** @@ -212,41 +240,55 @@ class User { * * Use the User::newFrom*() family of functions to set this. */ - var $mFrom; + public $mFrom; /** * Lazy-initialized variables, invalidated with clearInstanceCache */ - var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mRights, - $mBlockreason, $mEffectiveGroups, $mImplicitGroups, $mFormerGroups, $mBlockedGlobally, - $mLocked, $mHideName, $mOptions; + protected $mNewtalk; + + protected $mDatePreference; + + public $mBlockedby; + + protected $mHash; + + public $mRights; + + protected $mBlockreason; + + protected $mEffectiveGroups; + + protected $mImplicitGroups; + + protected $mFormerGroups; + + protected $mBlockedGlobally; + + protected $mLocked; + + public $mHideName; + + public $mOptions; /** * @var WebRequest */ private $mRequest; - /** - * @var Block - */ - var $mBlock; + /** @var Block */ + public $mBlock; - /** - * @var bool - */ - var $mAllowUsertalk; + /** @var bool */ + protected $mAllowUsertalk; - /** - * @var Block - */ + /** @var Block */ private $mBlockedFromCreateAccount = false; - /** - * @var array - */ + /** @var array */ private $mWatchedItems = array(); - static $idCacheByName = array(); + public static $idCacheByName = array(); /** * Lightweight constructor for an anonymous user. @@ -517,7 +559,12 @@ class User { } $dbr = wfGetDB( DB_SLAVE ); - $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), __METHOD__ ); + $s = $dbr->selectRow( + 'user', + array( 'user_id' ), + array( 'user_name' => $nt->getText() ), + __METHOD__ + ); if ( $s === false ) { $result = null; @@ -558,7 +605,8 @@ class User { * @return bool */ public static function isIP( $name ) { - return preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/', $name ) || IP::isIPv6( $name ); + return preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/', $name ) + || IP::isIPv6( $name ); } /** @@ -756,7 +804,9 @@ class User { } elseif ( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) { $status->error( 'password-name-match' ); return $status; - } elseif ( isset( $blockedLogins[$this->getName()] ) && $password == $blockedLogins[$this->getName()] ) { + } elseif ( isset( $blockedLogins[$this->getName()] ) + && $password == $blockedLogins[$this->getName()] + ) { $status->error( 'password-login-forbidden' ); return $status; } else { @@ -955,7 +1005,8 @@ class User { */ public static function randomPassword() { global $wgMinimalPasswordLength; - // Decide the final password length based on our min password length, stopping at a minimum of 10 chars + // Decide the final password length based on our min password length, + // stopping at a minimum of 10 chars. $length = max( 10, $wgMinimalPasswordLength ); // Multiply by 1.25 to get the number of hex characters we need $length = $length * 1.25; @@ -1086,14 +1137,16 @@ class User { } if ( $request->getSessionData( 'wsToken' ) ) { - $passwordCorrect = ( $proposedUser->getToken( false ) === $request->getSessionData( 'wsToken' ) ); + $passwordCorrect = + ( $proposedUser->getToken( false ) === $request->getSessionData( 'wsToken' ) ); $from = 'session'; } elseif ( $request->getCookie( 'Token' ) ) { # Get the token from DB/cache and clean it up to remove garbage padding. # This deals with historical problems with bugs and the default column value. $token = rtrim( $proposedUser->getToken( false ) ); // correct token // Make comparison in constant time (bug 61346) - $passwordCorrect = strlen( $token ) && $this->compareSecrets( $token, $request->getCookie( 'Token' ) ); + $passwordCorrect = strlen( $token ) + && $this->compareSecrets( $token, $request->getCookie( 'Token' ) ); $from = 'cookie'; } else { // No session or persistent login cookie @@ -1123,11 +1176,13 @@ class User { $passwordCorrect = false; } else { $result = 0; - for ( $i = 0; $i < strlen( $answer ); $i++ ) { + $answerLength = strlen( $answer ); + for ( $i = 0; $i < $answerLength; $i++ ) { $result |= ord( $answer[$i] ) ^ ord( $test[$i] ); } $passwordCorrect = ( $result == 0 ); } + return $passwordCorrect; } @@ -1148,7 +1203,12 @@ class User { } $dbr = wfGetDB( DB_MASTER ); - $s = $dbr->selectRow( 'user', self::selectFields(), array( 'user_id' => $this->mId ), __METHOD__ ); + $s = $dbr->selectRow( + 'user', + self::selectFields(), + array( 'user_id' => $this->mId ), + __METHOD__ + ); wfRunHooks( 'UserLoadFromDatabase', array( $this, &$s ) ); @@ -1722,10 +1782,11 @@ class User { /** * Check if user is blocked * - * @param bool $bFromSlave Whether to check the slave database instead of the master + * @param bool $bFromSlave Whether to check the slave database instead of + * the master. Hacked from false due to horrible probs on site. * @return bool True if blocked, false otherwise */ - public function isBlocked( $bFromSlave = true ) { // hacked from false due to horrible probs on site + public function isBlocked( $bFromSlave = true ) { return $this->getBlock( $bFromSlave ) instanceof Block && $this->getBlock()->prevents( 'edit' ); } @@ -2082,7 +2143,8 @@ class User { /** * Update the 'You have new messages!' status. * @param bool $val Whether the user has new messages - * @param Revision $curRev New, as yet unseen revision of the user talk page. Ignored if null or !$val. + * @param Revision $curRev New, as yet unseen revision of the user talk + * page. Ignored if null or !$val. */ public function setNewtalk( $val, $curRev = null ) { if ( wfReadOnly() ) { @@ -2266,7 +2328,8 @@ class User { /** * Get the user's current token. - * @param bool $forceCreation Force the generation of a new token if the user doesn't have one (default=true for backwards compatibility) + * @param bool $forceCreation Force the generation of a new token if the + * user doesn't have one (default=true for backwards compatibility). * @return string Token */ public function getToken( $forceCreation = true ) { @@ -2603,7 +2666,8 @@ class User { * * @see User::listOptionKinds * @param IContextSource $context - * @param array $options Assoc. array with options keys to check as keys. Defaults to $this->mOptions. + * @param array $options Assoc. array with options keys to check as keys. + * Defaults to $this->mOptions. * @return array the key => kind mapping data */ public function getOptionKinds( IContextSource $context, $options = null ) { @@ -3478,17 +3542,20 @@ class User { * Add a user to the database, return the user object * * @param string $name Username to add - * @param array $params Array of Strings Non-default parameters to save to the database as user_* fields: - * - password The user's password hash. Password logins will be disabled if this is omitted. - * - newpassword Hash for a temporary password that has been mailed to the user - * - email The user's email address - * - email_authenticated The email authentication timestamp - * - real_name The user's real name - * - options An associative array of non-default options - * - token Random authentication token. Do not set. - * - registration Registration timestamp. Do not set. - * - * @return User|null User object, or null if the username already exists + * @param array $params Array of Strings Non-default parameters to save to + * the database as user_* fields: + * - password: The user's password hash. Password logins will be disabled + * if this is omitted. + * - newpassword: Hash for a temporary password that has been mailed to + * the user. + * - email: The user's email address. + * - email_authenticated: The email authentication timestamp. + * - real_name: The user's real name. + * - options: An associative array of non-default options. + * - token: Random authentication token. Do not set. + * - registration: Registration timestamp. Do not set. + * + * @return User|null User object, or null if the username already exists. */ public static function createNew( $name, $params = array() ) { $user = new User; @@ -3659,7 +3726,8 @@ class User { if ( $this->mBlockedFromCreateAccount === false && !$this->isAllowed( 'ipblock-exempt' ) ) { $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() ); } - return $this->mBlockedFromCreateAccount instanceof Block && $this->mBlockedFromCreateAccount->prevents( 'createaccount' ) + return $this->mBlockedFromCreateAccount instanceof Block + && $this->mBlockedFromCreateAccount->prevents( 'createaccount' ) ? $this->mBlockedFromCreateAccount : false; } @@ -3818,7 +3886,8 @@ class User { * Generate a looking random token for various uses. * * @return string The new random token - * @deprecated since 1.20: Use MWCryptRand for secure purposes or wfRandomString for pseudo-randomness + * @deprecated since 1.20: Use MWCryptRand for secure purposes or + * wfRandomString for pseudo-randomness. */ public static function generateToken() { return MWCryptRand::generateHex( 32 ); @@ -3840,6 +3909,7 @@ class User { if ( $val != $sessionToken ) { wfDebug( "User::matchEditToken: broken session data\n" ); } + return $val == $sessionToken; } @@ -3898,7 +3968,8 @@ class User { * * @param string $subject Message subject * @param string $body Message body - * @param string $from Optional From address; if unspecified, default $wgPasswordSender will be used + * @param string $from Optional From address; if unspecified, default + * $wgPasswordSender will be used. * @param string $replyto Reply-To address * @return Status */ @@ -4284,8 +4355,11 @@ class User { */ public static function getImplicitGroups() { global $wgImplicitGroups; + $groups = $wgImplicitGroups; - wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); #deprecated, use $wgImplictGroups instead + # Deprecated, use $wgImplictGroups instead + wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); + return $groups; } @@ -4359,7 +4433,13 @@ class User { public static function changeableByGroup( $group ) { global $wgAddGroups, $wgRemoveGroups, $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; - $groups = array( 'add' => array(), 'remove' => array(), 'add-self' => array(), 'remove-self' => array() ); + $groups = array( + 'add' => array(), + 'remove' => array(), + 'add-self' => array(), + 'remove-self' => array() + ); + if ( empty( $wgAddGroups[$group] ) ) { // Don't add anything to $groups } elseif ( $wgAddGroups[$group] === true ) { diff --git a/includes/UserArrayFromResult.php b/includes/UserArrayFromResult.php index 0012b444b1..dd67acd8fd 100644 --- a/includes/UserArrayFromResult.php +++ b/includes/UserArrayFromResult.php @@ -21,12 +21,14 @@ */ class UserArrayFromResult extends UserArray implements Countable { + /** @var ResultWrapper */ + public $res; - /** - * @var ResultWrapper - */ - var $res; - var $key, $current; + /** @var int */ + public $key; + + /** @var */ + public $current; /** * @param ResultWrapper $res diff --git a/includes/UserMailer.php b/includes/UserMailer.php index 2885e6a500..d3e8cb8f72 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -81,7 +81,7 @@ class MailAddress { * Collection of static functions for sending mail */ class UserMailer { - static $mErrorString; + private static $mErrorString; /** * Send mail using a PEAR mailer @@ -160,7 +160,9 @@ class UserMailer { * @throws MWException * @return Status */ - public static function send( $to, $from, $subject, $body, $replyto = null, $contentType = 'text/plain; charset=UTF-8' ) { + public static function send( $to, $from, $subject, $body, $replyto = null, + $contentType = 'text/plain; charset=UTF-8' + ) { global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail; $mime = null; if ( !is_array( $to ) ) { @@ -268,7 +270,11 @@ class UserMailer { $body['text'] = str_replace( "\n", "\r\n", $body['text'] ); $body['html'] = str_replace( "\n", "\r\n", $body['html'] ); } - $mime = new Mail_mime( array( 'eol' => $endl, 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8' ) ); + $mime = new Mail_mime( array( + 'eol' => $endl, + 'text_charset' => 'UTF-8', + 'html_charset' => 'UTF-8' + ) ); $mime->setTXTBody( $body['text'] ); $mime->setHTMLBody( $body['html'] ); $body = $mime->get(); // must call get() before headers() @@ -360,7 +366,13 @@ class UserMailer { if ( $safeMode ) { $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers ); } else { - $sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); + $sent = mail( + $recip, + self::quotedPrintable( $subject ), + $body, + $headers, + $wgAdditionalMailParams + ); } } } catch ( Exception $e ) { @@ -501,7 +513,9 @@ class EmailNotification { * @param bool $oldid (default: false) * @param string $pageStatus (default: 'changed') */ - public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $pageStatus = 'changed' ) { + public function notifyOnPageChange( $editor, $title, $timestamp, $summary, + $minorEdit, $oldid = false, $pageStatus = 'changed' + ) { global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk; @@ -555,7 +569,10 @@ class EmailNotification { // Only send notification for non minor edits, unless $wgEnotifMinorEdits if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) { $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK ); - if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) { + if ( $wgEnotifUserTalk + && $isUserTalkPage + && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) + ) { $sendEmail = true; } } @@ -564,6 +581,7 @@ class EmailNotification { if ( !$sendEmail ) { return; } + if ( $wgEnotifUseJobQ ) { $params = array( 'editor' => $editor->getName(), @@ -578,7 +596,16 @@ class EmailNotification { $job = new EnotifNotifyJob( $title, $params ); JobQueueGroup::singleton()->push( $job ); } else { - $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus ); + $this->actuallyNotifyOnPageChange( + $editor, + $title, + $timestamp, + $summary, + $minorEdit, + $oldid, + $watchers, + $pageStatus + ); } } @@ -632,8 +659,10 @@ class EmailNotification { $userTalkId = false; if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) { - - if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) { + if ( $wgEnotifUserTalk + && $isUserTalkPage + && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) + ) { $targetUser = User::newFromName( $title->getText() ); $this->compose( $targetUser ); $userTalkId = $targetUser->getId(); @@ -768,7 +797,9 @@ class EmailNotification { } $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL(); - $keys['$HELPPAGE'] = wfExpandUrl( Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ) ); + $keys['$HELPPAGE'] = wfExpandUrl( + Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ) + ); # Replace this after transforming the message, bug 35019 $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary; @@ -858,8 +889,9 @@ class EmailNotification { function sendPersonalised( $watchingUser ) { global $wgContLang, $wgEnotifUseRealName; // From the PHP manual: - // Note: The to parameter cannot be an address in the form of "Something ". - // The mail command will not parse this properly while talking with the MTA. + // Note: The to parameter cannot be an address in the form of + // "Something ". The mail command will not parse + // this properly while talking with the MTA. $to = new MailAddress( $watchingUser ); # $PAGEEDITDATE is the time and date of the page change -- 2.20.1