From 0cef781886e257732d7cd4d3d7fff28138d12699 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 5 Feb 2014 11:20:17 +0100 Subject: [PATCH] Fix CodeSniffer errors and warnings Change-Id: Idc74e34634d88625773fb8f73315f61edfa67e28 --- includes/api/ApiMain.php | 6 ++++-- includes/api/ApiPageSet.php | 5 +++-- includes/api/ApiQueryAllCategories.php | 8 ++++++-- includes/api/ApiQueryAllLinks.php | 1 - includes/api/ApiQueryAllPages.php | 8 ++++++-- includes/api/ApiQueryDeletedrevs.php | 8 ++++++-- includes/api/ApiQueryImageInfo.php | 3 ++- includes/api/ApiQuerySiteinfo.php | 12 ++++++++++-- includes/api/ApiQueryUserContributions.php | 8 +++++++- includes/api/ApiRevisionDelete.php | 15 +++++++++++---- includes/api/ApiWatch.php | 21 +++++++++++++++++---- includes/db/DatabaseMssql.php | 4 +++- includes/db/DatabasePostgres.php | 8 +++++--- includes/filebackend/SwiftFileBackend.php | 3 ++- includes/htmlform/HTMLForm.php | 10 ++++++++-- includes/installer/MysqlUpdater.php | 6 +++--- includes/installer/PostgresUpdater.php | 3 ++- includes/installer/SqliteUpdater.php | 3 ++- 18 files changed, 97 insertions(+), 35 deletions(-) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 81b5e9f3f5..2684f51356 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -39,7 +39,6 @@ * @ingroup API */ class ApiMain extends ApiBase { - /** * When no format parameter is given, this format will be used */ @@ -1148,7 +1147,10 @@ class ApiMain extends ApiBase { array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ), array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ), array( 'code' => 'assertuserfailed', 'info' => 'Assertion that the user is logged in failed' ), - array( 'code' => 'assertbotfailed', 'info' => 'Assertion that the user has the bot right failed' ), + array( + 'code' => 'assertbotfailed', + 'info' => 'Assertion that the user has the bot right failed' + ), ) ); } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 36dd726178..4ecf029495 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -39,7 +39,6 @@ * @since 1.21 derives from ApiBase instead of ApiQueryBase */ class ApiPageSet extends ApiBase { - /** * Constructor flag: The new instance of ApiPageSet will ignore the 'generator=' parameter * @since 1.21 @@ -536,7 +535,9 @@ class ApiPageSet extends ApiBase { * @return array Array suitable for inclusion in the response * @since 1.23 */ - public function getInvalidTitlesAndRevisions( $invalidChecks = array( 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ) ) { + public function getInvalidTitlesAndRevisions( $invalidChecks = array( 'invalidTitles', + 'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ) + ) { $result = array(); if ( in_array( "invalidTitles", $invalidChecks ) ) { self::addValues( $result, $this->getInvalidTitles(), 'invalid', 'title' ); diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index 6bf8075508..44bf0cb9ca 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -67,8 +67,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); - $from = ( $params['from'] === null ? null : $this->titlePartToKey( $params['from'], NS_CATEGORY ) ); - $to = ( $params['to'] === null ? null : $this->titlePartToKey( $params['to'], NS_CATEGORY ) ); + $from = ( $params['from'] === null + ? null + : $this->titlePartToKey( $params['from'], NS_CATEGORY ) ); + $to = ( $params['to'] === null + ? null + : $this->titlePartToKey( $params['to'], NS_CATEGORY ) ); $this->addWhereRange( 'cat_title', $dir, $from, $to ); $min = $params['min']; diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 5be304d34c..13f766e2ab 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -154,7 +154,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $this->titlePartToKey( $params['to'], $params['namespace'] ) ); $this->addWhereRange( $pfx . $fieldTitle, 'newer', $from, $to ); - if ( isset( $params['prefix'] ) ) { $this->addWhere( $pfx . $fieldTitle . $db->buildLike( $this->titlePartToKey( $params['prefix'], $params['namespace'] ), $db->anyString() ) ); diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php index 430dd51716..501154a60e 100644 --- a/includes/api/ApiQueryAllPages.php +++ b/includes/api/ApiQueryAllPages.php @@ -87,8 +87,12 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase { $this->addWhereFld( 'page_namespace', $params['namespace'] ); $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); - $from = ( $params['from'] === null ? null : $this->titlePartToKey( $params['from'], $params['namespace'] ) ); - $to = ( $params['to'] === null ? null : $this->titlePartToKey( $params['to'], $params['namespace'] ) ); + $from = ( $params['from'] === null + ? null + : $this->titlePartToKey( $params['from'], $params['namespace'] ) ); + $to = ( $params['to'] === null + ? null + : $this->titlePartToKey( $params['to'], $params['namespace'] ) ); $this->addWhereRange( 'page_title', $dir, $from, $to ); if ( isset( $params['prefix'] ) ) { diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 7585ba760c..365fe3f2ad 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -176,8 +176,12 @@ class ApiQueryDeletedrevs extends ApiQueryBase { } elseif ( $mode == 'all' ) { $this->addWhereFld( 'ar_namespace', $params['namespace'] ); - $from = $params['from'] === null ? null : $this->titlePartToKey( $params['from'], $params['namespace'] ); - $to = $params['to'] === null ? null : $this->titlePartToKey( $params['to'], $params['namespace'] ); + $from = $params['from'] === null + ? null + : $this->titlePartToKey( $params['from'], $params['namespace'] ); + $to = $params['to'] === null + ? null + : $this->titlePartToKey( $params['to'], $params['namespace'] ); $this->addWhereRange( 'ar_title', $dir, $from, $to ); if ( isset( $params['prefix'] ) ) { diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index baee9b1da9..95c1420eeb 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -677,7 +677,8 @@ class ApiQueryImageInfo extends ApiQueryBase { ' (requires url and param ' . $modulePrefix . 'urlwidth)', 'mediatype' => ' mediatype - Adds the media type of the image', 'metadata' => ' metadata - Lists Exif metadata for the version of the image', - 'commonmetadata' => ' commonmetadata - Lists file format generic metadata for the version of the image', + 'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' . + 'for the version of the image', 'extmetadata' => ' extmetadata - Lists formatted metadata combined ' . 'from multiple sources. Results are HTML formatted.', 'archivename' => ' archivename - Adds the file name of the archive ' . diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 07561caad3..a9a5f5faa5 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -573,12 +573,20 @@ class ApiQuerySiteinfo extends ApiQueryBase { $ret['vcs-url'] = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : ''; } } + if ( SpecialVersion::getExtLicenseFileName( $extensionPath ) ) { $ret['license-name'] = isset( $ext['license-name'] ) ? $ext['license-name'] : ''; - $ret['license'] = SpecialPage::getTitleFor( 'Version', "License/{$ext['name']}" )->getLinkURL(); + $ret['license'] = SpecialPage::getTitleFor( + 'Version', + "License/{$ext['name']}" + )->getLinkURL(); } + if ( SpecialVersion::getExtAuthorsFileName( $extensionPath ) ) { - $ret['credits'] = SpecialPage::getTitleFor( 'Version', "Credits/{$ext['name']}" )->getLinkURL(); + $ret['credits'] = SpecialPage::getTitleFor( + 'Version', + "Credits/{$ext['name']}" + )->getLinkURL(); } } $data[] = $ret; diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 7896a2cc25..b492d9a326 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -360,7 +360,13 @@ class ApiQueryContributions extends ApiQueryBase { $vals['commenthidden'] = ''; $anyHidden = true; } - if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_COMMENT, $this->getUser() ) ) { + + $userCanView = Revision::userCanBitfield( + $row->rev_deleted, + Revision::DELETED_COMMENT, $this->getUser() + ); + + if ( $userCanView ) { if ( $this->fld_comment ) { $vals['comment'] = $row->rev_comment; } diff --git a/includes/api/ApiRevisionDelete.php b/includes/api/ApiRevisionDelete.php index 55d59f452b..9ba30d710d 100644 --- a/includes/api/ApiRevisionDelete.php +++ b/includes/api/ApiRevisionDelete.php @@ -97,14 +97,19 @@ class ApiRevisionDelete extends ApiBase { $data = $this->extractStatusInfo( $status ); $data['target'] = $targetObj->getFullText(); $data['items'] = array(); + foreach ( $status->itemStatuses as $id => $s ) { $data['items'][$id] = $this->extractStatusInfo( $s ); $data['items'][$id]['id'] = $id; } + $list->reloadFromMaster(); + // @codingStandardsIgnoreStart Avoid function calls in a FOR loop test part for ( $item = $list->reset(); $list->current(); $item = $list->next() ) { $data['items'][$item->getId()] += $item->getApiData( $this->getResult() ); } + // @codingStandardsIgnoreEnd + $data['items'] = array_values( $data['items'] ); $result->setIndexedTagName( $data['items'], 'i' ); $result->addValue( null, $this->getModuleName(), $data ); @@ -232,10 +237,12 @@ class ApiRevisionDelete extends ApiBase { public function getExamples() { return array( - 'api.php?action=revisiondelete&target=Main%20Page&type=revision&ids=12345&hide=content&token=123ABC' - => 'Hide content for revision 12345 on the Main Page', - 'api.php?action=revisiondelete&type=logging&ids=67890&hide=content|comment|user&reason=BLP%20violation&token=123ABC' - => 'Hide all data on log entry 67890 with the reason "BLP violation"', + 'api.php?action=revisiondelete&target=Main%20Page&type=revision&ids=12345&' . + 'hide=content&token=123ABC' + => 'Hide content for revision 12345 on the Main Page', + 'api.php?action=revisiondelete&type=logging&ids=67890&hide=content|comment|user&' . + 'reason=BLP%20violation&token=123ABC' + => 'Hide all data on log entry 67890 with the reason "BLP violation"', ); } diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 09f9356aa5..d0049ffac7 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -48,12 +48,20 @@ class ApiWatch extends ApiBase { // title is still supported for backward compatibility if ( !isset( $params['title'] ) ) { $pageSet->execute(); - $res = $pageSet->getInvalidTitlesAndRevisions( array( 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles' ) ); + $res = $pageSet->getInvalidTitlesAndRevisions( array( + 'invalidTitles', + 'special', + 'missingIds', + 'missingRevIds', + 'interwikiTitles' + ) ); + foreach ( $pageSet->getMissingTitles() as $title ) { $r = $this->watchTitle( $title, $user, $params ); $r['missing'] = 1; $res[] = $r; } + foreach ( $pageSet->getGoodTitles() as $title ) { $r = $this->watchTitle( $title, $user, $params ); $res[] = $r; @@ -64,9 +72,13 @@ class ApiWatch extends ApiBase { $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(), function ( $x ) { return $x !== null && $x !== false; } ) ); + if ( $extraParams ) { $p = $this->getModulePrefix(); - $this->dieUsage( "The parameter {$p}title can not be used with ". implode( ", ", $extraParams ), 'invalidparammix' ); + $this->dieUsage( + "The parameter {$p}title can not be used with " . implode( ", ", $extraParams ), + 'invalidparammix' + ); } $title = Title::newFromText( $params['title'] ); @@ -78,7 +90,9 @@ class ApiWatch extends ApiBase { $this->getResult()->addValue( null, $this->getModuleName(), $res ); } - private function watchTitle( Title $title, User $user, array $params, $compatibilityMode = false ) { + private function watchTitle( Title $title, User $user, array $params, + $compatibilityMode = false + ) { if ( !$title->isWatchable() ) { return array( 'title' => $title->getPrefixedText(), 'watchable' => 0 ); } @@ -116,7 +130,6 @@ class ApiWatch extends ApiBase { $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang } - if ( !$status->isOK() ) { if ( $compatibilityMode ) { $this->dieStatus( $status ); diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 9636da5536..88266834fb 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -984,7 +984,9 @@ class DatabaseMssql extends DatabaseBase { * @param array $join_conds * @return string */ - protected function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), $join_conds = array() ) { + protected function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), + $join_conds = array() + ) { $ret = array(); $retJOIN = array(); $use_index_safe = is_array( $use_index ) ? $use_index : array(); diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 6475c8fee4..c8830d34a7 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -827,7 +827,9 @@ __INDEXATTR__; * can be locked. That means tables in an outer join cannot be FOR UPDATE locked. Trying to do * so causes a DB error. This wrapper checks which tables can be locked and adjusts it accordingly. */ - function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() ) { + function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__, + $options = array(), $join_conds = array() + ) { if ( is_array( $options ) ) { $forUpdateKey = array_search( 'FOR UPDATE', $options ); if ( $forUpdateKey !== false && $join_conds ) { @@ -1063,7 +1065,7 @@ __INDEXATTR__; /** * Return the next in a sequence, save the value for retrieval via insertId() - * + * * @param string $seqName * @return int|null */ @@ -1564,7 +1566,7 @@ SQL; if ( isset( $options['FOR UPDATE'] ) ) { $postLimitTail .= ' FOR UPDATE OF ' . implode( ', ', $options['FOR UPDATE'] ); - } else if ( isset( $noKeyOptions['FOR UPDATE'] ) ) { + } elseif ( isset( $noKeyOptions['FOR UPDATE'] ) ) { $postLimitTail .= ' FOR UPDATE'; } diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index f3b96644b5..c3d2de8bd1 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -1218,7 +1218,8 @@ class SwiftFileBackend extends FileBackendStore { } // Run all requests for the first stage, then the next, and so on - for ( $stage = 0; $stage < count( $httpReqsByStage ); ++$stage ) { + $reqCount = count( $httpReqsByStage ); + for ( $stage = 0; $stage < $reqCount; ++$stage ) { $httpReqs = $this->http->runMulti( $httpReqsByStage[$stage] ); foreach ( $httpReqs as $index => $httpReq ) { // Run the callback for each request of this operation diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 1e8da45d80..f3b7ce7f4d 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -812,8 +812,14 @@ class HTMLForm extends ContextSource { if ( $this->isVForm() ) { // mw-ui-block is necessary because the buttons aren't necessarily in an // immediate child div of the vform. - // TODO Let client specify if the primary submit button is progressive or destructive - array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-big', 'mw-ui-constructive', 'mw-ui-block' ); + // @todo Let client specify if the primary submit button is progressive or destructive + array_push( + $attribs['class'], + 'mw-ui-button', + 'mw-ui-big', + 'mw-ui-constructive', + 'mw-ui-block' + ); } $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n"; diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 9dfbff86ae..33ff65e951 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -28,7 +28,6 @@ * @since 1.17 */ class MysqlUpdater extends DatabaseUpdater { - protected function getCoreUpdateList() { return array( array( 'disableContentHandlerUseDB' ), @@ -246,8 +245,9 @@ class MysqlUpdater extends DatabaseUpdater { // 1.23 array( 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ), - array( 'addIndex', 'logging', 'log_user_text_type_time', 'patch-logging_user_text_type_time_index.sql' ), - array( 'addIndex', 'logging', 'log_user_text_time', 'patch-logging_user_text_time_index.sql' ), + array( 'addIndex', 'logging', 'log_user_text_type_time', + 'patch-logging_user_text_type_time_index.sql' ), + array( 'addIndex', 'logging', 'log_user_text_time', 'patch-logging_user_text_time_index.sql' ), array( 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ), ); } diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index cd5a8add12..7841fca993 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -260,7 +260,8 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ), array( 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ), array( 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ), - array( 'addPgIndex', 'logging', 'logging_user_text_type_time', '(log_user_text, log_type, log_timestamp)' ), + array( 'addPgIndex', 'logging', 'logging_user_text_type_time', + '(log_user_text, log_type, log_timestamp)' ), array( 'addPgIndex', 'logging', 'logging_user_text_time', '(log_user_text, log_timestamp)' ), array( 'checkIndex', 'pagelink_unique', array( diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 3db3758cba..5d4f6de6db 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -123,7 +123,8 @@ class SqliteUpdater extends DatabaseUpdater { // 1.23 array( 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ), - array( 'addIndex', 'logging', 'log_user_text_type_time', 'patch-logging_user_text_type_time_index.sql' ), + array( 'addIndex', 'logging', 'log_user_text_type_time', + 'patch-logging_user_text_type_time_index.sql' ), array( 'addIndex', 'logging', 'log_user_text_time', 'patch-logging_user_text_time_index.sql' ), array( 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ), ); -- 2.20.1