From c37d6549fdffc9b53485a25d9f820385ecd91a52 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Sat, 3 Oct 2015 15:52:08 +0300 Subject: [PATCH] Fix Generic.Files.LineLength phpcs failure in 11 files under includes/ Bug: T102614 Change-Id: I0d759be6ef568c2c6f28606d3002484ad77a1830 --- includes/HttpFunctions.php | 23 ++++++++++++++++------- includes/MWTimestamp.php | 10 +++++++--- includes/PHPVersionCheck.php | 8 ++++---- includes/Revision.php | 3 ++- includes/api/ApiBlock.php | 2 ++ includes/api/ApiQueryAllMessages.php | 8 +++++++- includes/parser/Parser.php | 2 ++ includes/poolcounter/PoolCounterRedis.php | 3 +++ includes/specials/SpecialAllMessages.php | 6 +++++- includes/specials/SpecialMergeHistory.php | 7 ++++++- includes/upload/UploadBase.php | 3 +++ 11 files changed, 57 insertions(+), 18 deletions(-) diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 578b53580d..bbf3de6344 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -250,7 +250,9 @@ class MWHttpRequest { * @param string $caller The method making this request, for profiling * @param Profiler $profiler An instance of the profiler for profiling, or null */ - protected function __construct( $url, $options = array(), $caller = __METHOD__, $profiler = null ) { + protected function __construct( + $url, $options = array(), $caller = __METHOD__, $profiler = null + ) { global $wgHTTPTimeout, $wgHTTPConnectTimeout; $this->url = wfExpandUrl( $url, PROTO_HTTP ); @@ -870,8 +872,10 @@ class PhpHttpRequest extends MWHttpRequest { } /** - * Returns an array with a 'capath' or 'cafile' key that is suitable to be merged into the 'ssl' sub-array of a - * stream context options array. Uses the 'caInfo' option of the class if it is provided, otherwise uses the system + * Returns an array with a 'capath' or 'cafile' key + * that is suitable to be merged into the 'ssl' sub-array of + * a stream context options array. + * Uses the 'caInfo' option of the class if it is provided, otherwise uses the system * default CA bundle if PHP supports that, or searches a few standard locations. * @return array * @throws DomainException @@ -882,10 +886,13 @@ class PhpHttpRequest extends MWHttpRequest { if ( $this->caInfo ) { $certLocations = array( 'manual' => $this->caInfo ); } elseif ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) { + // @codingStandardsIgnoreStart Generic.Files.LineLength // Default locations, based on // https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/ - // PHP 5.5 and older doesn't have any defaults, so we try to guess ourselves. PHP 5.6+ gets the CA location - // from OpenSSL as long as it is not set manually, so we should leave capath/cafile empty there. + // PHP 5.5 and older doesn't have any defaults, so we try to guess ourselves. + // PHP 5.6+ gets the CA location from OpenSSL as long as it is not set manually, + // so we should leave capath/cafile empty there. + // @codingStandardsIgnoreEnd $certLocations = array_filter( array( getenv( 'SSL_CERT_DIR' ), getenv( 'SSL_CERT_PATH' ), @@ -914,8 +921,10 @@ class PhpHttpRequest extends MWHttpRequest { } /** - * Custom error handler for dealing with fopen() errors. fopen() tends to fire multiple errors in succession, and the last one - * is completely useless (something like "fopen: failed to open stream") so normal methods of handling errors programmatically + * Custom error handler for dealing with fopen() errors. + * fopen() tends to fire multiple errors in succession, and the last one + * is completely useless (something like "fopen: failed to open stream") + * so normal methods of handling errors programmatically * like get_last_error() don't work. */ public function errorHandler( $errno, $errstr ) { diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index 102be80182..639403d208 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -203,11 +203,15 @@ class MWTimestamp { * @deprecated since 1.26 Use Language::getHumanTimestamp directly * * @param MWTimestamp|null $relativeTo The base timestamp to compare to (defaults to now) - * @param User|null $user User the timestamp is being generated for (or null to use main context's user) - * @param Language|null $lang Language to use to make the human timestamp (or null to use main context's language) + * @param User|null $user User the timestamp is being generated for + * (or null to use main context's user) + * @param Language|null $lang Language to use to make the human timestamp + * (or null to use main context's language) * @return string Formatted timestamp */ - public function getHumanTimestamp( MWTimestamp $relativeTo = null, User $user = null, Language $lang = null ) { + public function getHumanTimestamp( + MWTimestamp $relativeTo = null, User $user = null, Language $lang = null + ) { if ( $lang === null ) { $lang = RequestContext::getMain()->getLanguage(); } diff --git a/includes/PHPVersionCheck.php b/includes/PHPVersionCheck.php index 4b2ff8c25a..f7e14a1f3f 100644 --- a/includes/PHPVersionCheck.php +++ b/includes/PHPVersionCheck.php @@ -189,10 +189,10 @@ function wfMissingVendorError( $type, $mwVersion ) { . "for help on installing the required components."; $longHtml = <<mediawiki.org - for help on installing the required components. + MediaWiki now also has some external dependencies that need to be installed via + composer or from a separate git repo. Please see + mediawiki.org + for help on installing the required components. HTML; wfGenericError( $type, $mwVersion, 'External dependencies', $shortText, $longText, $longHtml ); diff --git a/includes/Revision.php b/includes/Revision.php index 90d6265823..a7a87e8cbc 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1466,7 +1466,8 @@ class Revision implements IDBAccessObject { protected function checkContentModel() { global $wgContentHandlerUseDB; - $title = $this->getTitle(); // note: may return null for revisions that have not yet been inserted. + // Note: may return null for revisions that have not yet been inserted + $title = $this->getTitle(); $model = $this->getContentModel(); $format = $this->getContentFormat(); diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 6adfc1a02a..636baa7fef 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -162,12 +162,14 @@ class ApiBlock extends ApiBase { } protected function getExamplesMessages() { + // @codingStandardsIgnoreStart Generic.Files.LineLength return array( 'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC' => 'apihelp-block-example-ip-simple', 'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC' => 'apihelp-block-example-user-complex', ); + // @codingStandardsIgnoreEnd } public function getHelpUrls() { diff --git a/includes/api/ApiQueryAllMessages.php b/includes/api/ApiQueryAllMessages.php index 152711f835..d8a71caf41 100644 --- a/includes/api/ApiQueryAllMessages.php +++ b/includes/api/ApiQueryAllMessages.php @@ -116,7 +116,13 @@ class ApiQueryAllMessages extends ApiQueryBase { $lang = $langObj->getCode(); $customisedMessages = AllMessagesTablePager::getCustomisedStatuses( - array_map( array( $langObj, 'ucfirst' ), $messages_target ), $lang, $lang != $wgContLang->getCode() ); + array_map( + array( $langObj, 'ucfirst' ), + $messages_target + ), + $lang, + $lang != $wgContLang->getCode() + ); $customised = $params['customised'] === 'modified'; } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index bbee9d4e89..efad151b6c 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -91,8 +91,10 @@ class Parser { # at least one character of a host name (embeds EXT_LINK_URL_CLASS) const EXT_LINK_ADDR = '(?:[0-9.]+|\\[(?i:[0-9a-f:.]+)\\]|[^][<>"\\x00-\\x20\\x7F\p{Zs}])'; # RegExp to make image URLs (embeds IPv6 part of EXT_LINK_ADDR) + // @codingStandardsIgnoreStart Generic.Files.LineLength const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)((?:\\[(?i:[0-9a-f:.]+)\\])?[^][<>"\\x00-\\x20\\x7F\p{Zs}]+) \\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sxu'; + // @codingStandardsIgnoreEnd # Regular expression for a non-newline space const SPACE_NOT_NL = '(?:\t| |&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})'; diff --git a/includes/poolcounter/PoolCounterRedis.php b/includes/poolcounter/PoolCounterRedis.php index d7357cfe8e..6dd0b353f5 100644 --- a/includes/poolcounter/PoolCounterRedis.php +++ b/includes/poolcounter/PoolCounterRedis.php @@ -149,6 +149,7 @@ class PoolCounterRedis extends PoolCounter { } $conn = $status->value; + // @codingStandardsIgnoreStart Generic.Files.LineLength static $script = <<luaEval( $script, array( diff --git a/includes/specials/SpecialAllMessages.php b/includes/specials/SpecialAllMessages.php index 762658c523..ed1c903c5e 100644 --- a/includes/specials/SpecialAllMessages.php +++ b/includes/specials/SpecialAllMessages.php @@ -445,7 +445,11 @@ class AllMessagesTablePager extends TablePager { } elseif ( $field === 'am_title' ) { return array( 'class' => $field ); } else { - return array( 'lang' => wfBCP47( $this->langcode ), 'dir' => $this->lang->getDir(), 'class' => $field ); + return array( + 'lang' => wfBCP47( $this->langcode ), + 'dir' => $this->lang->getDir(), + 'class' => $field + ); } } diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 7b75480b96..ef1fd73c63 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -476,7 +476,12 @@ class SpecialMergeHistory extends SpecialPage { $logId = $logEntry->insert(); $logEntry->publish( $logId ); - $targetLink = Linker::link( $targetTitle, $targetTitle->getPrefixedText(), array(), array( 'redirect' => 'no' ) ); + $targetLink = Linker::link( + $targetTitle, + $targetTitle->getPrefixedText(), + array(), + array( 'redirect' => 'no' ) + ); $this->getOutput()->addWikiMsg( $this->msg( 'mergehistory-done' ) ->rawParams( $targetLink ) diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 508f62e6ce..5193a7f423 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1399,7 +1399,10 @@ abstract class UploadBase { # image/svg, text/xml, application/xml, and text/html, which can contain scripts if ( $stripped == 'href' && strncasecmp( 'data:', $value, 5 ) === 0 ) { // rfc2397 parameters. This is only slightly slower than (;[\w;]+)*. + // @codingStandardsIgnoreStart Generic.Files.LineLength $parameters = '(?>;[a-zA-Z0-9\!#$&\'*+.^_`{|}~-]+=(?>[a-zA-Z0-9\!#$&\'*+.^_`{|}~-]+|"(?>[\0-\x0c\x0e-\x21\x23-\x5b\x5d-\x7f]+|\\\\[\0-\x7f])*"))*(?:;base64)?'; + // @codingStandardsIgnoreEnd + if ( !preg_match( "!^data:\s*image/(gif|jpeg|jpg|png)$parameters,!i", $value ) ) { wfDebug( __METHOD__ . ": Found href to unwhitelisted data: uri " . "\"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" ); -- 2.20.1