summaryrefslogtreecommitdiff
path: root/includes/api/ApiMain.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
commitd9022f63880ce039446fba8364f68e656b7bf4cb (patch)
tree16b40fbf17bf7c9ee6f4ead25b16dd192378050a /includes/api/ApiMain.php
parent27cf83d177256813e2e802241085fce5dd0f3fb9 (diff)
Update to MediaWiki 1.19.0
Diffstat (limited to 'includes/api/ApiMain.php')
-rw-r--r--includes/api/ApiMain.php92
1 files changed, 52 insertions, 40 deletions
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index b7e118cf..fa95cfca 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -25,11 +25,6 @@
* @defgroup API API
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( 'ApiBase.php' );
-}
-
/**
* This is the main API class, used for both external and internal processing.
* When executed, it will create the requested formatter object,
@@ -132,7 +127,7 @@ class ApiMain extends ApiBase {
private $mPrinter;
private $mModules, $mModuleNames, $mFormats, $mFormatNames;
- private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
+ private $mResult, $mAction, $mShowVersions, $mEnableWrite;
private $mInternalMode, $mSquidMaxage, $mModule;
private $mCacheMode = 'private';
@@ -141,11 +136,25 @@ class ApiMain extends ApiBase {
/**
* Constructs an instance of ApiMain that utilizes the module and format specified by $request.
*
- * @param $request 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 $enableWrite bool should be set to true if the api may modify data
*/
- public function __construct( $request, $enableWrite = false ) {
- $this->mInternalMode = ( $request instanceof FauxRequest );
+ public function __construct( $context = null, $enableWrite = false ) {
+ if ( $context === null ) {
+ $context = RequestContext::getMain();
+ } elseif ( $context instanceof WebRequest ) {
+ // BC for pre-1.19
+ $request = $context;
+ $context = RequestContext::getMain();
+ }
+ // We set a derivative context so we can change stuff later
+ $this->setContext( new DerivativeContext( $context ) );
+
+ if ( isset( $request ) ) {
+ $this->getContext()->setRequest( $request );
+ }
+
+ $this->mInternalMode = ( $this->getRequest() instanceof FauxRequest );
// Special handling for the main module: $parent === $this
parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
@@ -156,11 +165,12 @@ class ApiMain extends ApiBase {
// Remove all modules other than login
global $wgUser;
- if ( $request->getVal( 'callback' ) !== null ) {
+ if ( $this->getRequest()->getVal( 'callback' ) !== null ) {
// JSON callback allows cross-site reads.
// For safety, strip user credentials.
wfDebug( "API: stripping user credentials for JSON callback\n" );
$wgUser = new User();
+ $this->getContext()->setUser( $wgUser );
}
}
@@ -175,8 +185,6 @@ class ApiMain extends ApiBase {
$this->mShowVersions = false;
$this->mEnableWrite = $enableWrite;
- $this->mRequest = &$request;
-
$this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
$this->mCommit = false;
}
@@ -190,14 +198,6 @@ class ApiMain extends ApiBase {
}
/**
- * Return the request object that contains client's request
- * @return WebRequest
- */
- public function getRequest() {
- return $this->mRequest;
- }
-
- /**
* Get the ApiResult object associated with current request
*
* @return ApiResult
@@ -286,6 +286,7 @@ class ApiMain extends ApiBase {
* $this->setCacheMode('private')
*/
public function setCachePrivate() {
+ wfDeprecated( __METHOD__, '1.17' );
$this->setCacheMode( 'private' );
}
@@ -314,6 +315,7 @@ class ApiMain extends ApiBase {
* @deprecated since 1.17 Use setCacheMode( 'anon-public-user-private' )
*/
public function setVaryCookie() {
+ wfDeprecated( __METHOD__, '1.17' );
$this->setCacheMode( 'anon-public-user-private' );
}
@@ -399,7 +401,7 @@ class ApiMain extends ApiBase {
}
protected function sendCacheHeaders() {
- global $wgUseXVO, $wgOut, $wgVaryOnXFP;
+ global $wgUseXVO, $wgVaryOnXFP;
$response = $this->getRequest()->response();
if ( $this->mCacheMode == 'private' ) {
@@ -411,11 +413,12 @@ class ApiMain extends ApiBase {
$xfp = $wgVaryOnXFP ? ', X-Forwarded-Proto' : '';
$response->header( 'Vary: Accept-Encoding, Cookie' . $xfp );
if ( $wgUseXVO ) {
+ $out = $this->getOutput();
if ( $wgVaryOnXFP ) {
- $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
+ $out->addVaryHeader( 'X-Forwarded-Proto' );
}
- $response->header( $wgOut->getXVO() );
- if ( $wgOut->haveCacheVaryCookies() ) {
+ $response->header( $out->getXVO() );
+ if ( $out->haveCacheVaryCookies() ) {
// Logged in, mark this request private
$response->header( 'Cache-Control: private' );
return;
@@ -428,7 +431,7 @@ class ApiMain extends ApiBase {
return;
} // else no XVO and anonymous, send public headers below
}
-
+
// Send public headers
if ( $wgVaryOnXFP ) {
$response->header( 'Vary: Accept-Encoding, X-Forwarded-Proto' );
@@ -486,6 +489,8 @@ class ApiMain extends ApiBase {
* @return string
*/
protected function substituteResultWithError( $e ) {
+ global $wgShowHostnames;
+
$result = $this->getResult();
// Printer may not be initialized if the extractRequestParams() fails for the main module
if ( !isset ( $this->mPrinter ) ) {
@@ -533,8 +538,12 @@ class ApiMain extends ApiBase {
if ( !is_null( $requestid ) ) {
$result->addValue( null, 'requestid', $requestid );
}
- // servedby is especially useful when debugging errors
- $result->addValue( null, 'servedby', wfHostName() );
+
+ if ( $wgShowHostnames ) {
+ // servedby is especially useful when debugging errors
+ $result->addValue( null, 'servedby', wfHostName() );
+ }
+
$result->addValue( null, 'error', $errMessage );
return $errMessage['code'];
@@ -545,15 +554,20 @@ class ApiMain extends ApiBase {
* @return array
*/
protected function setupExecuteAction() {
+ global $wgShowHostnames;
+
// First add the id to the top element
$result = $this->getResult();
$requestid = $this->getParameter( 'requestid' );
if ( !is_null( $requestid ) ) {
$result->addValue( null, 'requestid', $requestid );
}
- $servedby = $this->getParameter( 'servedby' );
- if ( $servedby ) {
- $result->addValue( null, 'servedby', wfHostName() );
+
+ if ( $wgShowHostnames ) {
+ $servedby = $this->getParameter( 'servedby' );
+ if ( $servedby ) {
+ $result->addValue( null, 'servedby', wfHostName() );
+ }
}
$params = $this->extractRequestParams();
@@ -591,8 +605,7 @@ class ApiMain extends ApiBase {
if ( !isset( $moduleParams['token'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
} else {
- global $wgUser;
- if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
+ if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
$this->dieUsageMsg( 'sessionfailure' );
}
}
@@ -634,9 +647,9 @@ class ApiMain extends ApiBase {
* @param $module ApiBase An Api module
*/
protected function checkExecutePermissions( $module ) {
- global $wgUser;
+ $user = $this->getUser();
if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) &&
- !$wgUser->isAllowed( 'read' ) )
+ !$user->isAllowed( 'read' ) )
{
$this->dieUsageMsg( 'readrequired' );
}
@@ -644,7 +657,7 @@ class ApiMain extends ApiBase {
if ( !$this->mEnableWrite ) {
$this->dieUsageMsg( 'writedisabled' );
}
- if ( !$wgUser->isAllowed( 'writeapi' ) ) {
+ if ( !$user->isAllowed( 'writeapi' ) ) {
$this->dieUsageMsg( 'writerequired' );
}
if ( wfReadOnly() ) {
@@ -660,7 +673,7 @@ class ApiMain extends ApiBase {
*/
protected function setupExternalResponse( $module, $params ) {
// Ignore mustBePosted() for internal calls
- if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
+ if ( $module->mustBePosted() && !$this->getRequest()->wasPosted() ) {
$this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
}
@@ -807,8 +820,8 @@ class ApiMain extends ApiBase {
'** **',
'** This is an auto-generated MediaWiki API documentation page **',
'** **',
- '** Documentation and Examples: **',
- '** https://www.mediawiki.org/wiki/API **',
+ '** Documentation and Examples: **',
+ '** https://www.mediawiki.org/wiki/API **',
'** **',
'**********************************************************************************************************',
'',
@@ -970,8 +983,7 @@ class ApiMain extends ApiBase {
*/
public function canApiHighLimits() {
if ( !isset( $this->mCanApiHighLimits ) ) {
- global $wgUser;
- $this->mCanApiHighLimits = $wgUser->isAllowed( 'apihighlimits' );
+ $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
}
return $this->mCanApiHighLimits;