34 $token = $params[
'token'];
35 $maxage = $params[
'maxtokenage'];
44 if ( str_ends_with( $token, urldecode( Token::SUFFIX ) ) ) {
45 $this->
addWarning(
'apiwarn-checktoken-percentencoding' );
48 if ( $tokenObj->match( $token, $maxage ) ) {
49 $res[
'result'] =
'valid';
50 } elseif ( $maxage !==
null && $tokenObj->match( $token ) ) {
51 $res[
'result'] =
'expired';
53 $res[
'result'] =
'invalid';
56 $ts = Token::getTimestamp( $token );
59 $mwts->timestamp->setTimestamp( $ts );
60 $res[
'generated'] = $mwts->getTimestamp( TS_ISO_8601 );
70 ParamValidator::PARAM_REQUIRED =>
true,
73 ParamValidator::PARAM_TYPE =>
'string',
74 ParamValidator::PARAM_REQUIRED =>
true,
75 ParamValidator::PARAM_SENSITIVE =>
true,
78 ParamValidator::PARAM_TYPE =>
'integer',
85 'action=checktoken&type=csrf&token=123ABC'
86 =>
'apihelp-checktoken-example-simple',
This abstract class implements many basic API functions, and is the base of all API classes.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static getTokenTypeSalts()
Get the salts for known token types.
static getToken(User $user, MediaWiki\Session\Session $session, $salt)
Get a token from a salt.
Library for creating and parsing MW-style timestamps.