From e61cb8218ba284d9d6e829dcf5734d051416b06c Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 4 Oct 2013 15:43:09 +0200 Subject: [PATCH] Update docs and declare visibility on class props Change-Id: Ib0f02202d075d4a56dc4e37b08d7ac9399e8c86c --- includes/ArrayUtils.php | 9 +-- includes/AuthPlugin.php | 59 +++++++------- includes/Exception.php | 38 +++++---- includes/GlobalFunctions.php | 117 ++++++++++++++++++--------- includes/Metadata.php | 15 ++-- includes/Status.php | 19 +++-- includes/cache/HTMLCacheUpdate.php | 2 - includes/db/LoadMonitor.php | 15 ++-- includes/diff/DifferenceEngine.php | 112 ++++++++++++++++--------- includes/filerepo/FileRepoStatus.php | 5 +- includes/logging/LogPager.php | 11 ++- includes/normal/UtfNormalTest.php | 1 + includes/upload/UploadFromChunks.php | 47 +++++++---- includes/upload/UploadFromStash.php | 44 +++++----- 14 files changed, 306 insertions(+), 188 deletions(-) diff --git a/includes/ArrayUtils.php b/includes/ArrayUtils.php index 985271f709..97a56e1ce9 100644 --- a/includes/ArrayUtils.php +++ b/includes/ArrayUtils.php @@ -14,9 +14,9 @@ class ArrayUtils { * justification for breaking compatibility with installations * compiled with ./configure --disable-hash. * - * @param $array The array to sort - * @param $key The string key - * @param $separator A separator used to delimit the array elements and the + * @param array $array Array to sort + * @param string $key + * @param string $separator A separator used to delimit the array elements and the * key. This can be chosen to provide backwards compatibility with * various consistent hash implementations that existed before this * function was introduced. @@ -35,8 +35,7 @@ class ArrayUtils { * Given an array of non-normalised probabilities, this function will select * an element and return the appropriate key * - * @param $weights array - * + * @param array $weights * @return bool|int|string */ public static function pickRandom( $weights ) { diff --git a/includes/AuthPlugin.php b/includes/AuthPlugin.php index 84cf3d5ece..c7b0c977cc 100644 --- a/includes/AuthPlugin.php +++ b/includes/AuthPlugin.php @@ -34,7 +34,6 @@ * someone logs in who can be authenticated externally. */ class AuthPlugin { - /** * @var string */ @@ -46,7 +45,7 @@ class AuthPlugin { * you might need to munge it (for instance, for lowercase initial * letters). * - * @param string $username username. + * @param string $username Username. * @return bool */ public function userExists( $username ) { @@ -60,8 +59,8 @@ class AuthPlugin { * you might need to munge it (for instance, for lowercase initial * letters). * - * @param string $username username. - * @param string $password user password. + * @param string $username Username. + * @param string $password User password. * @return bool */ public function authenticate( $username, $password ) { @@ -72,7 +71,7 @@ class AuthPlugin { /** * Modify options in the login template. * - * @param $template UserLoginTemplate object. + * @param UserLoginTemplate $template * @param string $type 'signup' or 'login'. Added in 1.16. */ public function modifyUITemplate( &$template, &$type ) { @@ -83,7 +82,7 @@ class AuthPlugin { /** * Set the domain this plugin is supposed to use when authenticating. * - * @param string $domain authentication domain. + * @param string $domain Authentication domain. */ public function setDomain( $domain ) { $this->domain = $domain; @@ -105,7 +104,7 @@ class AuthPlugin { /** * Check to see if the specific domain is a valid domain. * - * @param string $domain authentication domain. + * @param string $domain Authentication domain. * @return bool */ public function validDomain( $domain ) { @@ -121,7 +120,7 @@ class AuthPlugin { * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * - * @param $user User object + * @param User $user * @return bool */ public function updateUser( &$user ) { @@ -140,7 +139,7 @@ class AuthPlugin { * * This is just a question, and shouldn't perform any actions. * - * @return Boolean + * @return bool */ public function autoCreate() { return false; @@ -151,9 +150,9 @@ class AuthPlugin { * and use the same keys. 'Realname' 'Emailaddress' and 'Nickname' * all reference this. * - * @param $prop string + * @param string $prop * - * @return Boolean + * @return bool */ public function allowPropChange( $prop = '' ) { if ( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) { @@ -193,8 +192,8 @@ class AuthPlugin { * * Return true if successful. * - * @param $user User object. - * @param string $password password. + * @param User $user + * @param string $password Password. * @return bool */ public function setPassword( $user, $password ) { @@ -216,10 +215,10 @@ class AuthPlugin { * Update user groups in the external authentication database. * Return true if successful. * - * @param $user User object. - * @param $addgroups Groups to add. - * @param $delgroups Groups to remove. - * @return Boolean + * @param User $user + * @param array $addgroups Groups to add. + * @param array $delgroups Groups to remove. + * @return bool */ public function updateExternalDBGroups( $user, $addgroups, $delgroups = array() ) { return true; @@ -228,7 +227,7 @@ class AuthPlugin { /** * Check to see if external accounts can be created. * Return true if external accounts can be created. - * @return Boolean + * @return bool */ public function canCreateAccounts() { return false; @@ -238,11 +237,11 @@ class AuthPlugin { * Add a user to the external authentication database. * Return true if successful. * - * @param $user User: only the name should be assumed valid at this point - * @param $password String - * @param $email String - * @param $realname String - * @return Boolean + * @param User $user Only the name should be assumed valid at this point + * @param string $password + * @param string $email + * @param string $realname + * @return bool */ public function addUser( $user, $password, $email = '', $realname = '' ) { return true; @@ -254,7 +253,7 @@ class AuthPlugin { * * This is just a question, and shouldn't perform any actions. * - * @return Boolean + * @return bool */ public function strict() { return false; @@ -264,8 +263,8 @@ class AuthPlugin { * Check if a user should authenticate locally if the global authentication fails. * If either this or strict() returns true, local authentication is not used. * - * @param string $username username. - * @return Boolean + * @param string $username Username. + * @return bool */ public function strictUserAuth( $username ) { return false; @@ -279,8 +278,8 @@ class AuthPlugin { * The User object is passed by reference so it can be modified; don't * forget the & on your function declaration. * - * @param $user User object. - * @param $autocreate Boolean: True if user is being autocreated on login + * @param User $user + * @param bool $autocreate True if user is being autocreated on login */ public function initUser( &$user, $autocreate = false ) { # Override this to do something. @@ -289,7 +288,7 @@ class AuthPlugin { /** * If you want to munge the case of an account name before the final * check, now is your chance. - * @param $username string + * @param string $username * @return string */ public function getCanonicalName( $username ) { @@ -299,7 +298,7 @@ class AuthPlugin { /** * Get an instance of a User object * - * @param $user User + * @param User $user * * @return AuthPluginUser */ diff --git a/includes/Exception.php b/includes/Exception.php index 582ad9304a..aeafda8805 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -30,7 +30,6 @@ * @ingroup Exception */ class MWException extends Exception { - /** * Should the exception use $wgOut to output the error? * @@ -84,7 +83,9 @@ class MWException extends Exception { return null; // Just silently ignore } - if ( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[$name] ) ) { + if ( !array_key_exists( $name, $wgExceptionHooks ) || + !is_array( $wgExceptionHooks[$name] ) + ) { return null; } @@ -92,7 +93,11 @@ class MWException extends Exception { $callargs = array_merge( array( $this ), $args ); foreach ( $hooks as $hook ) { - if ( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) { // 'function' or array( 'class', hook' ) + if ( + is_string( $hook ) || + ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) + ) { + // 'function' or array( 'class', hook' ) $result = call_user_func_array( $hook, $callargs ); } else { $result = null; @@ -136,7 +141,8 @@ class MWException extends Exception { if ( $wgShowExceptionDetails ) { return '

' . nl2br( htmlspecialchars( $this->getMessage() ) ) . - '

Backtrace:

' . nl2br( htmlspecialchars( MWExceptionHandler::formatRedactedTrace( $this ) ) ) . + '

Backtrace:

' . + nl2br( htmlspecialchars( MWExceptionHandler::formatRedactedTrace( $this ) ) ) . "

\n"; } else { return "
" . @@ -492,11 +498,11 @@ class UserBlockedError extends ErrorPageError { class UserNotLoggedIn extends ErrorPageError { /** - * @param $reasonMsg A message key containing the reason for the error. + * @param string $reasonMsg A message key containing the reason for the error. * Optional, default: 'exception-nologin-text' - * @param $titleMsg A message key to set the page title. + * @param string $titleMsg A message key to set the page title. * Optional, default: 'exception-nologin' - * @param $params Parameters to wfMessage(). + * @param array $params Parameters to wfMessage(). * Optional, default: null */ public function __construct( @@ -630,10 +636,13 @@ class MWExceptionHandler { } } } else { - $message = "Unexpected non-MediaWiki exception encountered, of type \"" . get_class( $e ) . "\""; + $message = "Unexpected non-MediaWiki exception encountered, of type \"" . + get_class( $e ) . "\""; if ( $wgShowExceptionDetails ) { - $message .= "\nexception '" . get_class( $e ) . "' in " . $e->getFile() . ":" . $e->getLine() . "\nStack trace:\n" . self::formatRedactedTrace( $e ) . "\n"; + $message .= "\nexception '" . get_class( $e ) . "' in " . + $e->getFile() . ":" . $e->getLine() . "\nStack trace:\n" . + self::formatRedactedTrace( $e ) . "\n"; } if ( $cmdLine ) { @@ -651,8 +660,9 @@ class MWExceptionHandler { * @param string $message Failure text */ public static function printError( $message ) { - # NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602). - # Try to produce meaningful output anyway. Using echo may corrupt output to STDOUT though. + # NOTE: STDERR may not be available, especially if php-cgi is used from the + # command line (bug #15602). Try to produce meaningful output anyway. Using + # echo may corrupt output to STDOUT though. if ( defined( 'STDERR' ) ) { fwrite( STDERR, $message ); } else { @@ -690,7 +700,8 @@ class MWExceptionHandler { } /** - * Get the stack trace from the exception as a string, redacting certain function arguments in the process + * Get the stack trace from the exception as a string, redacting certain + * function arguments in the process. * @param Exception $e The exception * @return string The stack trace as a string */ @@ -748,12 +759,11 @@ class MWExceptionHandler { } } } - $finalExceptionText .= '(' . implode( ', ', $args ) . ")\n"; + $finalExceptionText .= '(' . implode( ', ', $args ) . ")\n"; } return $finalExceptionText . '#' . ( $i + 1 ) . ' {main}'; } - /** * Get the ID for this error. * diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a93387ee39..ef0ec2c00c 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -81,7 +81,6 @@ if ( !function_exists( 'mb_strpos' ) ) { function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { return Fallback::mb_strpos( $haystack, $needle, $offset, $encoding ); } - } if ( !function_exists( 'mb_strrpos' ) ) { @@ -283,8 +282,8 @@ function wfRandom() { # The maximum random value is "only" 2^31-1, so get two random # values to reduce the chance of dupes $max = mt_getrandmax() + 1; - $rand = number_format( ( mt_rand() * $max + mt_rand() ) - / $max / $max, 12, '.', '' ); + $rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max, 12, '.', '' ); + return $rand; } @@ -330,6 +329,7 @@ function wfRandomString( $length = 32 ) { */ function wfUrlencode( $s ) { static $needle; + if ( is_null( $s ) ) { $needle = null; return ''; @@ -337,7 +337,9 @@ function wfUrlencode( $s ) { if ( is_null( $needle ) ) { $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F' ); - if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) || ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false ) ) { + if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) || + ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false ) + ) { $needle[] = '%3A'; } } @@ -470,15 +472,17 @@ function wfAppendQuery( $url, $query ) { } /** - * Expand a potentially local URL to a fully-qualified URL. Assumes $wgServer + * Expand a potentially local URL to a fully-qualified URL. Assumes $wgServer * is correct. * * The meaning of the PROTO_* constants is as follows: * PROTO_HTTP: Output a URL starting with http:// * PROTO_HTTPS: Output a URL starting with https:// * PROTO_RELATIVE: Output a URL starting with // (protocol-relative URL) - * PROTO_CURRENT: Output a URL starting with either http:// or https:// , depending on which protocol was used for the current incoming request - * PROTO_CANONICAL: For URLs without a domain, like /w/index.php , use $wgCanonicalServer. For protocol-relative URLs, use the protocol of $wgCanonicalServer + * PROTO_CURRENT: Output a URL starting with either http:// or https:// , depending + * on which protocol was used for the current incoming request + * PROTO_CANONICAL: For URLs without a domain, like /w/index.php , use $wgCanonicalServer. + * For protocol-relative URLs, use the protocol of $wgCanonicalServer * PROTO_INTERNAL: Like PROTO_CANONICAL, but uses $wgInternalServer instead of $wgCanonicalServer * * @todo this won't work with current-path-relative URLs @@ -486,10 +490,9 @@ function wfAppendQuery( $url, $query ) { * * @param string $url either fully-qualified or a local path + query * @param $defaultProto Mixed: one of the PROTO_* constants. Determines the - * protocol to use if $url or $wgServer is - * protocol-relative + * protocol to use if $url or $wgServer is protocol-relative * @return string Fully-qualified URL, current-path-relative URL or false if - * no valid URL can be constructed + * no valid URL can be constructed */ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { global $wgServer, $wgCanonicalServer, $wgInternalServer; @@ -513,8 +516,9 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { if ( $serverHasProto ) { $defaultProto = $bits['scheme'] . '://'; } else { - // $wgCanonicalServer or $wgInternalServer doesn't have a protocol. This really isn't supposed to happen - // Fall back to HTTP in this ridiculous case + // $wgCanonicalServer or $wgInternalServer doesn't have a protocol. + // This really isn't supposed to happen. Fall back to HTTP in this + // ridiculous case. $defaultProto = PROTO_HTTP; } } @@ -524,7 +528,8 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { if ( substr( $url, 0, 2 ) == '//' ) { $url = $defaultProtoWithoutSlashes . $url; } elseif ( substr( $url, 0, 1 ) == '/' ) { - // If $serverUrl is protocol-relative, prepend $defaultProtoWithoutSlashes, otherwise leave it alone + // If $serverUrl is protocol-relative, prepend $defaultProtoWithoutSlashes, + // otherwise leave it alone. $url = ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url; } @@ -739,9 +744,10 @@ function wfUrlProtocolsWithoutProtRel() { /** * parse_url() work-alike, but non-broken. Differences: * - * 1) Does not raise warnings on bad URLs (just returns false) - * 2) Handles protocols that don't use :// (e.g., mailto: and news: , as well as protocol-relative URLs) correctly - * 3) Adds a "delimiter" element to the array, either '://', ':' or '//' (see (2)) + * 1) Does not raise warnings on bad URLs (just returns false). + * 2) Handles protocols that don't use :// (e.g., mailto: and news:, as well as + * protocol-relative URLs) correctly. + * 3) Adds a "delimiter" element to the array, either '://', ':' or '//' (see (2)). * * @param string $url a URL to parse * @return Array: bits of the URL in an associative array, per PHP docs @@ -749,8 +755,9 @@ function wfUrlProtocolsWithoutProtRel() { function wfParseUrl( $url ) { global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php - // Protocol-relative URLs are handled really badly by parse_url(). It's so bad that the easiest - // way to handle them is to just prepend 'http:' and strip the protocol out later + // Protocol-relative URLs are handled really badly by parse_url(). It's so + // bad that the easiest way to handle them is to just prepend 'http:' and + // strip the protocol out later. $wasRelative = substr( $url, 0, 2 ) == '//'; if ( $wasRelative ) { $url = "http:$url"; @@ -816,7 +823,11 @@ function wfParseUrl( $url ) { * @return string */ function wfExpandIRI( $url ) { - return preg_replace_callback( '/((?:%[89A-F][0-9A-F])+)/i', 'wfExpandIRI_callback', wfExpandUrl( $url ) ); + return preg_replace_callback( + '/((?:%[89A-F][0-9A-F])+)/i', + 'wfExpandIRI_callback', + wfExpandUrl( $url ) + ); } /** @@ -1053,7 +1064,8 @@ function wfLogDBError( $text ) { * Throws a warning that $function is deprecated * * @param $function String - * @param string|bool $version Version of MediaWiki that the function was deprecated in (Added in 1.19). + * @param string|bool $version Version of MediaWiki that the function + * was deprecated in (Added in 1.19). * @param string|bool $component Added in 1.19. * @param $callerOffset integer: How far up the call stack is the original * caller. 2 = function that called the function that called @@ -2325,7 +2337,15 @@ function wfSuppressWarnings( $end = false ) { } } else { if ( !$suppressCount ) { - $originalLevel = error_reporting( E_ALL & ~( E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT ) ); + $originalLevel = error_reporting( E_ALL & ~( + E_WARNING | + E_NOTICE | + E_USER_WARNING | + E_USER_NOTICE | + E_DEPRECATED | + E_USER_DEPRECATED | + E_STRICT + ) ); } ++$suppressCount; } @@ -2656,12 +2676,14 @@ function wfEscapeShellArg() { if ( wfIsWindows() ) { // Escaping for an MSVC-style command line parser and CMD.EXE + // @codingStandardsIgnoreStart For long URLs // Refs: // * http://web.archive.org/web/20020708081031/http://mailman.lyra.org/pipermail/scite-interest/2002-March/000436.html // * http://technet.microsoft.com/en-us/library/cc723564.aspx // * Bug #13518 // * CR r63214 // Double the backslashes before any double quotes. Escape the double quotes. + // @codingStandardsIgnoreEnd $tokens = preg_split( '/(\\\\*")/', $arg, -1, PREG_SPLIT_DELIM_CAPTURE ); $arg = ''; $iteration = 0; @@ -2736,7 +2758,9 @@ function wfShellExecDisabled() { * * @return string collected stdout as a string */ -function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array(), $options = array() ) { +function wfShellExec( $cmd, &$retval = null, $environ = array(), + $limits = array(), $options = array() +) { global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime, $wgMaxShellWallClockTime, $wgShellCgroup; @@ -3222,9 +3246,12 @@ function wfUseMW( $req_ver ) { * @return String */ function wfBaseName( $path, $suffix = '' ) { - $encSuffix = ( $suffix == '' ) - ? '' - : ( '(?:' . preg_quote( $suffix, '#' ) . ')?' ); + if ( $suffix == '' ) { + $encSuffix = ''; + } else { + $encSuffix = '(?:' . preg_quote( $suffix, '#' ) . ')?'; + } + $matches = array(); if ( preg_match( "#([^/\\\\]*?){$encSuffix}[/\\\\]*$#", $path, $matches ) ) { return $matches[1]; @@ -3305,7 +3332,9 @@ function wfDoUpdates( $commit = '' ) { * @param string $engine Either "gmp", "bcmath", or "php" * @return string|bool The output number as a string, or false on error */ -function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = true, $engine = 'auto' ) { +function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, + $lowercase = true, $engine = 'auto' +) { $input = (string)$input; if ( $sourceBase < 2 || @@ -3315,7 +3344,10 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = t $sourceBase != (int)$sourceBase || $destBase != (int)$destBase || $pad != (int)$pad || - !preg_match( "/^[" . substr( '0123456789abcdefghijklmnopqrstuvwxyz', 0, $sourceBase ) . "]+$/i", $input ) + !preg_match( + "/^[" . substr( '0123456789abcdefghijklmnopqrstuvwxyz', 0, $sourceBase ) . "]+$/i", + $input + ) ) { return false; } @@ -3449,9 +3481,11 @@ function wfFixSessionID() { // We treat it as disabled if it doesn't have an entropy length of at least 32 $entropyEnabled = wfCheckEntropy(); - // If built-in entropy is not enabled or not sufficient override php's built in session id generation code + // If built-in entropy is not enabled or not sufficient override PHP's + // built in session id generation code if ( !$entropyEnabled ) { - wfDebug( __METHOD__ . ": PHP's built in entropy is disabled or not sufficient, overriding session id generation using our cryptrand source.\n" ); + wfDebug( __METHOD__ . ": PHP's built in entropy is disabled or not sufficient, " . + "overriding session id generation using our cryptrand source.\n" ); session_id( MWCryptRand::generateHex( 32 ) ); } } @@ -3757,9 +3791,7 @@ function wfBoolToStr( $value ) { * @return string */ function wfGetNull() { - return wfIsWindows() - ? 'NUL' - : '/dev/null'; + return wfIsWindows() ? 'NUL' : '/dev/null'; } /** @@ -3769,14 +3801,17 @@ function wfGetNull() { * in maintenance scripts, to avoid causing too much lag. Of course, this is * a no-op if there are no slaves. * - * @param $maxLag Integer (deprecated) - * @param $wiki mixed Wiki identifier accepted by wfGetLB - * @param $cluster string cluster name accepted by LBFactory + * @param int|bool $maxLag (deprecated) + * @param mixed $wiki Wiki identifier accepted by wfGetLB + * @param string|bool $cluster Cluster name accepted by LBFactory. Default: false. */ function wfWaitForSlaves( $maxLag = false, $wiki = false, $cluster = false ) { - $lb = ( $cluster !== false ) - ? wfGetLBFactory()->getExternalLB( $cluster ) - : wfGetLB( $wiki ); + if( $cluster !== false ) { + $lb = wfGetLBFactory()->getExternalLB( $cluster ); + } else { + $lb = wfGetLB( $wiki ); + } + // bug 27975 - Don't try to wait for slaves if there are none // Prevents permission error when getting master position if ( $lb->getServerCount() > 1 ) { @@ -3831,8 +3866,10 @@ function wfCountDown( $n ) { * characters before hashing. * @return string * @codeCoverageIgnore - * @deprecated since 1.20; Please use MWCryptRand for security purposes and wfRandomString for pseudo-random strings - * @warning This method is NOT secure. Additionally it has many callers that use it for pseudo-random purposes. + * @deprecated since 1.20; Please use MWCryptRand for security purposes and + * wfRandomString for pseudo-random strings + * @warning This method is NOT secure. Additionally it has many callers that + * use it for pseudo-random purposes. */ function wfGenerateToken( $salt = '' ) { wfDeprecated( __METHOD__, '1.20' ); diff --git a/includes/Metadata.php b/includes/Metadata.php index 37df489c9d..ea89f524bb 100644 --- a/includes/Metadata.php +++ b/includes/Metadata.php @@ -28,10 +28,10 @@ abstract class RdfMetaData { /** * Constructor - * @param $article Article object + * @param Page $page */ - public function __construct( Page $article ) { - $this->mArticle = $article; + public function __construct( Page $page ) { + $this->mArticle = $page; } abstract public function show(); @@ -40,7 +40,10 @@ abstract class RdfMetaData { global $wgOut, $wgRequest; $httpaccept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : null; - $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) ); + $rdftype = wfNegotiateType( + wfAcceptToPrefs( $httpaccept ), + wfAcceptToPrefs( self::RDF_TYPE_PREFS ) + ); if ( !$rdftype ) { throw new HttpError( 406, wfMessage( 'notacceptable' ) ); @@ -103,8 +106,8 @@ abstract class RdfMetaData { } /** - * @param $name string - * @param $title Title + * @param string $name + * @param Title $title */ protected function page( $name, $title ) { $this->url( $name, $title->getFullURL() ); diff --git a/includes/Status.php b/includes/Status.php index 928f8ebd61..836c24a459 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -38,16 +38,18 @@ * so that a lack of error-handling will be explicit. */ class Status { - var $ok = true; - var $value; + public $ok = true; + public $value; /** Counters for batch operations */ - public $successCount = 0, $failCount = 0; + public $successCount = 0; + public $failCount = 0; + /** Array to indicate which items of the batch operations were successful */ public $success = array(); - /*semi-private*/ var $errors = array(); - /*semi-private*/ var $cleanCallback = false; + public $errors = array(); + public $cleanCallback = false; /** * Factory function for fatal errors @@ -347,7 +349,6 @@ class Status { /** * Returns a list of status messages of the given type * @param $type String - * * @return Array */ protected function getStatusArray( $type ) { @@ -355,7 +356,10 @@ class Status { foreach ( $this->errors as $error ) { if ( $error['type'] === $type ) { if ( $error['message'] instanceof Message ) { - $result[] = array_merge( array( $error['message']->getKey() ), $error['message']->getParams() ); + $result[] = array_merge( + array( $error['message']->getKey() ), + $error['message']->getParams() + ); } elseif ( $error['params'] ) { $result[] = array_merge( array( $error['message'] ), $error['params'] ); } else { @@ -363,6 +367,7 @@ class Status { } } } + return $result; } diff --git a/includes/cache/HTMLCacheUpdate.php b/includes/cache/HTMLCacheUpdate.php index 992809efcd..4147424c2a 100644 --- a/includes/cache/HTMLCacheUpdate.php +++ b/includes/cache/HTMLCacheUpdate.php @@ -37,8 +37,6 @@ class HTMLCacheUpdate implements DeferrableUpdate { /** * @param $titleTo * @param $table - * @param $start bool - * @param $end bool */ function __construct( Title $titleTo, $table ) { $this->mTitle = $titleTo; diff --git a/includes/db/LoadMonitor.php b/includes/db/LoadMonitor.php index 519e2dfd0e..f10d07f898 100644 --- a/includes/db/LoadMonitor.php +++ b/includes/db/LoadMonitor.php @@ -36,9 +36,9 @@ interface LoadMonitor { /** * Perform pre-connection load ratio adjustment. - * @param $loads array - * @param string $group the selected query group - * @param $wiki String + * @param array $loads + * @param string|bool $group the selected query group. Default: false + * @param string|bool $wiki Default: false */ function scaleLoads( &$loads, $group = false, $wiki = false ); @@ -71,6 +71,10 @@ interface LoadMonitor { function getLagTimes( $serverIndexes, $wiki ); } +/** + * @todo FIXME: Should be LoadMonitorNull per naming conventions. + * PHP CodeSniffer Squiz.Classes.ValidClassName.NotCamelCaps + */ class LoadMonitor_Null implements LoadMonitor { function __construct( $parent ) { } @@ -96,13 +100,14 @@ class LoadMonitor_Null implements LoadMonitor { * Uses memcached to cache the replication lag for a short time * * @ingroup Database + * @todo FIXME: Should be LoadMonitorMySQL per naming conventions. + * PHP CodeSniffer Squiz.Classes.ValidClassName.NotCamelCaps */ class LoadMonitor_MySQL implements LoadMonitor { - /** * @var LoadBalancer */ - var $parent; + public $parent; /** * @param LoadBalancer $parent diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 0dd9af0844..39f8a47fa8 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -34,37 +34,40 @@ define( 'MW_DIFF_VERSION', '1.11a' ); * @ingroup DifferenceEngine */ class DifferenceEngine extends ContextSource { - /**#@+ - * @private - */ - var $mOldid, $mNewid; - var $mOldTags, $mNewTags; + public $mOldid; + public $mNewid; + private $mOldTags; + private $mNewTags; + /** * @var Content */ - var $mOldContent, $mNewContent; + public $mOldContent; + public $mNewContent; protected $mDiffLang; /** * @var Title */ - var $mOldPage, $mNewPage; + public $mOldPage; + public $mNewPage; /** * @var Revision */ - var $mOldRev, $mNewRev; + public $mOldRev; + public $mNewRev; private $mRevisionsIdsLoaded = false; // Have the revisions IDs been loaded - var $mRevisionsLoaded = false; // Have the revisions been loaded - var $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2? - var $mCacheHit = false; // Was the diff fetched from cache? + public $mRevisionsLoaded = false; // Have the revisions been loaded + public $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2? + public $mCacheHit = false; // Was the diff fetched from cache? /** * Set this to true to add debug info to the HTML output. * Warning: this may cause RSS readers to spuriously mark articles as "new" * (bug 20601) */ - var $enableDebugComment = false; + public $enableDebugComment = false; // If true, line X is not displayed when X is 1, for example to increase // readability and conserve space with many small diffs. @@ -80,14 +83,14 @@ class DifferenceEngine extends ContextSource { * Constructor * @param $context IContextSource context to use, anything else will be ignored * @param $old Integer old ID we want to show and diff with. - * @param $new String either 'prev' or 'next'. + * @param $new String|int either 'prev' or 'next'. Default: 0. * @param $rcid Integer Deprecated, no longer used! * @param $refreshCache boolean If set, refreshes the diff cache * @param $unhide boolean If set, allow viewing deleted revs */ function __construct( $context = null, $old = 0, $new = 0, $rcid = 0, - $refreshCache = false, $unhide = false ) - { + $refreshCache = false, $unhide = false + ) { if ( $context instanceof IContextSource ) { $this->setContext( $context ); } @@ -259,8 +262,8 @@ class DifferenceEngine extends ContextSource { $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) ); $samePage = true; } else { - $out->setPageTitle( $this->msg( 'difference-title-multipage', $this->mOldPage->getPrefixedText(), - $this->mNewPage->getPrefixedText() ) ); + $out->setPageTitle( $this->msg( 'difference-title-multipage', + $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) ); $out->addSubtitle( $this->msg( 'difference-multipage' ) ); $samePage = false; } @@ -273,7 +276,10 @@ class DifferenceEngine extends ContextSource { $rollback = '   ' . $rollbackLink; } } - if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) { + + if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && + !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) + ) { $undoLink = Html::element( 'a', array( 'href' => $this->mNewPage->getLocalURL( array( 'action' => 'edit', @@ -359,7 +365,8 @@ class DifferenceEngine extends ContextSource { foreach ( $revisionTools as $tool ) { $formattedRevisionTools[] = $this->msg( 'parentheses' )->rawParams( $tool )->escaped(); } - $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) . ' ' . implode( ' ', $formattedRevisionTools ); + $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) . + ' ' . implode( ' ', $formattedRevisionTools ); $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' ); $newHeader = '
' . $newRevisionHeader . '
' . @@ -390,9 +397,13 @@ class DifferenceEngine extends ContextSource { array( $msg ) ); } else { # Give explanation and add a link to view the diff... - $link = $this->getTitle()->getFullURL( $this->getRequest()->appendQueryValue( 'unhide', '1', true ) ); + $query = $this->getRequest()->appendQueryValue( 'unhide', '1', true ); + $link = $this->getTitle()->getFullURL( $query ); $msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff'; - $out->wrapWikiMsg( "\n", array( $msg, $link ) ); + $out->wrapWikiMsg( + "\n", + array( $msg, $link ) + ); } # Otherwise, output a regular diff... } else { @@ -400,7 +411,9 @@ class DifferenceEngine extends ContextSource { $notice = ''; if ( $deleted ) { $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view'; - $notice = "\n"; + $notice = "\n"; } $this->showDiff( $oldHeader, $newHeader, $notice ); if ( !$diffOnly ) { @@ -505,6 +518,7 @@ class DifferenceEngine extends ContextSource { $out->addHTML( "

{$revHeader}

\n" ); # Page content may be handled by a hooked call instead... + # @codingStandardsIgnoreStart Ignoring long lines. if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $out ) ) ) { $this->loadNewText(); $out->setRevisionId( $this->mNewid ); @@ -560,6 +574,8 @@ class DifferenceEngine extends ContextSource { } } } + # @codingStandardsIgnoreEnd + # Add redundant patrol link on bottom... $out->addHTML( $this->markPatrolledLink() ); @@ -581,6 +597,9 @@ class DifferenceEngine extends ContextSource { * Get the diff text, send it to the OutputPage object * Returns false if the diff could not be generated, otherwise returns true * + * @param string|bool $otitle Header for old text or false + * @param string|bool $ntitle Header for new text or false + * @param string $notice * @return bool */ function showDiff( $otitle, $ntitle, $notice = '' ) { @@ -614,14 +633,17 @@ class DifferenceEngine extends ContextSource { $body = $this->getDiffBody(); if ( $body === false ) { return false; - } else { - $multi = $this->getMultiNotice(); - // Display a message when the diff is empty - if ( $body === '' ) { - $notice .= '
' . $this->msg( 'diff-empty' )->parse() . "
\n"; - } - return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice ); } + + $multi = $this->getMultiNotice(); + // Display a message when the diff is empty + if ( $body === '' ) { + $notice .= '
' . + $this->msg( 'diff-empty' )->parse() . + "
\n"; + } + + return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice ); } /** @@ -637,10 +659,14 @@ class DifferenceEngine extends ContextSource { if ( !$this->loadRevisionData() ) { wfProfileOut( __METHOD__ ); return false; - } elseif ( $this->mOldRev && !$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { + } elseif ( $this->mOldRev && + !$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) + ) { wfProfileOut( __METHOD__ ); return false; - } elseif ( $this->mNewRev && !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { + } elseif ( $this->mNewRev && + !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) + ) { wfProfileOut( __METHOD__ ); return false; } @@ -961,11 +987,16 @@ class DifferenceEngine extends ContextSource { $editQuery['oldid'] = $rev->getID(); } - $msg = $this->msg( $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold' )->escaped(); + $key = $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold'; + $msg = $this->msg( $key )->escaped(); $header .= ' ' . $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $msg, array(), $editQuery ) )->plain(); if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) { - $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header ); + $header = Html::rawElement( + 'span', + array( 'class' => 'history-deleted' ), + $header + ); } } else { $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header ); @@ -1014,7 +1045,8 @@ class DifferenceEngine extends ContextSource { } if ( $multi != '' ) { - $header .= "{$multi}"; + $header .= "{$multi}"; } if ( $notice != '' ) { $header .= "{$notice}"; @@ -1130,9 +1162,15 @@ class DifferenceEngine extends ContextSource { $this->loadRevisionIds(); // Load the new revision object - $this->mNewRev = $this->mNewid - ? Revision::newFromId( $this->mNewid ) - : Revision::newFromTitle( $this->getTitle(), false, Revision::READ_NORMAL ); + if ( $this->mNewid ) { + $this->mNewRev = Revision::newFromId( $this->mNewid ); + } else { + $this->mNewRev = Revision::newFromTitle( + $this->getTitle(), + false, + Revision::READ_NORMAL + ); + } if ( !$this->mNewRev instanceof Revision ) { return false; diff --git a/includes/filerepo/FileRepoStatus.php b/includes/filerepo/FileRepoStatus.php index 6f28b104bc..5300e5ee19 100644 --- a/includes/filerepo/FileRepoStatus.php +++ b/includes/filerepo/FileRepoStatus.php @@ -29,8 +29,7 @@ class FileRepoStatus extends Status { /** * Factory function for fatal errors * - * @param $repo FileRepo - * + * @param FileRepo $repo * @return FileRepoStatus */ static function newFatal( $repo /*, parameters...*/ ) { @@ -42,7 +41,7 @@ class FileRepoStatus extends Status { } /** - * @param $repo FileRepo + * @param FileRepo|bool $repo Default: false * @param $value * @return FileRepoStatus */ diff --git a/includes/logging/LogPager.php b/includes/logging/LogPager.php index 09ae3b8ce9..a11dcb7d85 100644 --- a/includes/logging/LogPager.php +++ b/includes/logging/LogPager.php @@ -27,7 +27,10 @@ * @ingroup Pager */ class LogPager extends ReverseChronologicalPager { - private $types = array(), $performer = '', $title = '', $pattern = ''; + private $types = array(); + private $performer = ''; + private $title = ''; + private $pattern = ''; private $typeCGI = ''; public $mLogEventsList; @@ -35,13 +38,13 @@ class LogPager extends ReverseChronologicalPager { * Constructor * * @param LogEventsList $list - * @param string $types or Array: log types to show + * @param string|array $types Log types to show * @param string $performer the user who made the log entries * @param string|Title $title the page title the log entries are for * @param string $pattern do a prefix search rather than an exact title match * @param array $conds extra conditions for the query - * @param int $year The year to start from - * @param int $month The month to start from + * @param int|bool $year The year to start from. Default: false + * @param int|bool $month The month to start from. Default: false * @param string $tagFilter tag */ public function __construct( $list, $types = array(), $performer = '', $title = '', $pattern = '', diff --git a/includes/normal/UtfNormalTest.php b/includes/normal/UtfNormalTest.php index 511836666e..ad913b1cf5 100644 --- a/includes/normal/UtfNormalTest.php +++ b/includes/normal/UtfNormalTest.php @@ -39,6 +39,7 @@ if( defined( 'PRETTY_UTF8' ) ) { } else { /** * @ignore + * @param string $string * @return string */ function pretty( $string ) { diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 2e0b944415..091bd78f99 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -28,14 +28,17 @@ * @author Michael Dale */ class UploadFromChunks extends UploadFromFile { - protected $mOffset, $mChunkIndex, $mFileKey, $mVirtualTempPath; + protected $mOffset; + protected $mChunkIndex; + protected $mFileKey; + protected $mVirtualTempPath; /** * Setup local pointers to stash, repo and user (similar to UploadFromStash) * - * @param $user User - * @param $stash UploadStash - * @param $repo FileRepo + * @param $user User|null Default: null + * @param $stash UploadStash|bool Default: false + * @param $repo FileRepo|bool Default: false */ public function __construct( $user = null, $stash = false, $repo = false ) { // user object. sometimes this won't exist, as when running from cron. @@ -108,13 +111,14 @@ class UploadFromChunks extends UploadFromFile { * @return FileRepoStatus */ public function concatenateChunks() { + $chunkIndex = $this->getChunkIndex(); wfDebug( __METHOD__ . " concatenate {$this->mChunkIndex} chunks:" . - $this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n" ); + $this->getOffset() . ' inx:' . $chunkIndex . "\n" ); // Concatenate all the chunks to mVirtualTempPath - $fileList = Array(); + $fileList = array(); // The first chunk is stored at the mVirtualTempPath path so we start on "chunk 1" - for ( $i = 0; $i <= $this->getChunkIndex(); $i++ ) { + for ( $i = 0; $i <= $chunkIndex; $i++ ) { $fileList[] = $this->getVirtualChunkLocation( $i ); } @@ -122,9 +126,12 @@ class UploadFromChunks extends UploadFromFile { $ext = FileBackend::extensionFromPath( $this->mVirtualTempPath ); // Get a 0-byte temp file to perform the concatenation at $tmpFile = TempFSFile::factory( 'chunkedupload_', $ext ); - $tmpPath = $tmpFile - ? $tmpFile->bind( $this )->getPath() // keep alive with $this - : false; // fail in concatenate() + $tmpPath = false; // fail in concatenate() + if( $tmpFile ) { + // keep alive with $this + $tmpPath = $tmpFile->bind( $this )->getPath(); + } + // Concatenate the chunks at the temp file $tStart = microtime( true ); $status = $this->repo->concatenate( $fileList, $tmpPath, FileRepo::DELETE_SOURCE ); @@ -134,8 +141,10 @@ class UploadFromChunks extends UploadFromFile { } wfDebugLog( 'fileconcatenate', "Combined $i chunks in $tAmount seconds.\n" ); - $this->mTempPath = $tmpPath; // file system path - $this->mFileSize = filesize( $this->mTempPath ); //Since this was set for the last chunk previously + // File system path + $this->mTempPath = $tmpPath; + // Since this was set for the last chunk previously + $this->mFileSize = filesize( $this->mTempPath ); $ret = $this->verifyUpload(); if ( $ret['status'] !== UploadBase::OK ) { wfDebugLog( 'fileconcatenate', "Verification failed for chunked upload" ); @@ -321,7 +330,8 @@ class UploadFromChunks extends UploadFromFile { $error = array( 'unknown', 'no error recorded' ); } } - throw new UploadChunkFileException( "error storing file in '$chunkPath': " . implode( '; ', $error ) ); + throw new UploadChunkFileException( "Error storing file in '$chunkPath': " . + implode( '; ', $error ) ); } return $storeStatus; } @@ -352,6 +362,11 @@ class UploadFromChunks extends UploadFromFile { } } -class UploadChunkZeroLengthFileException extends MWException {}; -class UploadChunkFileException extends MWException {}; -class UploadChunkVerificationException extends MWException {}; +class UploadChunkZeroLengthFileException extends MWException { +} + +class UploadChunkFileException extends MWException { +} + +class UploadChunkVerificationException extends MWException { +} diff --git a/includes/upload/UploadFromStash.php b/includes/upload/UploadFromStash.php index cb85fc63f0..a67fc57634 100644 --- a/includes/upload/UploadFromStash.php +++ b/includes/upload/UploadFromStash.php @@ -28,7 +28,10 @@ * @author Bryan Tong Minh */ class UploadFromStash extends UploadBase { - protected $mFileKey, $mVirtualTempPath, $mFileProps, $mSourceType; + protected $mFileKey; + protected $mVirtualTempPath; + protected $mFileProps; + protected $mSourceType; // an instance of UploadStash private $stash; @@ -37,9 +40,9 @@ class UploadFromStash extends UploadBase { private $repo; /** - * @param $user User - * @param $stash UploadStash - * @param $repo FileRepo + * @param User|bool $user Default: false + * @param UploadStash|bool $stash Default: false + * @param FileRepo|bool $repo Default: false */ public function __construct( $user = false, $stash = false, $repo = false ) { // user object. sometimes this won't exist, as when running from cron. @@ -65,7 +68,7 @@ class UploadFromStash extends UploadBase { } /** - * @param $key string + * @param string $key * @return bool */ public static function isValidKey( $key ) { @@ -74,9 +77,8 @@ class UploadFromStash extends UploadBase { } /** - * @param $request WebRequest - * - * @return Boolean + * @param WebRequest $request + * @return bool */ public static function isValidRequest( $request ) { // this passes wpSessionKey to getText() as a default when wpFileKey isn't set. @@ -86,8 +88,9 @@ class UploadFromStash extends UploadBase { } /** - * @param $key string - * @param $name string + * @param string $key + * @param string $name + * @param bool $initTempFile */ public function initialize( $key, $name = 'upload_file', $initTempFile = true ) { /** @@ -110,14 +113,17 @@ class UploadFromStash extends UploadBase { } /** - * @param $request WebRequest + * @param WebRequest $request */ public function initializeFromRequest( &$request ) { // sends wpSessionKey as a default when wpFileKey is missing $fileKey = $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ); // chooses one of wpDestFile, wpUploadFile, filename in that order. - $desiredDestName = $request->getText( 'wpDestFile', $request->getText( 'wpUploadFile', $request->getText( 'filename' ) ) ); + $desiredDestName = $request->getText( + 'wpDestFile', + $request->getText( 'wpUploadFile', $request->getText( 'filename' ) ) + ); $this->initialize( $fileKey, $desiredDestName ); } @@ -144,7 +150,7 @@ class UploadFromStash extends UploadBase { /** * Stash the file. * - * @param $user User + * @param User $user * @return UploadStashFile */ public function stashFile( User $user = null ) { @@ -156,7 +162,7 @@ class UploadFromStash extends UploadBase { /** * This should return the key instead of the UploadStashFile instance, for backward compatibility. - * @return String + * @return string */ public function stashSession() { return $this->stashFile()->getFileKey(); @@ -164,7 +170,7 @@ class UploadFromStash extends UploadBase { /** * Remove a temporarily kept file stashed by saveTempUploadedFile(). - * @return bool success + * @return bool Success */ public function unsaveUploadedFile() { return $this->stash->removeFile( $this->mFileKey ); @@ -172,10 +178,10 @@ class UploadFromStash extends UploadBase { /** * Perform the upload, then remove the database record afterward. - * @param $comment string - * @param $pageText string - * @param $watch bool - * @param $user User + * @param string $comment + * @param string $pageText + * @param bool $watch + * @param User $user * @return Status */ public function performUpload( $comment, $pageText, $watch, $user ) { -- 2.20.1