Make phpcs-strict pass on includes/ (2/~10)
authorSiebrand Mazeland <siebrand@kitano.nl>
Sun, 11 May 2014 15:33:33 +0000 (17:33 +0200)
committerReedy <reedy@wikimedia.org>
Sun, 11 May 2014 19:22:05 +0000 (19:22 +0000)
Change-Id: I59fa9af7b16e0a5a4eb8a5cc764a605b18137316

includes/MessageBlobStore.php
includes/OutputHandler.php
includes/PHPVersionError.php
includes/Pager.php
includes/Preferences.php
includes/PrefixSearch.php
includes/Sanitizer.php
includes/Setup.php
includes/SiteConfiguration.php
includes/Skin.php

index f5b346c..5725898 100644 (file)
@@ -32,7 +32,6 @@
  * constituent messages or the resource itself is changed.
  */
 class MessageBlobStore {
-
        /**
         * Get the message blobs for a set of modules
         *
@@ -128,7 +127,8 @@ class MessageBlobStore {
         * @param string $name Module name
         * @param ResourceLoaderModule $module
         * @param string $lang Language code
-        * @return string Regenerated message blob, or null if there was no blob for the given module/language pair
+        * @return string Regenerated message blob, or null if there was no blob for
+        *   the given module/language pair.
         */
        public static function updateModule( $name, ResourceLoaderModule $module, $lang ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -331,6 +331,7 @@ class MessageBlobStore {
         */
        private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {
                global $wgCacheEpoch;
+
                $retval = array();
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'msg_resource',
@@ -345,10 +346,14 @@ class MessageBlobStore {
                                // This shouldn't be possible
                                throw new MWException( __METHOD__ . ' passed an invalid module name' );
                        }
+
                        // Update the module's blobs if the set of messages changed or if the blob is
                        // older than $wgCacheEpoch
-                       if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== array_values( array_unique( $module->getMessages() ) ) ||
-                                       wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch ) {
+                       $keys = array_keys( FormatJson::decode( $row->mr_blob, true ) );
+                       $values = array_values( array_unique( $module->getMessages() ) );
+                       if ( $keys !== $values
+                               || wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch
+                       ) {
                                $retval[$row->mr_resource] = self::updateModule( $row->mr_resource, $module, $lang );
                        } else {
                                $retval[$row->mr_resource] = $row->mr_blob;
index c783fd3..b3b3b88 100644 (file)
@@ -164,7 +164,10 @@ function wfMangleFlashPolicy( $s ) {
  * @param int $length
  */
 function wfDoContentLength( $length ) {
-       if ( !headers_sent() && isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) {
+       if ( !headers_sent()
+               && isset( $_SERVER['SERVER_PROTOCOL'] )
+               && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0'
+       ) {
                header( "Content-Length: $length" );
        }
 }
index 9b5373b..0fb3952 100644 (file)
@@ -43,10 +43,13 @@ function wfPHPVersionError( $type ) {
 
        $phpVersion = phpversion();
        $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
-       $message = "MediaWiki $mwVersion requires at least PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
+       $message = "MediaWiki $mwVersion requires at least "
+               . "PHP version $minimumVersionPHP, you are using PHP $phpVersion.";
+
        if ( $type == 'cli' ) {
-               $finalOutput = "You are using PHP version $phpVersion but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n" .
-               "Check if you have a newer php executable with a different name, such as php5.\n";
+               $finalOutput = "You are using PHP version $phpVersion "
+                       . "but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n"
+                       . "Check if you have a newer php executable with a different name, such as php5.\n";
        } elseif ( $type == 'index.php' ) {
                $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
                $encLogo = htmlspecialchars(
index 33bf067..5f05460 100644 (file)
@@ -365,7 +365,9 @@ abstract class IndexPager extends ContextSource implements Pager {
         * @return ResultWrapper
         */
        public function reallyDoQuery( $offset, $limit, $descending ) {
-               list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo( $offset, $limit, $descending );
+               list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
+                       $this->buildQueryInfo( $offset, $limit, $descending );
+
                return $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
        }
 
@@ -409,7 +411,8 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @param ResultWrapper $result
         */
-       protected function preprocessResults( $result ) {}
+       protected function preprocessResults( $result ) {
+       }
 
        /**
         * Get the formatted result list. Calls getStartBody(), formatRow() and
@@ -491,7 +494,8 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return void
         */
-       protected function doBatchLookups() {}
+       protected function doBatchLookups() {
+       }
 
        /**
         * Hook into getBody(), allows text to be inserted at the start. This
@@ -924,8 +928,9 @@ abstract class ReverseChronologicalPager extends IndexPager {
  * @ingroup Pager
  */
 abstract class TablePager extends IndexPager {
-       var $mSort;
-       var $mCurrentRow;
+       protected $mSort;
+
+       protected $mCurrentRow;
 
        public function __construct( IContextSource $context = null ) {
                if ( $context ) {
@@ -995,7 +1000,10 @@ abstract class TablePager extends IndexPager {
                }
 
                $tableClass = $this->getTableClass();
-               $ret = Html::openElement( 'table', array( 'style' => 'border:1px;', 'class' => "mw-datatable $tableClass" ) );
+               $ret = Html::openElement( 'table', array(
+                       'style' => 'border:1px;',
+                       'class' => "mw-datatable $tableClass" )
+               );
                $ret .= Html::rawElement( 'thead', array(), Html::rawElement( 'tr', array(), "\n" . $s . "\n" ) );
                $ret .= Html::openElement( 'tbody' ) . "\n";
 
index 493626a..13e94dd 100644 (file)
  * over to the tryUISubmit static method of this class.
  */
 class Preferences {
-       static $defaultPreferences = null;
-       static $saveFilters = array(
-                       'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
-                       'cols' => array( 'Preferences', 'filterIntval' ),
-                       'rows' => array( 'Preferences', 'filterIntval' ),
-                       'rclimit' => array( 'Preferences', 'filterIntval' ),
-                       'wllimit' => array( 'Preferences', 'filterIntval' ),
-                       'searchlimit' => array( 'Preferences', 'filterIntval' ),
+       /** @var array */
+       protected static $defaultPreferences = null;
+
+       /** @var array */
+       protected static $saveFilters = array(
+               'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
+               'cols' => array( 'Preferences', 'filterIntval' ),
+               'rows' => array( 'Preferences', 'filterIntval' ),
+               'rclimit' => array( 'Preferences', 'filterIntval' ),
+               'wllimit' => array( 'Preferences', 'filterIntval' ),
+               'searchlimit' => array( 'Preferences', 'filterIntval' ),
        );
 
        // Stuff that shouldn't be saved as a preference.
@@ -1401,7 +1404,10 @@ class Preferences {
 
                // Fortunately, the realname field is MUCH simpler
                // (not really "private", but still shouldn't be edited without permission)
-               if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) && array_key_exists( 'realname', $formData ) ) {
+               if ( !in_array( 'realname', $wgHiddenPrefs )
+                       && $user->isAllowed( 'editmyprivateinfo' )
+                       && array_key_exists( 'realname', $formData )
+               ) {
                        $realName = $formData['realname'];
                        $user->setRealName( $realName );
                }
index c5dd698..a796d35 100644 (file)
@@ -121,7 +121,7 @@ abstract class PrefixSearch {
         * @param array $titles
         * @return array
         */
-       protected abstract function titles( array $titles );
+       abstract protected function titles( array $titles );
 
        /**
         * When implemented in a descendant class, receives an array of titles as strings and returns
@@ -131,7 +131,7 @@ abstract class PrefixSearch {
         *
         * @return array
         */
-       protected abstract function strings( array $strings );
+       abstract protected function strings( array $strings );
 
        /**
         * Do a prefix search of titles and return a list of matching page names.
@@ -296,7 +296,9 @@ class TitlePrefixSearch extends PrefixSearch {
 class StringPrefixSearch extends PrefixSearch {
 
        protected function titles( array $titles ) {
-               return array_map( function( Title $t ) { return $t->getPrefixedText(); }, $titles );
+               return array_map( function ( Title $t ) {
+                       return $t->getPrefixedText();
+               }, $titles );
        }
 
        protected function strings( array $strings ) {
index 67cf70c..1ea6523 100644 (file)
@@ -459,7 +459,10 @@ class Sanitizer {
                                                $badtag = true;
                                        } elseif ( $slash ) {
                                                # Closing a tag... is it the one we just opened?
-                                               $ot = @array_pop( $tagstack );
+                                               wfSuppressWarnings();
+                                               $ot = array_pop( $tagstack );
+                                               wfRestoreWarnings();
+
                                                if ( $ot != $t ) {
                                                        if ( isset( $htmlsingleallowed[$ot] ) ) {
                                                                # Pop all elements with an optional close tag
@@ -489,7 +492,10 @@ class Sanitizer {
                                                                        }
                                                                }
                                                        } else {
-                                                               @array_push( $tagstack, $ot );
+                                                               wfSuppressWarnings();
+                                                               array_push( $tagstack, $ot );
+                                                               wfRestoreWarnings();
+
                                                                # <li> can be nested in <ul> or <ol>, skip those cases:
                                                                if ( !isset( $htmllist[$ot] ) || !isset( $listtags[$t] ) ) {
                                                                        $badtag = true;
@@ -567,9 +573,16 @@ class Sanitizer {
                } else {
                        # this might be possible using tidy itself
                        foreach ( $bits as $x ) {
-                               preg_match( '/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/',
-                               $x, $regs );
-                               @list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs;
+                               preg_match(
+                                       '/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/',
+                                       $x,
+                                       $regs
+                               );
+
+                               wfSuppressWarnings();
+                               list( /* $qbar */, $slash, $t, $params, $brace, $rest ) = $regs;
+                               wfRestoreWarnings();
+
                                $badtag = false;
                                if ( isset( $htmlelements[$t = strtolower( $t )] ) ) {
                                        if ( is_callable( $processCallback ) ) {
index 391bc13..a1bca22 100644 (file)
@@ -123,7 +123,8 @@ if ( isset( $wgFooterIcons['poweredby'] )
        && isset( $wgFooterIcons['poweredby']['mediawiki'] )
        && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
 ) {
-       $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
+       $wgFooterIcons['poweredby']['mediawiki']['src'] =
+               "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
 }
 
 /**
@@ -252,7 +253,10 @@ if ( $wgRCFilterByAge ) {
        // as determined by $wgRCMaxAge.
        // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
        sort( $wgRCLinkDays );
+
+       // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
        for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
+               // @codingStandardsIgnoreEnd
                if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
                        $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
                        break;
@@ -367,7 +371,9 @@ if ( $wgArticleCountMethod === null ) {
 }
 
 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
+       // @codingStandardsIgnoreStart Generic.PHP.NoSilencedErrors.Discouraged - No GlobalFunction here yet.
        $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
+       // @codingStandardsIgnoreEnd
 }
 
 if ( $wgNewUserLog ) {
@@ -429,7 +435,8 @@ if ( $wgCanonicalServer === false ) {
 // Set server name
 $serverParts = wfParseUrl( $wgCanonicalServer );
 if ( $wgServerName !== false ) {
-       wfWarn( '$wgServerName should be derived from $wgCanonicalServer, not customized. Overwriting $wgServerName.' );
+       wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
+               . 'not customized. Overwriting $wgServerName.' );
 }
 $wgServerName = $serverParts['host'];
 unset( $serverParts );
@@ -446,7 +453,8 @@ if ( $wgPasswordSender === false ) {
 
 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
        $wgSecureLogin = false;
-       wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' );
+       wfWarn( 'Secure login was enabled on a server that only supports '
+               . 'HTTP or HTTPS. Disabling secure login.' );
 }
 
 // Now that GlobalFunctions is loaded, set defaults that depend
index 2f28e7b..b99840f 100644 (file)
  * extract( $globals );
  * @endcode
  *
- * TODO: give examples for,
+ * @todo Give examples for,
  * suffixes:
  * $conf->suffixes = array( 'wiki' );
  * localVHosts
@@ -176,7 +176,9 @@ class SiteConfiguration {
         * @param array $wikiTags The tags assigned to the wiki.
         * @return mixed The value of the setting requested.
         */
-       public function get( $settingName, $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function get( $settingName, $wiki, $suffix = null, $params = array(),
+               $wikiTags = array()
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                return $this->getSetting( $settingName, $wiki, $params );
        }
@@ -228,7 +230,9 @@ class SiteConfiguration {
                                                        $retval = $thisSetting[$suffix];
                                                }
                                                break;
-                                       } elseif ( array_key_exists( "+$suffix", $thisSetting ) && is_array( $thisSetting["+$suffix"] ) ) {
+                                       } elseif ( array_key_exists( "+$suffix", $thisSetting )
+                                               && is_array( $thisSetting["+$suffix"] )
+                                       ) {
                                                if ( !isset( $retval ) ) {
                                                        $retval = array();
                                                }
@@ -338,7 +342,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractVar( $setting, $wiki, $suffix, &$var, $params = array(), $wikiTags = array() ) {
+       public function extractVar( $setting, $wiki, $suffix, &$var,
+               $params = array(), $wikiTags = array()
+       ) {
                $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
                if ( !is_null( $value ) ) {
                        $var = $value;
@@ -353,7 +359,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractGlobal( $setting, $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function extractGlobal( $setting, $wiki, $suffix = null,
+               $params = array(), $wikiTags = array()
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                $this->extractGlobalSetting( $setting, $wiki, $params );
        }
@@ -386,7 +394,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractAllGlobals( $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function extractAllGlobals( $wiki, $suffix = null, $params = array(),
+               $wikiTags = array()
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                foreach ( $this->settings as $varName => $setting ) {
                        $this->extractGlobalSetting( $varName, $wiki, $params );
@@ -574,12 +584,14 @@ class SiteConfiguration {
         */
        static function arrayMerge( $array1/* ... */ ) {
                $out = $array1;
-               for ( $i = 1; $i < func_num_args(); $i++ ) {
+               $argsCount = func_num_args();
+               for ( $i = 1; $i < $argsCount; $i++ ) {
                        foreach ( func_get_arg( $i ) as $key => $value ) {
                                if ( isset( $out[$key] ) && is_array( $out[$key] ) && is_array( $value ) ) {
                                        $out[$key] = self::arrayMerge( $out[$key], $value );
                                } elseif ( !isset( $out[$key] ) || !$out[$key] && !is_numeric( $key ) ) {
-                                       // Values that evaluate to true given precedence, for the primary purpose of merging permissions arrays.
+                                       // Values that evaluate to true given precedence, for the
+                                       // primary purpose of merging permissions arrays.
                                        $out[$key] = $value;
                                } elseif ( is_numeric( $key ) ) {
                                        $out[] = $value;
index cfa059e..9d1034b 100644 (file)
@@ -678,12 +678,15 @@ abstract class Skin extends ContextSource {
        function printSource() {
                $oldid = $this->getRevisionId();
                if ( $oldid ) {
-                       $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
+                       $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
+                       $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
                } else {
                        // oldid not available for non existing pages
                        $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
                }
-               return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url . '">' . $url . '</a>' )->text();
+
+               return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url
+                       . '">' . $url . '</a>' )->text();
        }
 
        /**
@@ -799,7 +802,9 @@ abstract class Skin extends ContextSource {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
 
                if ( $type == 'detect' ) {
-                       if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
+                       if ( !$this->isRevisionCurrent()
+                               && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
+                       ) {
                                $type = 'history';
                        } else {
                                $type = 'normal';
@@ -827,14 +832,21 @@ abstract class Skin extends ContextSource {
                // Allow for site and per-namespace customization of copyright notice.
                $forContent = true;
 
-               wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
+               wfRunHooks(
+                       'SkinCopyrightFooter',
+                       array( $this->getTitle(), $type, &$msg, &$link, &$forContent )
+               );
 
                $msgObj = $this->msg( $msg )->rawParams( $link );
                if ( $forContent ) {
                        $msg = $msgObj->inContentLanguage()->text();
                        if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
-                               $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
+                               $msg = Html::rawElement( 'span', array(
+                                       'lang' => $wgContLang->getHtmlCode(),
+                                       'dir' => $wgContLang->getDir()
+                               ), $msg );
                        }
+
                        return $msg;
                } else {
                        return $msgObj->text();
@@ -878,7 +890,8 @@ abstract class Skin extends ContextSource {
                global $wgStylePath;
 
                $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
-               $text = '<a href="//www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
+               $text = '<a href="//www.mediawiki.org/"><img src="' . $url
+                       . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
                wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
                return $text;
        }
@@ -934,8 +947,10 @@ abstract class Skin extends ContextSource {
 
        /**
         * Renders a $wgFooterIcons icon according to the method's arguments
-        * @param array $icon The icon to build the html for, see $wgFooterIcons for the format of this array
-        * @param bool|string $withImage Whether to use the icon's image or output a text-only footericon
+        * @param array $icon The icon to build the html for, see $wgFooterIcons
+        *   for the format of this array.
+        * @param bool|string $withImage Whether to use the icon's image or output
+        *   a text-only footericon.
         * @return string HTML
         */
        function makeFooterIcon( $icon, $withImage = 'withImage' ) {
@@ -945,7 +960,8 @@ abstract class Skin extends ContextSource {
                        $url = isset( $icon["url"] ) ? $icon["url"] : null;
                        unset( $icon["url"] );
                        if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
-                               $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
+                               // do this the lazy way, just pass icon data as an attribute array
+                               $html = Html::element( 'img', $icon );
                        } else {
                                $html = htmlspecialchars( $icon["alt"] );
                        }
@@ -1044,8 +1060,11 @@ abstract class Skin extends ContextSource {
                } else {
                        $targetUser = User::newFromId( $id );
                }
-               return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address
-                       $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
+
+               # The sending user must have a confirmed email address and the target
+               # user must have a confirmed email address and allow emails from users.
+               return $this->getUser()->canSendEmail() &&
+                       $targetUser->canReceiveEmail();
        }
 
        /**