* @file
*/
+use MediaWiki\Session\Token;
+
/**
* @since 1.25
* @ingroup API
$maxage = $params['maxtokenage'];
$salts = ApiQueryTokens::getTokenTypeSalts();
- $res = array();
+ $res = [];
$tokenObj = ApiQueryTokens::getToken(
$this->getUser(), $this->getRequest()->getSession(), $salts[$params['type']]
);
+
+ if ( substr( $token, -strlen( urldecode( Token::SUFFIX ) ) ) === urldecode( Token::SUFFIX ) ) {
+ $this->addWarning( 'apiwarn-checktoken-percentencoding' );
+ }
+
if ( $tokenObj->match( $token, $maxage ) ) {
$res['result'] = 'valid';
} elseif ( $maxage !== null && $tokenObj->match( $token ) ) {
$res['result'] = 'invalid';
}
- $ts = MediaWiki\Session\Token::getTimestamp( $token );
+ $ts = Token::getTimestamp( $token );
if ( $ts !== null ) {
$mwts = new MWTimestamp();
$mwts->timestamp->setTimestamp( $ts );
}
public function getAllowedParams() {
- return array(
- 'type' => array(
+ return [
+ 'type' => [
ApiBase::PARAM_TYPE => array_keys( ApiQueryTokens::getTokenTypeSalts() ),
ApiBase::PARAM_REQUIRED => true,
- ),
- 'token' => array(
+ ],
+ 'token' => [
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
- ),
- 'maxtokenage' => array(
+ ],
+ 'maxtokenage' => [
ApiBase::PARAM_TYPE => 'integer',
- ),
- );
+ ],
+ ];
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=checktoken&type=csrf&token=123ABC'
=> 'apihelp-checktoken-example-simple',
- );
+ ];
}
}