From d026e1a403921e6714a553e4de3f7064013691bb Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sat, 16 Nov 2013 20:09:17 +0100 Subject: [PATCH] Address errors and warnings in CodeSniffer in api/ Change-Id: I06de371393d50eada33154626874b106d814642b --- includes/api/ApiBlock.php | 19 ++++-- includes/api/ApiComparePages.php | 13 +++- includes/api/ApiCreateAccount.php | 23 +++++-- includes/api/ApiDelete.php | 23 +++++-- includes/api/ApiEditPage.php | 100 ++++++++++++++++++++--------- includes/api/ApiEmailUser.php | 3 +- includes/api/ApiFeedWatchlist.php | 17 +++-- includes/api/ApiFileRevert.php | 13 +++- includes/api/ApiFormatBase.php | 33 +++++----- includes/api/ApiFormatJson.php | 6 +- includes/api/ApiFormatWddx.php | 3 +- includes/api/ApiFormatXml.php | 6 +- includes/api/ApiHelp.php | 19 ++++-- includes/api/ApiImport.php | 3 +- includes/api/ApiLogin.php | 35 +++++++--- includes/api/ApiMain.php | 74 ++++++++++++++------- includes/api/ApiMove.php | 12 +++- includes/api/ApiOptions.php | 15 +++-- includes/api/ApiQueryImageInfo.php | 3 +- 19 files changed, 294 insertions(+), 126 deletions(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 975153ac8f..332fa9ea4a 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -55,8 +55,11 @@ class ApiBlock extends ApiBase { } $target = User::newFromName( $params['user'] ); - // Bug 38633 - if the target is a user (not an IP address), but it doesn't exist or is unusable, error. - if ( $target instanceof User && ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $target->getName() ) ) ) { + // Bug 38633 - if the target is a user (not an IP address), but it + // doesn't exist or is unusable, error. + if ( $target instanceof User && + ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $target->getName() ) ) + ) { $this->dieUsageMsg( array( 'nosuchuser', $params['user'] ) ); } @@ -167,14 +170,18 @@ class ApiBlock extends ApiBase { return array( 'user' => 'Username, IP address or IP range you want to block', 'token' => 'A block token previously obtained through prop=info', - 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.', + 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. ' . + 'If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.', 'reason' => 'Reason for block', 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)', 'nocreate' => 'Prevent account creation', - 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from', - 'noemail' => 'Prevent user from sending email through the wiki. (Requires the "blockemail" right.)', + 'autoblock' => 'Automatically block the last used IP address, and ' . + 'any subsequent IP addresses they try to login from', + 'noemail' + => 'Prevent user from sending email through the wiki. (Requires the "blockemail" right.)', 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)', - 'allowusertalk' => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)', + 'allowusertalk' + => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)', 'reblock' => 'If the user is already blocked, overwrite the existing block', 'watchuser' => 'Watch the user/IP\'s user and talk pages', ); diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php index cbad164b03..1049b49c35 100644 --- a/includes/api/ApiComparePages.php +++ b/includes/api/ApiComparePages.php @@ -65,8 +65,11 @@ class ApiComparePages extends ApiBase { $difftext = $de->getDiffBody(); if ( $difftext === false ) { - $this->dieUsage( 'The diff cannot be retrieved. ' . - 'Maybe one or both revisions do not exist or you do not have permission to view them.', 'baddiff' ); + $this->dieUsage( + 'The diff cannot be retrieved. Maybe one or both revisions do ' . + 'not exist or you do not have permission to view them.', + 'baddiff' + ); } else { ApiResult::setContent( $vals, $difftext ); } @@ -164,7 +167,11 @@ class ApiComparePages extends ApiBase { array( 'code' => 'inputneeded', 'info' => 'A title or a revision is needed' ), array( 'invalidtitle', 'title' ), array( 'nosuchpageid', 'pageid' ), - array( 'code' => 'baddiff', 'info' => 'The diff cannot be retrieved. Maybe one or both revisions do not exist or you do not have permission to view them.' ), + array( + 'code' => 'baddiff', + 'info' => 'The diff cannot be retrieved. Maybe one or both ' . + 'revisions do not exist or you do not have permission to view them.' + ), ) ); } diff --git a/includes/api/ApiCreateAccount.php b/includes/api/ApiCreateAccount.php index f25f5aeb9c..439f46b9ad 100644 --- a/includes/api/ApiCreateAccount.php +++ b/includes/api/ApiCreateAccount.php @@ -39,7 +39,10 @@ class ApiCreateAccount extends ApiBase { // Use userCan in order to hit GlobalBlock checks (according to Special:userlogin) $loginTitle = SpecialPage::getTitleFor( 'Userlogin' ); if ( !$loginTitle->userCan( 'createaccount', $this->getUser() ) ) { - $this->dieUsage( 'You do not have the right to create a new account', 'permdenied-createaccount' ); + $this->dieUsage( + 'You do not have the right to create a new account', + 'permdenied-createaccount' + ); } if ( $this->getUser()->isBlockedFromCreateAccount() ) { $this->dieUsage( 'You cannot create a new account because you are blocked', 'blocked' ); @@ -96,7 +99,12 @@ class ApiCreateAccount extends ApiBase { if ( $params['mailpassword'] ) { // If mailpassword was set, disable the password and send an email. $user->setPassword( null ); - $status->merge( $loginForm->mailPasswordInternal( $user, false, 'createaccount-title', 'createaccount-text' ) ); + $status->merge( $loginForm->mailPasswordInternal( + $user, + false, + 'createaccount-title', + 'createaccount-text' + ) ); } elseif ( $wgEmailAuthentication && Sanitizer::validateEmail( $user->getEmail() ) ) { // Send out an email authentication message if needed $status->merge( $user->sendConfirmationMail() ); @@ -207,7 +215,8 @@ class ApiCreateAccount extends ApiBase { 'realname' => 'Real name of user (optional)', 'mailpassword' => 'If set to any value, a random password will be emailed to the user', 'reason' => 'Optional reason for creating the account to be put in the logs', - 'language' => 'Language code to set as default for the user (optional, defaults to content language)' + 'language' + => 'Language code to set as default for the user (optional, defaults to content language)' ); } @@ -256,7 +265,10 @@ class ApiCreateAccount extends ApiBase { $errors = parent::getPossibleErrors(); // All local errors are from LoginForm, which means they're actually message keys. foreach ( $localErrors as $error ) { - $errors[] = array( 'code' => $error, 'info' => wfMessage( $error )->inLanguage( 'en' )->useDatabase( false )->parse() ); + $errors[] = array( + 'code' => $error, + 'info' => wfMessage( $error )->inLanguage( 'en' )->useDatabase( false )->parse() + ); } $errors[] = array( @@ -280,7 +292,8 @@ class ApiCreateAccount extends ApiBase { global $wgMinimalPasswordLength; $errors[] = array( 'code' => 'passwordtooshort', - 'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength )->inLanguage( 'en' )->useDatabase( false )->parse() + 'info' => wfMessage( 'passwordtooshort', $wgMinimalPasswordLength ) + ->inLanguage( 'en' )->useDatabase( false )->parse() ); return $errors; diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 21264bcbb1..b9b07d149b 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -31,7 +31,6 @@ * @ingroup API */ class ApiDelete extends ApiBase { - /** * Extracts the title, token, and reason from the request parameters and invokes * the local delete() function with these as arguments. It does not make use of @@ -52,7 +51,14 @@ class ApiDelete extends ApiBase { $user = $this->getUser(); if ( $titleObj->getNamespace() == NS_FILE ) { - $status = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false ); + $status = self::deleteFile( + $pageObj, + $user, + $params['token'], + $params['oldimage'], + $reason, + false + ); } else { $status = self::delete( $pageObj, $user, $params['token'], $reason ); } @@ -135,7 +141,9 @@ class ApiDelete extends ApiBase { * @param $suppress bool * @return Status|array */ - public static function deleteFile( Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false ) { + public static function deleteFile( Page $page, User $user, $token, $oldimage, + &$reason = null, $suppress = false + ) { $title = $page->getTitle(); $errors = self::getPermissionsError( $title, $user, $token ); if ( count( $errors ) ) { @@ -211,9 +219,11 @@ class ApiDelete extends ApiBase { 'title' => "Title of the page you want to delete. Cannot be used together with {$p}pageid", 'pageid' => "Page ID of the page you want to delete. Cannot be used together with {$p}title", 'token' => 'A delete token previously retrieved through prop=info', - 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used', + 'reason' + => 'Reason for the deletion. If not set, an automatically generated reason will be used', 'watch' => 'Add the page to your watchlist', - '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', 'unwatch' => 'Remove the page from your watchlist', 'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename' ); @@ -258,7 +268,8 @@ class ApiDelete extends ApiBase { public function getExamples() { return array( 'api.php?action=delete&title=Main%20Page&token=123ABC' => 'Delete the Main Page', - 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' => 'Delete the Main Page with the reason "Preparing for move"', + 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' + => 'Delete the Main Page with the reason "Preparing for move"', ); } diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index fd024e10ae..daa5d1fa6b 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -32,7 +32,6 @@ * @ingroup API */ class ApiEditPage extends ApiBase { - public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); @@ -88,7 +87,8 @@ class ApiEditPage extends ApiBase { $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] ); } - // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such + // @todo Ask handler whether direct editing is supported at all! make + // allowFlatEdit() method or some such if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) { $params['contentformat'] = $contentHandler->getDefaultFormat(); @@ -156,7 +156,10 @@ class ApiEditPage extends ApiBase { if ( !is_null( $params['section'] ) ) { if ( !$contentHandler->supportsSections() ) { $modelName = $contentHandler->getModelID(); - $this->dieUsage( "Sections are not supported for this content model: $modelName.", 'sectionsnotsupported' ); + $this->dieUsage( + "Sections are not supported for this content model: $modelName.", + 'sectionsnotsupported' + ); } if ( $params['section'] == 'new' ) { @@ -204,13 +207,19 @@ class ApiEditPage extends ApiBase { } if ( $undoRev->getPage() != $pageObj->getID() ) { - $this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText() ) ); + $this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), + $titleObj->getPrefixedText() ) ); } if ( $undoafterRev->getPage() != $pageObj->getID() ) { - $this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) ); + $this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), + $titleObj->getPrefixedText() ) ); } - $newContent = $contentHandler->getUndoContent( $pageObj->getRevision(), $undoRev, $undoafterRev ); + $newContent = $contentHandler->getUndoContent( + $pageObj->getRevision(), + $undoRev, + $undoafterRev + ); if ( !$newContent ) { $this->dieUsageMsg( 'undo-failure' ); @@ -220,8 +229,11 @@ class ApiEditPage extends ApiBase { // If no summary was given and we only undid one rev, // use an autosummary - if ( is_null( $params['summary'] ) && $titleObj->getNextRevisionID( $undoafterRev->getID() ) == $params['undo'] ) { - $params['summary'] = wfMessage( 'undo-summary', $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text(); + if ( is_null( $params['summary'] ) && + $titleObj->getNextRevisionID( $undoafterRev->getID() ) == $params['undo'] + ) { + $params['summary'] = wfMessage( 'undo-summary' ) + ->params ( $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text(); } } @@ -333,8 +345,9 @@ class ApiEditPage extends ApiBase { // The following is needed to give the hook the full content of the // new revision rather than just the current section. (Bug 52077) - if ( !is_null( $params['section'] ) && $contentHandler->supportsSections() && $titleObj->exists() ) { - + if ( !is_null( $params['section'] ) && + $contentHandler->supportsSections() && $titleObj->exists() + ) { $sectionTitle = ''; // If sectiontitle is set, use it, otherwise use the summary as the section title (for // backwards compatibility with old forms/bots). @@ -346,7 +359,11 @@ class ApiEditPage extends ApiBase { $contentObj = $contentHandler->unserializeContent( $content, $contentFormat ); - $fullContentObj = $articleObject->replaceSectionContent( $params['section'], $contentObj, $sectionTitle ); + $fullContentObj = $articleObject->replaceSectionContent( + $params['section'], + $contentObj, + $sectionTitle + ); if ( $fullContentObj ) { $content = $fullContentObj->serialize( $contentFormat ); } else { @@ -511,14 +528,25 @@ class ApiEditPage extends ApiBase { array( 'emptynewsection' ), array( 'unknownerror', 'retval' ), array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ), - array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ), - array( 'code' => 'sectionsnotsupported', 'info' => 'Sections are not supported for this type of page.' ), - array( 'code' => 'editnotsupported', 'info' => 'Editing of this type of page is not supported using ' - . 'the text based edit API.' ), - array( 'code' => 'appendnotsupported', 'info' => 'This type of page can not be edited by appending ' - . 'or prepending text.' ), - array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to ' - . 'the page\'s content model' ), + array( + 'code' => 'invalidsection', + 'info' => 'The section parameter must be set to an integer or \'new\'' + ), + array( + 'code' => 'sectionsnotsupported', + 'info' => 'Sections are not supported for this type of page.' + ), + array( + 'code' => 'editnotsupported', + 'info' => 'Editing of this type of page is not supported using the text based edit API.' + ), + array( + 'code' => 'appendnotsupported', + 'info' => 'This type of page can not be edited by appending or prepending text.' ), + array( + 'code' => 'badformat', + 'info' => 'The requested serialization format can not be applied to the page\'s content model' + ), array( 'customcssprotected' ), array( 'customjsprotected' ), ) @@ -599,17 +627,22 @@ class ApiEditPage extends ApiBase { 'section' => 'Section number. 0 for the top section, \'new\' for a new section', 'sectiontitle' => 'The title for a new section', 'text' => 'Page content', - 'token' => array( 'Edit token. You can get one of these through prop=info.', - "The token should always be sent as the last parameter, or at least, after the {$p}text parameter" + 'token' => array( + 'Edit token. You can get one of these through prop=info.', + "The token should always be sent as the last parameter, or at " . + "least, after the {$p}text parameter" ), - 'summary' => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set", + 'summary' + => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set", 'minor' => 'Minor edit', 'notminor' => 'Non-minor edit', 'bot' => 'Mark this edit as bot', - 'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).', + 'basetimestamp' => array( + 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).', 'Used to detect edit conflicts; leave unset to ignore conflicts' ), - 'starttimestamp' => array( 'Timestamp when you obtained the edit token.', + 'starttimestamp' => array( + 'Timestamp when you obtained the edit token.', 'Used to detect edit conflicts; leave unset to ignore conflicts' ), 'recreate' => 'Override any errors about the article having been deleted in the meantime', @@ -617,9 +650,13 @@ class ApiEditPage extends ApiBase { 'nocreate' => 'Throw an error if the page doesn\'t exist', 'watch' => 'Add the page to your watchlist', 'unwatch' => 'Remove the page from your watchlist', - 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', - 'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.", - 'If set, the edit won\'t be done unless the hash is correct' ), + 'watchlist' => 'Unconditionally add or remove the page from your ' . + 'watchlist, use preferences or do not change watch', + 'md5' => array( + "The MD5 hash of the {$p}text parameter, or the {$p}prependtext " . + "and {$p}appendtext parameters concatenated.", + 'If set, the edit won\'t be done unless the hash is correct' + ), 'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text", 'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.", "Use {$p}section=new to append a new section" ), @@ -676,11 +713,14 @@ class ApiEditPage extends ApiBase { public function getExamples() { return array( - 'api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\' + 'api.php?action=edit&title=Test&summary=test%20summary&' . + 'text=article%20content&basetimestamp=20070824123454&token=%2B\\' => 'Edit a page (anonymous user)', - 'api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\' + 'api.php?action=edit&title=Test&summary=NOTOC&minor=&' . + 'prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\' => 'Prepend __NOTOC__ to a page (anonymous user)', - 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\' + 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&' . + 'basetimestamp=20070824123454&token=%2B\\' => 'Undo r13579 through r13585 with autosummary (anonymous user)', ); } diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index cd0d0cba53..29f7e056e9 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -149,7 +149,8 @@ class ApiEmailUser extends ApiBase { public function getExamples() { return array( - 'api.php?action=emailuser&target=WikiSysop&text=Content' => 'Send an email to the User "WikiSysop" with the text "Content"', + 'api.php?action=emailuser&target=WikiSysop&text=Content' + => 'Send an email to the User "WikiSysop" with the text "Content"', ); } diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index 645e7c7178..84c1fae875 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -132,15 +132,21 @@ class ApiFeedWatchlist extends ApiBase { $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']'; $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); - $feed = new $wgFeedClasses[$params['feedformat']] ( $feedTitle, htmlspecialchars( $msg ), $feedUrl ); + $feed = new $wgFeedClasses[$params['feedformat']] ( + $feedTitle, + htmlspecialchars( $msg ), + $feedUrl + ); ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems ); } catch ( Exception $e ) { - // Error results should not be cached $this->getMain()->setCacheMaxAge( 0 ); - $feedTitle = $wgSitename . ' - Error - ' . wfMessage( 'watchlist' )->inContentLanguage()->text() . ' [' . $wgLanguageCode . ']'; + // @todo FIXME: Localise brackets + $feedTitle = $wgSitename . ' - Error - ' . + wfMessage( 'watchlist' )->inContentLanguage()->text() . + ' [' . $wgLanguageCode . ']'; $feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL(); $feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss'; @@ -178,8 +184,11 @@ class ApiFeedWatchlist extends ApiBase { // The anchor won't work for sections that have dupes on page // as there's no way to strip that info from ApiWatchlist (apparently?). // RegExp in the line below is equal to Linker::formatAutocomments(). - if ( $this->linkToSections && $comment !== null && preg_match( '!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment, $matches ) ) { + if ( $this->linkToSections && $comment !== null && + preg_match( '!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment, $matches ) + ) { global $wgParser; + $sectionTitle = $wgParser->stripSectionName( $matches[2] ); $sectionTitle = Sanitizer::normalizeSectionNameWhitespace( $sectionTitle ); $titleUrl .= Title::newFromText( '#' . $sectionTitle )->getFragmentForURL(); diff --git a/includes/api/ApiFileRevert.php b/includes/api/ApiFileRevert.php index 2a7f46d2c3..dc5e24e717 100644 --- a/includes/api/ApiFileRevert.php +++ b/includes/api/ApiFileRevert.php @@ -46,7 +46,15 @@ class ApiFileRevert extends ApiBase { $this->checkPermissions( $this->getUser() ); $sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName ); - $status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'], 0, false, false, $this->getUser() ); + $status = $this->file->upload( + $sourceUrl, + $this->params['comment'], + $this->params['comment'], + 0, + false, + false, + $this->getUser() + ); if ( $status->isGood() ) { $result = array( 'result' => 'Success' ); @@ -185,7 +193,8 @@ class ApiFileRevert extends ApiBase { public function getExamples() { return array( - 'api.php?action=filerevert&filename=Wiki.png&comment=Revert&archivename=20110305152740!Wiki.png&token=123ABC' + 'api.php?action=filerevert&filename=Wiki.png&comment=Revert&' . + 'archivename=20110305152740!Wiki.png&token=123ABC' => 'Revert Wiki.png to the version of 20110305152740', ); } diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index c1817fa816..63a55024b3 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -30,7 +30,6 @@ * @ingroup API */ abstract class ApiFormatBase extends ApiBase { - private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared; private $mBufferResult = false, $mBuffer, $mDisabled = false; @@ -156,17 +155,20 @@ abstract class ApiFormatBase extends ApiBase { -mUnescapeAmps ) { +mUnescapeAmps ) { ?> MediaWiki API - MediaWiki API Result - +
@@ -179,15 +181,14 @@ See the complete documentation,
  for help screens
-			          // because these are actually formatted to rely on
-			          // the monospaced font for layout purposes
+// @codingStandardsIgnoreEnd
+			// don't wrap the contents of the 
 for help screens
+			// because these are actually formatted to rely on
+			// the monospaced font for layout purposes
+			} else {
 ?>
 
 complete documentation,
 
 
 complete documentation,
 		// identify URLs
 		$protos = wfUrlProtocolsWithoutProtRel();
 		// This regex hacks around bug 13218 (" included in the URL)
-		$text = preg_replace( "#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '\\1\\3\\4', $text );
+		$text = preg_replace(
+			"#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#",
+			'\\1\\3\\4',
+			$text
+		);
 
 		/**
 		 * Temporary fix for bad links in help messages. As a special case,
diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php
index 7a8817654e..15dc73b02c 100644
--- a/includes/api/ApiFormatJson.php
+++ b/includes/api/ApiFormatJson.php
@@ -81,8 +81,10 @@ class ApiFormatJson extends ApiFormatBase {
 
 	public function getParamDescription() {
 		return array(
-			'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
-			'utf8' => 'If specified, encodes most (but not all) non-ASCII characters as UTF-8 instead of replacing them with hexadecimal escape sequences.',
+			'callback' => 'If specified, wraps the output into a given function ' .
+				'call. For safety, all user-specific data will be restricted.',
+			'utf8' => 'If specified, encodes most (but not all) non-ASCII ' .
+				'characters as UTF-8 instead of replacing them with hexadecimal escape sequences.',
 		);
 	}
 
diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php
index eb83198fc6..df8e745be0 100644
--- a/includes/api/ApiFormatWddx.php
+++ b/includes/api/ApiFormatWddx.php
@@ -38,7 +38,8 @@ class ApiFormatWddx extends ApiFormatBase {
 		// Some versions of PHP have a broken wddx_serialize_value, see
 		// PHP bug 45314. Test encoding an affected character (U+00A0)
 		// to avoid this.
-		$expected = "
\xc2\xa0"; + $expected = + "
\xc2\xa0"; if ( function_exists( 'wddx_serialize_value' ) && !$this->getIsHtml() && wddx_serialize_value( "\xc2\xa0" ) == $expected diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 0917ac7fad..e707eb4e28 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -160,7 +160,8 @@ class ApiFormatXml extends ApiFormatBase { } if ( is_null( $subElemIndName ) && count( $indElements ) ) { - ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." ); + ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys " . + "without _element value. Use ApiResult::setIndexedTagName()." ); } if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) { @@ -214,7 +215,8 @@ class ApiFormatXml extends ApiFormatBase { return; } - $this->printText( 'getLocalURL( 'action=raw' ) ) . '" type="text/xsl" ?>' ); + $this->printText( 'getLocalURL( 'action=raw' ) ) . '" type="text/xsl" ?>' ); } public function getAllowedParams() { diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index 1aa300a8ba..5b1f29cbc7 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -30,7 +30,6 @@ * @ingroup API */ class ApiHelp extends ApiBase { - /** * Module for displaying help */ @@ -68,14 +67,17 @@ class ApiHelp extends ApiBase { // In case the '+' was typed into URL, it resolves as a space $subNames = explode( ' ', $m ); } + $module = $this->getMain(); - for ( $i = 0; $i < count( $subNames ); $i++ ) { + $subNamesCount = count( $subNames ); + for ( $i = 0; $i < $subNamesCount; $i++ ) { $subs = $module->getModuleManager(); if ( $subs === null ) { $module = null; } else { $module = $subs->getModule( $subNames[$i] ); } + if ( $module === null ) { if ( count( $subNames ) === 2 && $i === 1 @@ -94,6 +96,7 @@ class ApiHelp extends ApiBase { $type = $subs->getModuleGroup( $subNames[$i] ); } } + if ( $module !== null ) { $r[] = $this->buildModuleHelp( $module, $type ); } @@ -141,8 +144,10 @@ class ApiHelp extends ApiBase { public function getParamDescription() { return array( - 'modules' => 'List of module names (value of the action= parameter). Can specify submodules with a \'+\'', - 'querymodules' => 'Use modules=query+value instead. List of query module names (value of prop=, meta= or list= parameter)', + 'modules' => 'List of module names (value of the action= parameter). ' . + 'Can specify submodules with a \'+\'', + 'querymodules' => 'Use modules=query+value instead. List of query ' . + 'module names (value of prop=, meta= or list= parameter)', ); } @@ -154,8 +159,10 @@ class ApiHelp extends ApiBase { return array( 'api.php?action=help' => 'Whole help page', 'api.php?action=help&modules=protect' => 'Module (action) help page', - 'api.php?action=help&modules=query+categorymembers' => 'Help for the query/categorymembers module', - 'api.php?action=help&modules=login|query+info' => 'Help for the login and query/info modules', + 'api.php?action=help&modules=query+categorymembers' + => 'Help for the query/categorymembers module', + 'api.php?action=help&modules=login|query+info' + => 'Help for the login and query/info modules', ); } diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 92539646f1..295f16ec53 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -177,7 +177,8 @@ class ApiImport extends ApiBase { public function getExamples() { return array( - 'api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&namespace=100&fullhistory=&token=123ABC' + 'api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' . + 'namespace=100&fullhistory=&token=123ABC' => 'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history', ); } diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 18fd0c7570..fe3143ea89 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -132,7 +132,9 @@ class ApiLogin extends ApiBase { $result['result'] = 'NotExists'; break; - case LoginForm::RESET_PASS: // bug 20223 - Treat a temporary password as wrong. Per SpecialUserLogin - "The e-mailed temporary password should not be used for actual logins;" + // bug 20223 - Treat a temporary password as wrong. Per SpecialUserLogin: + // The e-mailed temporary password should not be used for actual logins. + case LoginForm::RESET_PASS: case LoginForm::WRONG_PASS: $result['result'] = 'WrongPass'; break; @@ -256,24 +258,39 @@ class ApiLogin extends ApiBase { public function getDescription() { return array( 'Log in and get the authentication tokens.', - 'In the event of a successful log-in, a cookie will be attached', - 'to your session. In the event of a failed log-in, you will not', - 'be able to attempt another log-in through this method for 5 seconds.', - 'This is to prevent password guessing by automated password crackers' + 'In the event of a successful log-in, a cookie will be attached to your session.', + 'In the event of a failed log-in, you will not be able to attempt another log-in', + 'through this method for 5 seconds. This is to prevent password guessing by', + 'automated password crackers' ); } public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( - array( 'code' => 'NeedToken', 'info' => 'You need to resubmit your login with the specified token. See https://bugzilla.wikimedia.org/show_bug.cgi?id=23076' ), + array( + 'code' => 'NeedToken', 'info' => 'You need to resubmit your ' . + 'login with the specified token. See ' . + 'https://bugzilla.wikimedia.org/show_bug.cgi?id=23076' + ), array( 'code' => 'WrongToken', 'info' => 'You specified an invalid token' ), array( 'code' => 'NoName', 'info' => 'You didn\'t set the lgname parameter' ), array( 'code' => 'Illegal', 'info' => 'You provided an illegal username' ), array( 'code' => 'NotExists', 'info' => 'The username you provided doesn\'t exist' ), - array( 'code' => 'EmptyPass', 'info' => 'You didn\'t set the lgpassword parameter or you left it empty' ), + array( + 'code' => 'EmptyPass', + 'info' => 'You didn\'t set the lgpassword parameter or you left it empty' + ), array( 'code' => 'WrongPass', 'info' => 'The password you provided is incorrect' ), - array( 'code' => 'WrongPluginPass', 'info' => 'Same as "WrongPass", returned when an authentication plugin rather than MediaWiki itself rejected the password' ), - array( 'code' => 'CreateBlocked', 'info' => 'The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation' ), + array( + 'code' => 'WrongPluginPass', + 'info' => 'Same as "WrongPass", returned when an authentication ' . + 'plugin rather than MediaWiki itself rejected the password' + ), + array( + 'code' => 'CreateBlocked', + 'info' => 'The wiki tried to automatically create a new account ' . + 'for you, but your IP address has been blocked from account creation' + ), array( 'code' => 'Throttled', 'info' => 'You\'ve logged in too many times in a short time' ), array( 'code' => 'Blocked', 'info' => 'User is blocked' ), ) ); diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index c301e9eb72..a6a6e08b49 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -110,6 +110,7 @@ class ApiMain extends ApiBase { 'none' => 'ApiFormatNone', ); + // @codingStandardsIgnoreStart String contenation on "msg" not allowed to break long line /** * List of user roles that are specifically relevant to the API. * array( 'right' => array ( 'msg' => 'Some message with a $1', @@ -126,6 +127,7 @@ class ApiMain extends ApiBase { 'params' => array( ApiBase::LIMIT_SML2, ApiBase::LIMIT_BIG2 ) ) ); + // @codingStandardsIgnoreEnd /** * @var ApiFormatBase @@ -144,7 +146,8 @@ class ApiMain extends ApiBase { /** * Constructs an instance of ApiMain that utilizes the module and format specified by $request. * - * @param $context IContextSource|WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs + * @param $context IContextSource|WebRequest - if this is an instance of + * FauxRequest, errors are thrown and no printing occurs * @param bool $enableWrite should be set to true if the api may modify data */ public function __construct( $context = null, $enableWrite = false ) { @@ -459,6 +462,7 @@ class ApiMain extends ApiBase { } else { $origins = explode( ' ', $originHeader ); } + if ( !in_array( $originParam, $origins ) ) { // origin parameter set but incorrect // Send a 403 response @@ -469,7 +473,14 @@ class ApiMain extends ApiBase { return false; } - if ( self::matchOrigin( $originParam, $wgCrossSiteAJAXdomains, $wgCrossSiteAJAXdomainExceptions ) ) { + + $matchOrigin = self::matchOrigin( + $originParam, + $wgCrossSiteAJAXdomains, + $wgCrossSiteAJAXdomainExceptions + ); + + if ( $matchOrigin ) { $response->header( "Access-Control-Allow-Origin: $originParam" ); $response->header( 'Access-Control-Allow-Credentials: true' ); $this->getOutput()->addVaryHeader( 'Origin' ); @@ -483,7 +494,8 @@ class ApiMain extends ApiBase { * @param string $value Origin header * @param array $rules Set of wildcard rules * @param array $exceptions Set of wildcard rules - * @return bool True if $value matches a rule in $rules and doesn't match any rules in $exceptions, false otherwise + * @return bool True if $value matches a rule in $rules and doesn't match + * any rules in $exceptions, false otherwise */ protected static function matchOrigin( $value, $rules, $exceptions ) { foreach ( $rules as $rule ) { @@ -650,7 +662,10 @@ class ApiMain extends ApiBase { 'code' => 'internal_api_error_' . get_class( $e ), 'info' => $info, ); - ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' ); + ApiResult::setContent( + $errMessage, + $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' + ); } // Remember all the warnings to re-add them later @@ -727,7 +742,9 @@ class ApiMain extends ApiBase { if ( !isset( $moduleParams['token'] ) ) { $this->dieUsageMsg( array( 'missingparam', 'token' ) ); } else { - if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getContext()->getRequest() ) ) { + if ( !$this->getUser() + ->matchEditToken( $moduleParams['token'], $salt, $this->getContext()->getRequest() ) + ) { $this->dieUsageMsg( 'sessionfailure' ); } } @@ -892,7 +909,8 @@ class ApiMain extends ApiBase { static $table; if ( !$table ) { $chars = ';@$!*(),/:'; - for ( $i = 0; $i < strlen( $chars ); $i++ ) { + $numChars = strlen( $chars ); + for ( $i = 0; $i < $numChars; $i++ ) { $table[rawurlencode( $chars[$i] )] = $chars[$i]; } } @@ -1053,13 +1071,17 @@ class ApiMain extends ApiBase { 'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached', 'maxage' => 'Set the max-age header to this many seconds. Errors are never cached', 'requestid' => 'Request ID to distinguish requests. This will just be output back to you', - 'servedby' => 'Include the hostname that served the request in the results. Unconditionally shown on error', + 'servedby' => 'Include the hostname that served the request in the ' . + 'results. Unconditionally shown on error', 'origin' => array( - 'When accessing the API using a cross-domain AJAX request (CORS), set this to the originating domain.', - 'This must be included in any pre-flight request, and therefore must be part of the request URI (not the POST body).', - 'This must match one of the origins in the Origin: header exactly, so it has to be set to something like http://en.wikipedia.org or https://meta.wikimedia.org .', - 'If this parameter does not match the Origin: header, a 403 response will be returned.', - 'If this parameter matches the Origin: header and the origin is whitelisted, an Access-Control-Allow-Origin header will be set.', + 'When accessing the API using a cross-domain AJAX request (CORS), set this to the', + 'originating domain. This must be included in any pre-flight request, and', + 'therefore must be part of the request URI (not the POST body). This must match', + 'one of the origins in the Origin: header exactly, so it has to be set to ', + 'something like http://en.wikipedia.org or https://meta.wikimedia.org . If this', + 'parameter does not match the Origin: header, a 403 response will be returned. If', + 'this parameter matches the Origin: header and the origin is whitelisted, an', + 'Access-Control-Allow-Origin header will be set.', ), ); } @@ -1073,14 +1095,14 @@ class ApiMain extends ApiBase { return array( '', '', - '**********************************************************************************************************', - '** **', - '** This is an auto-generated MediaWiki API documentation page **', - '** **', - '** Documentation and Examples: **', - '** https://www.mediawiki.org/wiki/API **', - '** **', - '**********************************************************************************************************', + '**********************************************************************************************', + '** **', + '** This is an auto-generated MediaWiki API documentation page **', + '** **', + '** Documentation and Examples: **', + '** https://www.mediawiki.org/wiki/API **', + '** **', + '**********************************************************************************************', '', 'Status: All features shown on this page should be working, but the API', ' is still in active development, and may change at any time.', @@ -1093,13 +1115,15 @@ class ApiMain extends ApiBase { ' In the case of an invalid action being passed, these will have a value', ' of "unknown_action"', '', - ' For more information see https://www.mediawiki.org/wiki/API:Errors_and_warnings', + ' For more information see https://www.mediawiki.org' . + '/wiki/API:Errors_and_warnings', '', 'Documentation: https://www.mediawiki.org/wiki/API:Main_page', 'FAQ https://www.mediawiki.org/wiki/API:FAQ', 'Mailing list: https://lists.wikimedia.org/mailman/listinfo/mediawiki-api', 'Api Announcements: https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce', - 'Bugs & Requests: https://bugzilla.wikimedia.org/buglist.cgi?component=API&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts', + 'Bugs & Requests: https://bugzilla.wikimedia.org/buglist.cgi?component=API&' . + 'bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts', '', '', '', @@ -1132,7 +1156,8 @@ class ApiMain extends ApiBase { ' Victor Vasiliev - vasilvv @ gmail . com', ' Bryan Tong Minh - bryan . tongminh @ gmail . com', ' Sam Reed - sam @ reedyboy . net', - ' Yuri Astrakhan "@gmail.com" (creator, lead developer Sep 2006-Sep 2007, 2012-present)', + ' Yuri Astrakhan "@gmail.com" (creator, lead ' . + 'developer Sep 2006-Sep 2007, 2012-present)', '', 'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org', 'or file a bug report at https://bugzilla.wikimedia.org/' @@ -1221,7 +1246,8 @@ class ApiMain extends ApiBase { /** * @param $module ApiBase - * @param string $paramName What type of request is this? e.g. action, query, list, prop, meta, format + * @param string $paramName What type of request is this? e.g. action, + * query, list, prop, meta, format * @return string */ public static function makeHelpMsgHeader( $module, $paramName ) { diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index c2d095954f..5d5d1b7a98 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -77,7 +77,11 @@ class ApiMove extends ApiBase { $this->dieUsageMsg( reset( $retval ) ); } - $r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] ); + $r = array( + 'from' => $fromTitle->getPrefixedText(), + 'to' => $toTitle->getPrefixedText(), + 'reason' => $params['reason'] + ); if ( $fromTitle->exists() ) { //NOTE: we assume that if the old title exists, it's because it was re-created as @@ -232,7 +236,8 @@ class ApiMove extends ApiBase { 'noredirect' => 'Don\'t create a redirect', 'watch' => 'Add the page and the redirect to your watchlist', 'unwatch' => 'Remove the page and the redirect from your watchlist', - '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' ); } @@ -293,7 +298,8 @@ class ApiMove extends ApiBase { public function getExamples() { return array( - 'api.php?action=move&from=Badtitle&to=Goodtitle&token=123ABC&reason=Misspelled%20title&movetalk=&noredirect=' + 'api.php?action=move&from=Badtitle&to=Goodtitle&token=123ABC&' . + 'reason=Misspelled%20title&movetalk=&noredirect=' ); } diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 7256066d09..929b0b6544 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -31,7 +31,6 @@ * @ingroup API */ class ApiOptions extends ApiBase { - /** * Changes preferences of the current user. */ @@ -172,9 +171,13 @@ class ApiOptions extends ApiBase { 'token' => 'An options token previously obtained through the action=tokens', 'reset' => 'Resets preferences to the site defaults', 'resetkinds' => 'List of types of options to reset when the "reset" option is set', - 'change' => 'List of changes, formatted name=value (e.g. skin=vector), value cannot contain pipe characters. If no value is given (not even an equals sign), e.g., optionname|otheroption|..., the option will be reset to its default value', + 'change' => 'List of changes, formatted name=value (e.g. skin=vector), ' . + 'value cannot contain pipe characters. If no value is given (not ' . + 'even an equals sign), e.g., optionname|otheroption|..., the ' . + 'option will be reset to its default value', 'optionname' => 'A name of a option which should have an optionvalue set', - 'optionvalue' => 'A value of the option specified by the optionname, can contain pipe characters', + 'optionvalue' => 'A value of the option specified by the optionname, ' . + 'can contain pipe characters', ); } @@ -182,7 +185,8 @@ class ApiOptions extends ApiBase { return array( 'Change preferences of the current user', 'Only options which are registered in core or in one of installed extensions,', - 'or as options with keys prefixed with \'userjs-\' (intended to be used by user scripts), can be set.' + 'or as options with keys prefixed with \'userjs-\' (intended to be used by user', + 'scripts), can be set.' ); } @@ -209,7 +213,8 @@ class ApiOptions extends ApiBase { return array( 'api.php?action=options&reset=&token=123ABC', 'api.php?action=options&change=skin=vector|hideminor=1&token=123ABC', - 'api.php?action=options&reset=&change=skin=monobook&optionname=nickname&optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC', + 'api.php?action=options&reset=&change=skin=monobook&optionname=nickname&' . + 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC', ); } } diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 9981ec1213..8105b94803 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -684,7 +684,8 @@ class ApiQueryImageInfo extends ApiQueryBase { =>'If translations for extmetadata property are available, fetch all of them.', 'extmetadatafilter' => "If specified and non-empty, only these keys will be returned for {$p}prop=extmetadata", - 'continue' => 'If the query response includes a continue value, use it here to get another page of results', + 'continue' => 'If the query response includes a continue value, ' . + 'use it here to get another page of results', 'localonly' => 'Look only for files in the local repository', ); } -- 2.20.1