From a60643422ba87bba57417663f3aadc6a3e1f9b3b Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Nov 2013 13:42:04 +0100 Subject: [PATCH] Update formatting on more API classes Change-Id: I1e6325b628359a557ceaa1e1ae30043aa5fc1402 --- includes/api/ApiFormatRaw.php | 1 + includes/api/ApiFormatWddx.php | 5 +++-- includes/api/ApiFormatXml.php | 8 ++++++-- includes/api/ApiHelp.php | 6 +++--- includes/api/ApiImageRotate.php | 5 +++++ includes/api/ApiImport.php | 1 + includes/api/ApiLogin.php | 1 + includes/api/ApiMain.php | 32 ++++++++++++++++++++++++++----- includes/api/ApiModuleManager.php | 3 +++ includes/api/ApiMove.php | 8 +++++--- 10 files changed, 55 insertions(+), 15 deletions(-) diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index d278efa0bc..45003e90ad 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -58,6 +58,7 @@ class ApiFormatRaw extends ApiFormatBase { $data = $this->getResultData(); if ( isset( $data['error'] ) ) { $this->mErrorFallback->execute(); + return; } diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php index 5685d93716..eb83198fc6 100644 --- a/includes/api/ApiFormatWddx.php +++ b/includes/api/ApiFormatWddx.php @@ -40,8 +40,9 @@ class ApiFormatWddx extends ApiFormatBase { // to avoid this. $expected = "
\xc2\xa0"; if ( function_exists( 'wddx_serialize_value' ) - && !$this->getIsHtml() - && wddx_serialize_value( "\xc2\xa0" ) == $expected ) { + && !$this->getIsHtml() + && wddx_serialize_value( "\xc2\xa0" ) == $expected + ) { $this->printText( wddx_serialize_value( $this->getResultData() ) ); } else { // Don't do newlines and indentation if we weren't asked diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 4ec149c09e..0917ac7fad 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -69,7 +69,7 @@ class ApiFormatXml extends ApiFormatBase { $this->printText( self::recXmlPrint( $this->mRootElemName, $data, - $this->getIsHtml() ? - 2 : null + $this->getIsHtml() ? -2 : null ) ); } @@ -193,6 +193,7 @@ class ApiFormatXml extends ApiFormatBase { $retval .= $indstr . Xml::element( $elemName, null, $elemValue ); } } + return $retval; } @@ -200,14 +201,17 @@ class ApiFormatXml extends ApiFormatBase { $nt = Title::newFromText( $this->mXslt ); if ( is_null( $nt ) || !$nt->exists() ) { $this->setWarning( 'Invalid or non-existent stylesheet specified' ); + return; } if ( $nt->getNamespace() != NS_MEDIAWIKI ) { $this->setWarning( 'Stylesheet should be in the MediaWiki namespace.' ); + return; } - if ( substr( $nt->getText(), - 4 ) !== '.xsl' ) { + if ( substr( $nt->getText(), -4 ) !== '.xsl' ) { $this->setWarning( 'Stylesheet should have .xsl extension.' ); + return; } $this->printText( 'getLocalURL( 'action=raw' ) ) . '" type="text/xsl" ?>' ); diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php index 9cafc5bbfa..1aa300a8ba 100644 --- a/includes/api/ApiHelp.php +++ b/includes/api/ApiHelp.php @@ -78,9 +78,9 @@ class ApiHelp extends ApiBase { } if ( $module === null ) { if ( count( $subNames ) === 2 - && $i === 1 - && $subNames[0] === 'query' - && in_array( $subNames[1], $queryModules ) + && $i === 1 + && $subNames[0] === 'query' + && in_array( $subNames[1], $queryModules ) ) { // Legacy: This is one of the renamed 'querymodule=...' parameters, // do not use '+' notation in the output, use submodule's name instead. diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php index 7a60e831b3..1a8f2a6a4b 100644 --- a/includes/api/ApiImageRotate.php +++ b/includes/api/ApiImageRotate.php @@ -145,6 +145,7 @@ class ApiImageRotate extends ApiBase { if ( $this->mPageSet === null ) { $this->mPageSet = new ApiPageSet( $this, 0, NS_FILE ); } + return $this->mPageSet; } @@ -163,6 +164,7 @@ class ApiImageRotate extends ApiBase { if ( $permissionErrors ) { // Just return the first error $msg = $this->parseMsg( $permissionErrors[0] ); + return $msg['info']; } @@ -191,11 +193,13 @@ class ApiImageRotate extends ApiBase { if ( $flags ) { $result += $this->getPageSet()->getFinalParams( $flags ); } + return $result; } public function getParamDescription() { $pageSet = $this->getPageSet(); + return $pageSet->getFinalParamDescription() + array( 'rotation' => 'Degrees to rotate image clockwise', 'token' => 'Edit token. You can get one of these through action=tokens', @@ -216,6 +220,7 @@ class ApiImageRotate extends ApiBase { public function getPossibleErrors() { $pageSet = $this->getPageSet(); + return array_merge( parent::getPossibleErrors(), $pageSet->getFinalPossibleErrors() diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index f48a822e36..92539646f1 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -99,6 +99,7 @@ class ApiImport extends ApiBase { public function getAllowedParams() { global $wgImportSources; + return array( 'token' => array( ApiBase::PARAM_TYPE => 'string', diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 13e58b8950..18fd0c7570 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -52,6 +52,7 @@ class ApiLogin extends ApiBase { 'result' => 'Aborted', 'reason' => 'Cannot log in when using a callback', ) ); + return; } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index c11f16cba4..61577cb0cd 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -191,7 +191,7 @@ class ApiMain extends ApiBase { $this->mResult = new ApiResult( $this ); $this->mEnableWrite = $enableWrite; - $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling() + $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling() $this->mCommit = false; } @@ -270,6 +270,7 @@ class ApiMain extends ApiBase { public function setCacheMode( $mode ) { if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) { wfDebug( __METHOD__ . ": unrecognised cache mode \"$mode\"\n" ); + // Ignore for forwards-compatibility return; } @@ -278,6 +279,7 @@ class ApiMain extends ApiBase { // Private wiki, only private headers if ( $mode !== 'private' ) { wfDebug( __METHOD__ . ": ignoring request for $mode cache mode, private wiki\n" ); + return; } } @@ -337,6 +339,7 @@ class ApiMain extends ApiBase { if ( $printer === null ) { $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' ); } + return $printer; } @@ -463,6 +466,7 @@ class ApiMain extends ApiBase { $response->header( "HTTP/1.1 403 $message", true, 403 ); $response->header( 'Cache-Control: no-cache' ); echo "'origin' parameter does not match Origin header\n"; + return false; } if ( self::matchOrigin( $originParam, $wgCrossSiteAJAXdomains, $wgCrossSiteAJAXdomainExceptions ) ) { @@ -470,6 +474,7 @@ class ApiMain extends ApiBase { $response->header( 'Access-Control-Allow-Credentials: true' ); $this->getOutput()->addVaryHeader( 'Origin' ); } + return true; } @@ -489,9 +494,11 @@ class ApiMain extends ApiBase { return false; } } + return true; } } + return false; } @@ -510,6 +517,7 @@ class ApiMain extends ApiBase { array( '.*?', '.' ), $wildcard ); + return "/https?:\/\/$wildcard/"; } @@ -524,6 +532,7 @@ class ApiMain extends ApiBase { if ( $this->mCacheMode == 'private' ) { $response->header( 'Cache-Control: private' ); + return; } @@ -535,6 +544,7 @@ class ApiMain extends ApiBase { if ( $out->haveCacheVaryCookies() ) { // Logged in, mark this request private $response->header( 'Cache-Control: private' ); + return; } // Logged out, send normal public headers below @@ -542,6 +552,7 @@ class ApiMain extends ApiBase { // Logged in or otherwise has session (e.g. anonymous users who have edited) // Mark request private $response->header( 'Cache-Control: private' ); + return; } // else no XVO and anonymous, send public headers below } @@ -565,6 +576,7 @@ class ApiMain extends ApiBase { // Sending a Vary header in this case is harmless, and protects us // against conditional calls of setCacheMaxAge(). $response->header( 'Cache-Control: private' ); + return; } @@ -720,6 +732,7 @@ class ApiMain extends ApiBase { } } } + return $module; } @@ -746,9 +759,11 @@ class ApiMain extends ApiBase { } else { $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' ); } + return false; } } + return true; } @@ -759,8 +774,8 @@ class ApiMain extends ApiBase { protected function checkExecutePermissions( $module ) { $user = $this->getUser(); if ( $module->isReadMode() && !User::isEveryoneAllowed( 'read' ) && - !$user->isAllowed( 'read' ) ) - { + !$user->isAllowed( 'read' ) + ) { $this->dieUsageMsg( 'readrequired' ); } if ( $module->isWriteMode() ) { @@ -881,6 +896,7 @@ class ApiMain extends ApiBase { $table[rawurlencode( $chars[$i] )] = $chars[$i]; } } + return strtr( rawurlencode( $s ), $table ); } @@ -896,6 +912,7 @@ class ApiMain extends ApiBase { */ public function getVal( $name, $default = null ) { $this->mParamsUsed[$name] = true; + return $this->getRequest()->getVal( $name, $default ); } @@ -905,6 +922,7 @@ class ApiMain extends ApiBase { */ public function getCheck( $name ) { $this->mParamsUsed[$name] = true; + return $this->getRequest()->getCheck( $name ); } @@ -917,6 +935,7 @@ class ApiMain extends ApiBase { */ public function getUpload( $name ) { $this->mParamsUsed[$name] = true; + return $this->getRequest()->getUpload( $name ); } @@ -932,7 +951,7 @@ class ApiMain extends ApiBase { // Printer has not yet executed; don't warn that its parameters are unused $printerParams = array_map( array( $this->mPrinter, 'encodeParamName' ), - array_keys( $this->mPrinter->getFinalParams() ?: array() ) + array_keys( $this->mPrinter->getFinalParams() ? : array() ) ); $unusedParams = array_diff( $allParams, $paramsUsed, $printerParams ); } else { @@ -1150,6 +1169,7 @@ class ApiMain extends ApiBase { if ( $wgAPICacheHelpTimeout > 0 ) { $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout ); } + return $retval; } @@ -1180,7 +1200,7 @@ class ApiMain extends ApiBase { foreach ( self::$mRights as $right => $rightMsg ) { $groups = User::getGroupsWithPermission( $right ); $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg['msg'], $rightMsg['params'] ) . - "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n"; + "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n"; } $msg .= "\n$astriks Formats $astriks\n\n"; @@ -1234,6 +1254,7 @@ class ApiMain extends ApiBase { */ public function getShowVersions() { wfDeprecated( __METHOD__, '1.21' ); + return false; } @@ -1336,6 +1357,7 @@ class UsageException extends MWException { if ( is_array( $this->mExtraData ) ) { $result = array_merge( $result, $this->mExtraData ); } + return $result; } diff --git a/includes/api/ApiModuleManager.php b/includes/api/ApiModuleManager.php index 100392bf00..407e089ca3 100644 --- a/includes/api/ApiModuleManager.php +++ b/includes/api/ApiModuleManager.php @@ -97,6 +97,7 @@ class ApiModuleManager extends ContextSource { // cache this instance in case it is needed later $this->mInstances[$moduleName] = $instance; } + return $instance; } } @@ -116,6 +117,7 @@ class ApiModuleManager extends ContextSource { $result[] = $name; } } + return $result; } @@ -131,6 +133,7 @@ class ApiModuleManager extends ContextSource { $result[$name] = $grpCls[1]; } } + return $result; } diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index c18036cf37..c2d095954f 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -61,8 +61,8 @@ class ApiMove extends ApiBase { if ( $toTitle->getNamespace() == NS_FILE && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle ) - && wfFindFile( $toTitle ) ) - { + && wfFindFile( $toTitle ) + ) { if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) { $this->dieUsageMsg( 'sharedfile-exists' ); } elseif ( !$user->isAllowed( 'reupload-shared' ) ) { @@ -115,7 +115,7 @@ class ApiMove extends ApiBase { // Move subpages if ( $params['movesubpages'] ) { $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle, - $params['reason'], $params['noredirect'] ); + $params['reason'], $params['noredirect'] ); $result->setIndexedTagName( $r['subpages'], 'subpage' ); if ( $params['movetalk'] ) { @@ -167,6 +167,7 @@ class ApiMove extends ApiBase { $retval[] = $r; } } + return $retval; } @@ -219,6 +220,7 @@ class ApiMove extends ApiBase { public function getParamDescription() { $p = $this->getModulePrefix(); + return array( 'from' => "Title of the page you want to move. Cannot be used together with {$p}fromid", 'fromid' => "Page ID of the page you want to move. Cannot be used together with {$p}from", -- 2.20.1