Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71858
Change subject: PATH_INFO-based API actions
......................................................................
PATH_INFO-based API actions
* all legacy api.php?action=... calls are treated as version 0
* api.php/action is treated as version 1
* A number of core modules will check this version to change their
behaviour, such as change output format and parameters in the following
patches.
Change-Id: Ic8b6b5e64c15b42abed787fd561d58cf38835759
---
M includes/api/ApiMain.php
1 file changed, 42 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/58/71858/1
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 7583993..b70c1f9 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -146,8 +146,10 @@
*
* @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
+ * @param int $apiVersion If the version is default (-1), the version
will either be 0 or 1 depending if
+ * request's pathinfo is set
*/
- public function __construct( $context = null, $enableWrite = false ) {
+ public function __construct( $context = null, $enableWrite = false,
$apiVersion = -1 ) {
if ( $context === null ) {
$context = RequestContext::getMain();
} elseif ( $context instanceof WebRequest ) {
@@ -162,12 +164,34 @@
$this->getContext()->setRequest( $request );
}
- $this->mInternalMode = ( $this->getRequest() instanceof
FauxRequest );
+ $req = $this->getRequest();
+ $isInternal = ( $req instanceof FauxRequest );
+ $this->mInternalMode = $isInternal;
+
+ // action is determined by the pathinfo, e.g. /w/api.php/query
for live requests,
+ // and by the action=xxx parameter for the internal FauxRequests
+ $this->mAction = null;
+ if ( !$isInternal ) {
+ // @TODO: pathinfo should be part of the context
+ $pathInfo = WebRequest::getPathInfo();
+ if ( array_key_exists( 'title', $pathInfo ) ) {
+ $this->mAction = $pathInfo['title'];
+ }
+ }
+
+ if ( $apiVersion < 0 ) {
+ $apiVersion = $this->mAction === null ? 0 : 1;
+ }
+
+ $name = $isInternal ? 'main_int' : 'main';
+ if ( $apiVersion > 0 ) {
+ $name = $name . '~' . $apiVersion;
+ }
// Special handling for the main module: $parent === $this
- parent::__construct( $this, $this->mInternalMode ? 'main_int' :
'main' );
+ parent::__construct( $this, $name );
- if ( !$this->mInternalMode ) {
+ if ( !$isInternal ) {
// Impose module restrictions.
// If the current user cannot read,
// Remove all modules other than login
@@ -693,7 +717,9 @@
$params = $this->extractRequestParams();
- $this->mAction = $params['action'];
+ if ( $this->mAction === null && array_key_exists( 'action',
$params ) ) {
+ $this->mAction = $params['action'];
+ }
if ( !is_string( $this->mAction ) ) {
$this->dieUsage( 'The API requires a valid action
parameter', 'unknown_action' );
@@ -999,14 +1025,10 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ $res = array(
'format' => array(
ApiBase::PARAM_DFLT =>
ApiMain::API_DEFAULT_FORMAT,
ApiBase::PARAM_TYPE =>
$this->mModuleMgr->getNames( 'format' )
- ),
- 'action' => array(
- ApiBase::PARAM_DFLT => 'help',
- ApiBase::PARAM_TYPE =>
$this->mModuleMgr->getNames( 'action' )
),
'maxlag' => array(
ApiBase::PARAM_TYPE => 'integer'
@@ -1023,6 +1045,16 @@
'servedby' => false,
'origin' => null,
);
+ if ( $this->getModuleVersion() < 1 || $this->isInternalMode() )
{
+ // Force 'action' to be the first value
+ $res = array_merge( array(
+ 'action' => array(
+ ApiBase::PARAM_DFLT => 'help',
+ ApiBase::PARAM_TYPE =>
$this->mModuleMgr->getNames( 'action' )
+ ) ),
+ $res );
+ }
+ return $res;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/71858
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8b6b5e64c15b42abed787fd561d58cf38835759
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits