From fc50d150db37b3cccffcaf9839253453f18f7583 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Nov 2013 14:31:56 +0100 Subject: [PATCH] Fix CodeSniffer errors and warnings on some API classes Change-Id: Id5fd7180f3a1d62663f79b27ad5108062607596a --- includes/api/ApiQueryUsers.php | 3 +- includes/api/ApiQueryWatchlist.php | 50 +++++++++++++++----- includes/api/ApiQueryWatchlistRaw.php | 12 +++-- includes/api/ApiResult.php | 29 +++++++----- includes/api/ApiRollback.php | 25 +++++++--- includes/api/ApiSetNotificationTimestamp.php | 27 ++++++++--- includes/api/ApiUnblock.php | 6 ++- includes/api/ApiUndelete.php | 10 ++-- includes/api/ApiUpload.php | 16 +++++-- includes/api/ApiWatch.php | 13 +++-- 10 files changed, 135 insertions(+), 56 deletions(-) diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 78bf24e82d..f22140a0df 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -314,7 +314,8 @@ class ApiQueryUsers extends ApiQueryBase { ' rights - Lists all the rights the user(s) has', ' editcount - Adds the user\'s edit count', ' registration - Adds the user\'s registration timestamp', - ' emailable - Tags if the user can and wants to receive email through [[Special:Emailuser]]', + ' emailable - Tags if the user can and wants to receive ' . + 'email through [[Special:Emailuser]]', ' gender - Tags the gender of the user. Returns "male", "female", or "unknown"', ), 'users' => 'A list of users to obtain the same information for', diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 2f784f4d39..f9af75ae0d 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -44,9 +44,11 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->run( $resultPageSet ); } - private $fld_ids = false, $fld_title = false, $fld_patrol = false, $fld_flags = false, - $fld_timestamp = false, $fld_user = false, $fld_comment = false, $fld_parsedcomment = false, $fld_sizes = false, - $fld_notificationtimestamp = false, $fld_userid = false, $fld_loginfo = false; + private $fld_ids = false, $fld_title = false, $fld_patrol = false, + $fld_flags = false, $fld_timestamp = false, $fld_user = false, + $fld_comment = false, $fld_parsedcomment = false, $fld_sizes = false, + $fld_notificationtimestamp = false, $fld_userid = false, + $fld_loginfo = false; /** * @param $resultPageSet ApiPageSet @@ -103,7 +105,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->addFieldsIf( 'rc_patrolled', $this->fld_patrol ); $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes ); $this->addFieldsIf( 'wl_notificationtimestamp', $this->fld_notificationtimestamp ); - $this->addFieldsIf( array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ), $this->fld_loginfo ); + $this->addFieldsIf( + array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ), + $this->fld_loginfo + ); } elseif ( $params['allrev'] ) { $this->addFields( 'rc_this_oldid' ); } else { @@ -156,7 +161,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) { $user = $this->getUser(); if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) { - $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); + $this->dieUsage( + 'You need the patrol right to request the patrolled flag', + 'permissiondenied' + ); } } @@ -186,7 +194,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } // This is an index optimization for mysql, as done in the Special:Watchlist page - $this->addWhereIf( "rc_timestamp > ''", !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' ); + $this->addWhereIf( + "rc_timestamp > ''", + !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' + ); $this->addOption( 'LIMIT', $params['limit'] + 1 ); @@ -196,8 +207,12 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { foreach ( $res as $row ) { if ( ++$count > $params['limit'] ) { - // We've reached the one extra which shows that there are additional pages to be had. Stop here... - $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) ); + // We've reached the one extra which shows that there are + // additional pages to be had. Stop here... + $this->setContinueEnumParameter( + 'start', + wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) + ); break; } @@ -219,7 +234,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' ); + $this->getResult()->setIndexedTagName_internal( + array( 'query', $this->getModuleName() ), + 'item' + ); } elseif ( $params['allrev'] ) { $resultPageSet->populateFromRevisionIDs( $ids ); } else { @@ -485,7 +503,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { ' log - Log entries', ), 'owner' => 'The name of the user whose watchlist you\'d like to access', - 'token' => 'Give a security token (settable in preferences) to allow access to another user\'s watchlist' + 'token' => 'Give a security token (settable in preferences) to ' . + 'allow access to another user\'s watchlist' ); } @@ -578,11 +597,18 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ), - array( 'code' => 'bad_wltoken', 'info' => 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences' ), + array( + 'code' => 'bad_wltoken', + 'info' => 'Incorrect watchlist token provided -- ' . + 'please set a correct token in Special:Preferences' + ), array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ), array( 'code' => 'patrol', 'info' => 'patrol property is not available' ), array( 'show' ), - array( 'code' => 'permissiondenied', 'info' => 'You need the patrol right to request the patrolled flag' ), + array( + 'code' => 'permissiondenied', + 'info' => 'You need the patrol right to request the patrolled flag' + ), array( 'code' => 'user-excludeuser', 'info' => 'user and excludeuser cannot be used together' ), ) ); } diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index 4d977223c2..b53bea1abd 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -100,7 +100,8 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { $count = 0; foreach ( $res as $row ) { if ( ++$count > $params['limit'] ) { - // We've reached the one extra which shows that there are additional pages to be had. Stop here... + // We've reached the one extra which shows that there are + // additional pages to be had. Stop here... $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' . $row->wl_title ); break; } @@ -182,7 +183,8 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { ), 'show' => 'Only list items that meet these criteria', 'owner' => 'The name of the user whose watchlist you\'d like to access', - 'token' => 'Give a security token (settable in preferences) to allow access to another user\'s watchlist', + 'token' => 'Give a security token (settable in preferences) to allow ' . + 'access to another user\'s watchlist', 'dir' => 'Direction to sort the titles and namespaces in', ); } @@ -211,7 +213,11 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ), array( 'show' ), array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ), - array( 'code' => 'bad_wltoken', 'info' => 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences' ), + array( + 'code' => 'bad_wltoken', + 'info' => 'Incorrect watchlist token provided -- ' . + 'please set a correct token in Special:Preferences' + ), ) ); } diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 68137ff672..e92202025e 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -26,9 +26,9 @@ /** * This class represents the result of the API operations. - * It simply wraps a nested array() structure, adding some functions to simplify array's modifications. - * As various modules execute, they add different pieces of information to this result, - * structuring it as it will be given to the client. + * It simply wraps a nested array() structure, adding some functions to simplify + * array's modifications. As various modules execute, they add different pieces + * of information to this result, structuring it as it will be given to the client. * * Each subarray may either be a dictionary - key-value pairs with unique keys, * or lists, where the items are added using $data[] = $value notation. @@ -151,14 +151,17 @@ class ApiResult extends ApiBase { * @param array $arr to add $value to * @param string $name Index of $arr to add $value at * @param $value mixed - * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This parameter used to be - * boolean, and the value of OVERRIDE=1 was specifically chosen so that it would be backwards - * compatible with the new method signature. + * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. + * This parameter used to be boolean, and the value of OVERRIDE=1 was + * specifically chosen so that it would be backwards compatible with the + * new method signature. * * @since 1.21 int $flags replaced boolean $override */ public static function setElement( &$arr, $name, $value, $flags = 0 ) { - if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) { + if ( $arr === null || $name === null || $value === null + || !is_array( $arr ) || is_array( $name ) + ) { ApiBase::dieDebug( __METHOD__, 'Bad parameter' ); } @@ -177,7 +180,10 @@ class ApiResult extends ApiBase { ApiBase::dieDebug( __METHOD__, "Attempting to merge element $name" ); } } else { - ApiBase::dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" ); + ApiBase::dieDebug( + __METHOD__, + "Attempting to add element $name=$value, existing value is {$arr[$name]}" + ); } } @@ -272,9 +278,10 @@ class ApiResult extends ApiBase { * @param $path array|string|null * @param $name string * @param $value mixed - * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This parameter used to be - * boolean, and the value of OVERRIDE=1 was specifically chosen so that it would be backwards - * compatible with the new method signature. + * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This + * parameter used to be boolean, and the value of OVERRIDE=1 was specifically + * chosen so that it would be backwards compatible with the new method + * signature. * @return bool True if $value fits in the result, false if not * * @since 1.21 int $flags replaced boolean $override diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index b9873f49ce..2a372e4ea3 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -47,7 +47,14 @@ class ApiRollback extends ApiBase { $pageObj = WikiPage::factory( $titleObj ); $summary = $params['summary']; $details = array(); - $retval = $pageObj->doRollback( $this->getRbUser(), $summary, $params['token'], $params['markbot'], $details, $this->getUser() ); + $retval = $pageObj->doRollback( + $this->getRbUser(), + $summary, + $params['token'], + $params['markbot'], + $details, + $this->getUser() + ); if ( $retval ) { // We don't care about multiple errors, just report one of them @@ -107,11 +114,14 @@ class ApiRollback extends ApiBase { public function getParamDescription() { return array( 'title' => 'Title of the page you want to rollback.', - 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.', - 'token' => "A rollback token previously retrieved through {$this->getModulePrefix()}prop=revisions", + 'user' => 'Name of the user whose edits are to be rolled back. If ' . + 'set incorrectly, you\'ll get a badtoken error.', + 'token' => 'A rollback token previously retrieved through ' . + "{$this->getModulePrefix()}prop=revisions", 'summary' => 'Custom edit summary. If empty, default summary will be used', 'markbot' => 'Mark the reverted edits and the revert as bot edits', - 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' . + 'use preferences or do not change watch', ); } @@ -130,8 +140,8 @@ class ApiRollback extends ApiBase { public function getDescription() { return array( - 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,', - 'they will all be rolled back' + 'Undo the last edit to the page. If the last user who edited the page made', + 'multiple edits in a row, they will all be rolled back' ); } @@ -194,7 +204,8 @@ class ApiRollback extends ApiBase { public function getExamples() { return array( 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC', - 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1' + 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&' . + 'token=123ABC&summary=Reverting%20vandalism&markbot=1' ); } diff --git a/includes/api/ApiSetNotificationTimestamp.php b/includes/api/ApiSetNotificationTimestamp.php index 5302896532..dc593e5f91 100644 --- a/includes/api/ApiSetNotificationTimestamp.php +++ b/includes/api/ApiSetNotificationTimestamp.php @@ -48,7 +48,10 @@ class ApiSetNotificationTimestamp extends ApiBase { $pageSet = $this->getPageSet(); if ( $params['entirewatchlist'] && $pageSet->getDataSource() !== null ) { - $this->dieUsage( "Cannot use 'entirewatchlist' at the same time as '{$pageSet->getDataSource()}'", 'multisource' ); + $this->dieUsage( + "Cannot use 'entirewatchlist' at the same time as '{$pageSet->getDataSource()}'", + 'multisource' + ); } $dbw = wfGetDB( DB_MASTER, 'api' ); @@ -95,7 +98,9 @@ class ApiSetNotificationTimestamp extends ApiBase { __METHOD__ ); - $result['notificationtimestamp'] = ( is_null( $timestamp ) ? '' : wfTimestamp( TS_ISO_8601, $timestamp ) ); + $result['notificationtimestamp'] = is_null( $timestamp ) + ? '' + : wfTimestamp( TS_ISO_8601, $timestamp ); } else { // First, log the invalid titles foreach ( $pageSet->getInvalidTitles() as $title ) { @@ -128,7 +133,9 @@ class ApiSetNotificationTimestamp extends ApiBase { // Query the results of our update $timestamps = array(); - $res = $dbw->select( 'watchlist', array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ), + $res = $dbw->select( + 'watchlist', + array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ), array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ), __METHOD__ ); @@ -281,7 +288,8 @@ class ApiSetNotificationTimestamp extends ApiBase { $this->getRequireOnlyOneParameterErrorMessages( array_merge( array( 'entirewatchlist' ), array_keys( $ps->getFinalParams() ) ) ), array( - array( 'code' => 'notloggedin', 'info' => 'Anonymous users cannot use watchlist change notifications' ), + array( 'code' => 'notloggedin', 'info' + => 'Anonymous users cannot use watchlist change notifications' ), array( 'code' => 'multpages', 'info' => 'torevid may only be used with a single page' ), array( 'code' => 'multpages', 'info' => 'newerthanrevid may only be used with a single page' ), ) @@ -290,9 +298,14 @@ class ApiSetNotificationTimestamp extends ApiBase { public function getExamples() { return array( - 'api.php?action=setnotificationtimestamp&entirewatchlist=&token=123ABC' => 'Reset the notification status for the entire watchlist', - 'api.php?action=setnotificationtimestamp&titles=Main_page&token=123ABC' => 'Reset the notification status for "Main page"', - 'api.php?action=setnotificationtimestamp&titles=Main_page×tamp=2012-01-01T00:00:00Z&token=123ABC' => 'Set the notification timestamp for "Main page" so all edits since 1 January 2012 are unviewed', + 'api.php?action=setnotificationtimestamp&entirewatchlist=&token=123ABC' + => 'Reset the notification status for the entire watchlist', + 'api.php?action=setnotificationtimestamp&titles=Main_page&token=123ABC' + => 'Reset the notification status for "Main page"', + 'api.php?action=setnotificationtimestamp&titles=Main_page&' . + 'timestamp=2012-01-01T00:00:00Z&token=123ABC' + => 'Set the notification timestamp for "Main page" so all edits ' . + 'since 1 January 2012 are unviewed', ); } diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index 78137a8652..dabb8dac27 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -98,8 +98,10 @@ class ApiUnblock extends ApiBase { $p = $this->getModulePrefix(); return array( - 'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user", - 'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id", + 'id' => "ID of the block you want to unblock (obtained through list=blocks). ' . + 'Cannot be used together with {$p}user", + 'user' => "Username, IP address or IP range you want to unblock. ' . + 'Cannot be used together with {$p}id", 'token' => "An unblock token previously obtained through prop=info", 'reason' => 'Reason for unblock', ); diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 4bbe568d0b..93cefef097 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -122,8 +122,10 @@ class ApiUndelete extends ApiBase { 'title' => 'Title of the page you want to restore', 'token' => 'An undelete token previously retrieved through list=deletedrevs', 'reason' => 'Reason for restoring', - 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.', - 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', + 'timestamps' => 'Timestamps of the revisions to restore. If not set, all ' . + 'revisions will be restored.', + 'watchlist' => 'Unconditionally add or remove the page from your ' . + 'watchlist, use preferences or do not change watch', ); } @@ -140,8 +142,8 @@ class ApiUndelete extends ApiBase { public function getDescription() { return array( - 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be', - 'retrieved through list=deletedrevs' + 'Restore certain revisions of a deleted page. A list of deleted revisions ', + '(including timestamps) can be retrieved through list=deletedrevs' ); } diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 6d5861d585..01e0f6e04a 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -574,7 +574,9 @@ class ApiUpload extends ApiBase { if ( isset( $warnings['exists'] ) ) { $warning = $warnings['exists']; unset( $warnings['exists'] ); - $localFile = isset( $warning['normalizedFile'] ) ? $warning['normalizedFile'] : $warning['file']; + $localFile = isset( $warning['normalizedFile'] ) + ? $warning['normalizedFile'] + : $warning['file']; $warnings[$warning['warning']] = $localFile->getName(); } } @@ -751,16 +753,19 @@ class ApiUpload extends ApiBase { $params = array( 'filename' => 'Target filename', 'token' => 'Edit token. You can get one of these through prop=info', - 'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified', + 'comment' => 'Upload comment. Also used as the initial page text for new ' . + 'files if "text" is not specified', 'text' => 'Initial page text for new files', 'watch' => 'Watch the page', - 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', + 'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' . + 'use preferences or do not change watch', 'ignorewarnings' => 'Ignore any warnings', 'file' => 'File contents', 'url' => 'URL to fetch the file from', 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.', 'sessionkey' => 'Same as filekey, maintained for backward compatibility.', - 'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.', + 'stash' => 'If set, the server will not add the file to the repository ' . + 'and stash it temporarily.', 'chunk' => 'Chunk contents', 'offset' => 'Offset of chunk in bytes', @@ -858,7 +863,8 @@ class ApiUpload extends ApiBase { public function getExamples() { return array( - 'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png' + 'api.php?action=upload&filename=Wiki.png' . + '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png' => 'Upload from a URL', 'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1' => 'Complete an upload that failed due to warnings', diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index c7d636a1bc..7ad286fcf9 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -49,21 +49,26 @@ class ApiWatch extends ApiBase { $res = array( 'title' => $title->getPrefixedText() ); - // Currently unnecessary, code to act as a safeguard against any change in current behavior of uselang + // Currently unnecessary, code to act as a safeguard against any change + // in current behavior of uselang. // Copy from ApiParse $oldLang = null; - if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) { + if ( isset( $params['uselang'] ) && + $params['uselang'] != $this->getContext()->getLanguage()->getCode() + ) { $oldLang = $this->getContext()->getLanguage(); // Backup language $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); } if ( $params['unwatch'] ) { $res['unwatched'] = ''; - $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); + $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() ) + ->title( $title )->parseAsBlock(); $status = UnwatchAction::doUnwatch( $title, $user ); } else { $res['watched'] = ''; - $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); + $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() ) + ->title( $title )->parseAsBlock(); $status = WatchAction::doWatch( $title, $user ); } -- 2.20.1