2016-01-11 18:20:22 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2017-06-13 16:51:53 +00:00
|
|
|
* Copyright © 2016 Wikimedia Foundation and contributors
|
2016-01-11 18:20:22 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
|
2024-09-25 16:17:29 +00:00
|
|
|
namespace MediaWiki\Api;
|
|
|
|
|
|
2016-01-11 18:20:22 +00:00
|
|
|
use MediaWiki\Auth\AuthenticationRequest;
|
|
|
|
|
use MediaWiki\Auth\AuthenticationResponse;
|
2020-01-10 00:00:51 +00:00
|
|
|
use MediaWiki\Auth\AuthManager;
|
2016-01-11 18:20:22 +00:00
|
|
|
use MediaWiki\Auth\CreateFromLoginAuthenticationRequest;
|
2016-08-05 02:17:28 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2020-03-31 19:06:26 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-06-14 21:24:11 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2023-12-13 22:50:44 +00:00
|
|
|
use MediaWiki\Parser\Parser;
|
2024-09-25 16:17:29 +00:00
|
|
|
use UnexpectedValueException;
|
2022-06-05 23:18:50 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2016-01-11 18:20:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper class for AuthManager-using API modules. Intended for use via
|
|
|
|
|
* composition.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiAuthManagerHelper {
|
|
|
|
|
|
|
|
|
|
/** @var ApiBase API module, for context and parameters */
|
|
|
|
|
private $module;
|
|
|
|
|
|
|
|
|
|
/** @var string Message output format */
|
|
|
|
|
private $messageFormat;
|
|
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private AuthManager $authManager;
|
2020-03-31 19:06:26 +00:00
|
|
|
|
2016-01-11 18:20:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param ApiBase $module API module, for context and parameters
|
2020-03-31 19:06:26 +00:00
|
|
|
* @param AuthManager|null $authManager
|
2016-01-11 18:20:22 +00:00
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public function __construct( ApiBase $module, ?AuthManager $authManager = null ) {
|
2016-01-11 18:20:22 +00:00
|
|
|
$this->module = $module;
|
|
|
|
|
|
|
|
|
|
$params = $module->extractRequestParams();
|
2017-10-06 22:17:58 +00:00
|
|
|
$this->messageFormat = $params['messageformat'] ?? 'wikitext';
|
2020-03-31 19:06:26 +00:00
|
|
|
$this->authManager = $authManager ?: MediaWikiServices::getInstance()->getAuthManager();
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Static version of the constructor, for chaining
|
|
|
|
|
* @param ApiBase $module API module, for context and parameters
|
2020-03-31 19:06:26 +00:00
|
|
|
* @param AuthManager|null $authManager
|
2016-01-11 18:20:22 +00:00
|
|
|
* @return ApiAuthManagerHelper
|
|
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public static function newForModule( ApiBase $module, ?AuthManager $authManager = null ) {
|
2020-03-31 19:06:26 +00:00
|
|
|
return new self( $module, $authManager );
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format a message for output
|
|
|
|
|
* @param array &$res Result array
|
|
|
|
|
* @param string $key Result key
|
|
|
|
|
* @param Message $message
|
|
|
|
|
*/
|
|
|
|
|
private function formatMessage( array &$res, $key, Message $message ) {
|
|
|
|
|
switch ( $this->messageFormat ) {
|
|
|
|
|
case 'none':
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'wikitext':
|
|
|
|
|
$res[$key] = $message->setContext( $this->module )->text();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'html':
|
|
|
|
|
$res[$key] = $message->setContext( $this->module )->parseAsBlock();
|
|
|
|
|
$res[$key] = Parser::stripOuterParagraph( $res[$key] );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'raw':
|
2019-12-07 18:32:45 +00:00
|
|
|
$params = $message->getParams();
|
2016-01-11 18:20:22 +00:00
|
|
|
$res[$key] = [
|
|
|
|
|
'key' => $message->getKey(),
|
2019-12-07 18:32:45 +00:00
|
|
|
'params' => $params,
|
2016-01-11 18:20:22 +00:00
|
|
|
];
|
2019-12-07 18:32:45 +00:00
|
|
|
ApiResult::setIndexedTagName( $params, 'param' );
|
2016-01-11 18:20:22 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call $manager->securitySensitiveOperationStatus()
|
|
|
|
|
* @param string $operation Operation being checked.
|
2016-10-19 16:54:25 +00:00
|
|
|
* @throws ApiUsageException
|
2016-01-11 18:20:22 +00:00
|
|
|
*/
|
|
|
|
|
public function securitySensitiveOperation( $operation ) {
|
2020-03-31 19:06:26 +00:00
|
|
|
$status = $this->authManager->securitySensitiveOperationStatus( $operation );
|
2016-01-11 18:20:22 +00:00
|
|
|
switch ( $status ) {
|
|
|
|
|
case AuthManager::SEC_OK:
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case AuthManager::SEC_REAUTH:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->module->dieWithError( 'apierror-reauthenticate' );
|
2021-04-12 21:22:21 +00:00
|
|
|
// dieWithError prevents continuation
|
2016-01-11 18:20:22 +00:00
|
|
|
|
|
|
|
|
case AuthManager::SEC_FAIL:
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->module->dieWithError( 'apierror-cannotreauthenticate' );
|
2021-04-12 21:22:21 +00:00
|
|
|
// dieWithError prevents continuation
|
2016-01-11 18:20:22 +00:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new UnexpectedValueException( "Unknown status \"$status\"" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter out authentication requests by class name
|
|
|
|
|
* @param AuthenticationRequest[] $reqs Requests to filter
|
2021-03-19 16:12:50 +00:00
|
|
|
* @param string[] $remove Class names to remove
|
2016-01-11 18:20:22 +00:00
|
|
|
* @return AuthenticationRequest[]
|
|
|
|
|
*/
|
2021-03-19 16:12:50 +00:00
|
|
|
public static function blacklistAuthenticationRequests( array $reqs, array $remove ) {
|
|
|
|
|
if ( $remove ) {
|
2021-06-11 02:52:06 +00:00
|
|
|
$remove = array_fill_keys( $remove, true );
|
2021-03-19 16:12:50 +00:00
|
|
|
$reqs = array_filter( $reqs, static function ( $req ) use ( $remove ) {
|
|
|
|
|
return !isset( $remove[get_class( $req )] );
|
2016-01-11 18:20:22 +00:00
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
return $reqs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch and load the AuthenticationRequests for an action
|
|
|
|
|
* @param string $action One of the AuthManager::ACTION_* constants
|
|
|
|
|
* @return AuthenticationRequest[]
|
|
|
|
|
*/
|
|
|
|
|
public function loadAuthenticationRequests( $action ) {
|
|
|
|
|
$params = $this->module->extractRequestParams();
|
|
|
|
|
|
2020-03-31 19:06:26 +00:00
|
|
|
$reqs = $this->authManager->getAuthenticationRequests( $action, $this->module->getUser() );
|
2016-01-11 18:20:22 +00:00
|
|
|
|
|
|
|
|
// Filter requests, if requested to do so
|
|
|
|
|
$wantedRequests = null;
|
|
|
|
|
if ( isset( $params['requests'] ) ) {
|
2021-06-11 02:52:06 +00:00
|
|
|
$wantedRequests = array_fill_keys( $params['requests'], true );
|
2016-01-11 18:20:22 +00:00
|
|
|
} elseif ( isset( $params['request'] ) ) {
|
|
|
|
|
$wantedRequests = [ $params['request'] => true ];
|
|
|
|
|
}
|
|
|
|
|
if ( $wantedRequests !== null ) {
|
2020-02-13 10:24:10 +00:00
|
|
|
$reqs = array_filter(
|
|
|
|
|
$reqs,
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( AuthenticationRequest $req ) use ( $wantedRequests ) {
|
2020-02-13 10:24:10 +00:00
|
|
|
return isset( $wantedRequests[$req->getUniqueId()] );
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Collect the fields for all the requests
|
|
|
|
|
$fields = [];
|
2016-08-18 17:36:11 +00:00
|
|
|
$sensitive = [];
|
2016-01-11 18:20:22 +00:00
|
|
|
foreach ( $reqs as $req ) {
|
2016-08-18 17:36:11 +00:00
|
|
|
$info = (array)$req->getFieldInfo();
|
|
|
|
|
$fields += $info;
|
2021-02-10 22:31:02 +00:00
|
|
|
$sensitive += array_filter( $info, static function ( $opts ) {
|
2016-08-18 17:36:11 +00:00
|
|
|
return !empty( $opts['sensitive'] );
|
|
|
|
|
} );
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extract the request data for the fields and mark those request
|
|
|
|
|
// parameters as used
|
|
|
|
|
$data = array_intersect_key( $this->module->getRequest()->getValues(), $fields );
|
|
|
|
|
$this->module->getMain()->markParamsUsed( array_keys( $data ) );
|
|
|
|
|
|
2016-08-18 17:36:11 +00:00
|
|
|
if ( $sensitive ) {
|
2016-08-18 17:37:05 +00:00
|
|
|
$this->module->getMain()->markParamsSensitive( array_keys( $sensitive ) );
|
2016-10-31 17:41:17 +00:00
|
|
|
$this->module->requirePostedParameters( array_keys( $sensitive ), 'noprefix' );
|
2016-08-18 17:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-11 18:20:22 +00:00
|
|
|
return AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format an AuthenticationResponse for return
|
|
|
|
|
* @param AuthenticationResponse $res
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function formatAuthenticationResponse( AuthenticationResponse $res ) {
|
|
|
|
|
$ret = [
|
|
|
|
|
'status' => $res->status,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ( $res->status === AuthenticationResponse::PASS && $res->username !== null ) {
|
|
|
|
|
$ret['username'] = $res->username;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $res->status === AuthenticationResponse::REDIRECT ) {
|
|
|
|
|
$ret['redirecttarget'] = $res->redirectTarget;
|
|
|
|
|
if ( $res->redirectApiData !== null ) {
|
|
|
|
|
$ret['redirectdata'] = $res->redirectApiData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $res->status === AuthenticationResponse::REDIRECT ||
|
|
|
|
|
$res->status === AuthenticationResponse::UI ||
|
|
|
|
|
$res->status === AuthenticationResponse::RESTART
|
|
|
|
|
) {
|
|
|
|
|
$ret += $this->formatRequests( $res->neededRequests );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $res->status === AuthenticationResponse::FAIL ||
|
|
|
|
|
$res->status === AuthenticationResponse::UI ||
|
|
|
|
|
$res->status === AuthenticationResponse::RESTART
|
|
|
|
|
) {
|
|
|
|
|
$this->formatMessage( $ret, 'message', $res->message );
|
2017-02-21 17:06:41 +00:00
|
|
|
$ret['messagecode'] = ApiMessage::create( $res->message )->getApiCode();
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $res->status === AuthenticationResponse::FAIL ||
|
|
|
|
|
$res->status === AuthenticationResponse::RESTART
|
|
|
|
|
) {
|
|
|
|
|
$this->module->getRequest()->getSession()->set(
|
|
|
|
|
'ApiAuthManagerHelper::createRequest',
|
|
|
|
|
$res->createRequest
|
|
|
|
|
);
|
|
|
|
|
$ret['canpreservestate'] = $res->createRequest !== null;
|
|
|
|
|
} else {
|
|
|
|
|
$this->module->getRequest()->getSession()->remove( 'ApiAuthManagerHelper::createRequest' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 02:17:28 +00:00
|
|
|
/**
|
|
|
|
|
* Logs successful or failed authentication.
|
|
|
|
|
* @param string $event Event type (e.g. 'accountcreation')
|
2023-10-12 13:41:06 +00:00
|
|
|
* @param AuthenticationResponse $result Response or error message
|
2016-08-05 02:17:28 +00:00
|
|
|
*/
|
2023-10-12 13:41:06 +00:00
|
|
|
public function logAuthenticationResult( $event, AuthenticationResponse $result ) {
|
|
|
|
|
if ( !in_array( $result->status, [ AuthenticationResponse::PASS, AuthenticationResponse::FAIL ] ) ) {
|
2016-08-05 02:17:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$module = $this->module->getModuleName();
|
2016-08-10 01:32:28 +00:00
|
|
|
LoggerFactory::getInstance( 'authevents' )->info( "$module API attempt", [
|
2016-08-05 02:17:28 +00:00
|
|
|
'event' => $event,
|
2023-10-12 13:41:06 +00:00
|
|
|
'successful' => $result->status === AuthenticationResponse::PASS,
|
|
|
|
|
'status' => $result->message ? $result->message->getKey() : '-',
|
2016-08-05 02:17:28 +00:00
|
|
|
'module' => $module,
|
|
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 18:20:22 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch the preserved CreateFromLoginAuthenticationRequest, if any
|
|
|
|
|
* @return CreateFromLoginAuthenticationRequest|null
|
|
|
|
|
*/
|
|
|
|
|
public function getPreservedRequest() {
|
|
|
|
|
$ret = $this->module->getRequest()->getSession()->get( 'ApiAuthManagerHelper::createRequest' );
|
|
|
|
|
return $ret instanceof CreateFromLoginAuthenticationRequest ? $ret : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format an array of AuthenticationRequests for return
|
|
|
|
|
* @param AuthenticationRequest[] $reqs
|
|
|
|
|
* @return array Will have a 'requests' key, and also 'fields' if $module's
|
|
|
|
|
* params include 'mergerequestfields'.
|
|
|
|
|
*/
|
|
|
|
|
public function formatRequests( array $reqs ) {
|
|
|
|
|
$params = $this->module->extractRequestParams();
|
|
|
|
|
$mergeFields = !empty( $params['mergerequestfields'] );
|
|
|
|
|
|
|
|
|
|
$ret = [ 'requests' => [] ];
|
|
|
|
|
foreach ( $reqs as $req ) {
|
|
|
|
|
$describe = $req->describeCredentials();
|
|
|
|
|
$reqInfo = [
|
|
|
|
|
'id' => $req->getUniqueId(),
|
2016-05-24 18:05:52 +00:00
|
|
|
'metadata' => $req->getMetadata() + [ ApiResult::META_TYPE => 'assoc' ],
|
2016-01-11 18:20:22 +00:00
|
|
|
];
|
|
|
|
|
switch ( $req->required ) {
|
|
|
|
|
case AuthenticationRequest::OPTIONAL:
|
|
|
|
|
$reqInfo['required'] = 'optional';
|
|
|
|
|
break;
|
|
|
|
|
case AuthenticationRequest::REQUIRED:
|
|
|
|
|
$reqInfo['required'] = 'required';
|
|
|
|
|
break;
|
|
|
|
|
case AuthenticationRequest::PRIMARY_REQUIRED:
|
|
|
|
|
$reqInfo['required'] = 'primary-required';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$this->formatMessage( $reqInfo, 'provider', $describe['provider'] );
|
|
|
|
|
$this->formatMessage( $reqInfo, 'account', $describe['account'] );
|
|
|
|
|
if ( !$mergeFields ) {
|
|
|
|
|
$reqInfo['fields'] = $this->formatFields( (array)$req->getFieldInfo() );
|
|
|
|
|
}
|
|
|
|
|
$ret['requests'][] = $reqInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $mergeFields ) {
|
|
|
|
|
$fields = AuthenticationRequest::mergeFieldInfo( $reqs );
|
|
|
|
|
$ret['fields'] = $this->formatFields( $fields );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clean up a field array for output
|
|
|
|
|
* @param array $fields
|
2021-04-04 19:18:22 +00:00
|
|
|
* @phpcs:ignore Generic.Files.LineLength
|
2019-08-30 17:56:27 +00:00
|
|
|
* @phan-param array{type:string,options:array,value:string,label:Message,help:Message,optional:bool,sensitive:bool,skippable:bool} $fields
|
2016-01-11 18:20:22 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function formatFields( array $fields ) {
|
|
|
|
|
static $copy = [
|
|
|
|
|
'type' => true,
|
|
|
|
|
'value' => true,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$module = $this->module;
|
|
|
|
|
$retFields = [];
|
|
|
|
|
|
|
|
|
|
foreach ( $fields as $name => $field ) {
|
|
|
|
|
$ret = array_intersect_key( $field, $copy );
|
|
|
|
|
|
|
|
|
|
if ( isset( $field['options'] ) ) {
|
2021-02-10 22:31:02 +00:00
|
|
|
$ret['options'] = array_map( static function ( $msg ) use ( $module ) {
|
2016-01-11 18:20:22 +00:00
|
|
|
return $msg->setContext( $module )->plain();
|
|
|
|
|
}, $field['options'] );
|
|
|
|
|
ApiResult::setArrayType( $ret['options'], 'assoc' );
|
|
|
|
|
}
|
|
|
|
|
$this->formatMessage( $ret, 'label', $field['label'] );
|
|
|
|
|
$this->formatMessage( $ret, 'help', $field['help'] );
|
|
|
|
|
$ret['optional'] = !empty( $field['optional'] );
|
2016-08-18 17:03:10 +00:00
|
|
|
$ret['sensitive'] = !empty( $field['sensitive'] );
|
2016-01-11 18:20:22 +00:00
|
|
|
|
|
|
|
|
$retFields[$name] = $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApiResult::setArrayType( $retFields, 'assoc' );
|
|
|
|
|
|
|
|
|
|
return $retFields;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the standard parameters this helper recognizes
|
|
|
|
|
* @param string $action AuthManager action
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
* @param string ...$wantedParams Parameters to use
|
2016-01-11 18:20:22 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
public static function getStandardParams( $action, ...$wantedParams ) {
|
2016-01-11 18:20:22 +00:00
|
|
|
$params = [
|
|
|
|
|
'requests' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => [ 'api-help-authmanagerhelper-requests', $action ],
|
|
|
|
|
],
|
|
|
|
|
'request' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => [ 'api-help-authmanagerhelper-request', $action ],
|
|
|
|
|
],
|
|
|
|
|
'messageformat' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 'wikitext',
|
|
|
|
|
ParamValidator::PARAM_TYPE => [ 'html', 'wikitext', 'raw', 'none' ],
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-authmanagerhelper-messageformat',
|
|
|
|
|
],
|
|
|
|
|
'mergerequestfields' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-authmanagerhelper-mergerequestfields',
|
|
|
|
|
],
|
|
|
|
|
'preservestate' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-authmanagerhelper-preservestate',
|
|
|
|
|
],
|
|
|
|
|
'returnurl' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-authmanagerhelper-returnurl',
|
|
|
|
|
],
|
|
|
|
|
'continue' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2016-01-11 18:20:22 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-authmanagerhelper-continue',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$ret = [];
|
|
|
|
|
foreach ( $wantedParams as $name ) {
|
|
|
|
|
if ( isset( $params[$name] ) ) {
|
|
|
|
|
$ret[$name] = $params[$name];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-25 16:17:29 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ApiAuthManagerHelper::class, 'ApiAuthManagerHelper' );
|