X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiCheckToken.php;h=3d2159cf50b36bf0c6cf60d7080c73c390ea7f3e;hb=c57fe1c4a890b360fbf88035c601a1e46130d60a;hp=28c6ece7c09aca93a99a71ab9221503c3d0a2fc3;hpb=a756c3b753e34a479da69a88a3176fd2d3e7cfa2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiCheckToken.php b/includes/api/ApiCheckToken.php index 28c6ece7c0..3d2159cf50 100644 --- a/includes/api/ApiCheckToken.php +++ b/includes/api/ApiCheckToken.php @@ -32,21 +32,22 @@ class ApiCheckToken extends ApiBase { $params = $this->extractRequestParams(); $token = $params['token']; $maxage = $params['maxtokenage']; - $request = $this->getRequest(); $salts = ApiQueryTokens::getTokenTypeSalts(); - $salt = $salts[$params['type']]; - $res = array(); + $res = []; - if ( $this->getUser()->matchEditToken( $token, $salt, $request, $maxage ) ) { + $tokenObj = ApiQueryTokens::getToken( + $this->getUser(), $this->getRequest()->getSession(), $salts[$params['type']] + ); + if ( $tokenObj->match( $token, $maxage ) ) { $res['result'] = 'valid'; - } elseif ( $maxage !== null && $this->getUser()->matchEditToken( $token, $salt, $request ) ) { + } elseif ( $maxage !== null && $tokenObj->match( $token ) ) { $res['result'] = 'expired'; } else { $res['result'] = 'invalid'; } - $ts = User::getEditTokenTimestamp( $token ); + $ts = MediaWiki\Session\Token::getTimestamp( $token ); if ( $ts !== null ) { $mwts = new MWTimestamp(); $mwts->timestamp->setTimestamp( $ts ); @@ -57,25 +58,25 @@ class ApiCheckToken extends ApiBase { } 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', - ); + ]; } }