From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- includes/api/ApiCheckToken.php | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 includes/api/ApiCheckToken.php (limited to 'includes/api/ApiCheckToken.php') diff --git a/includes/api/ApiCheckToken.php b/includes/api/ApiCheckToken.php new file mode 100644 index 00000000..28c6ece7 --- /dev/null +++ b/includes/api/ApiCheckToken.php @@ -0,0 +1,81 @@ +extractRequestParams(); + $token = $params['token']; + $maxage = $params['maxtokenage']; + $request = $this->getRequest(); + $salts = ApiQueryTokens::getTokenTypeSalts(); + $salt = $salts[$params['type']]; + + $res = array(); + + if ( $this->getUser()->matchEditToken( $token, $salt, $request, $maxage ) ) { + $res['result'] = 'valid'; + } elseif ( $maxage !== null && $this->getUser()->matchEditToken( $token, $salt, $request ) ) { + $res['result'] = 'expired'; + } else { + $res['result'] = 'invalid'; + } + + $ts = User::getEditTokenTimestamp( $token ); + if ( $ts !== null ) { + $mwts = new MWTimestamp(); + $mwts->timestamp->setTimestamp( $ts ); + $res['generated'] = $mwts->getTimestamp( TS_ISO_8601 ); + } + + $this->getResult()->addValue( null, $this->getModuleName(), $res ); + } + + public function getAllowedParams() { + return array( + 'type' => array( + ApiBase::PARAM_TYPE => array_keys( ApiQueryTokens::getTokenTypeSalts() ), + ApiBase::PARAM_REQUIRED => true, + ), + 'token' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => true, + ), + 'maxtokenage' => array( + ApiBase::PARAM_TYPE => 'integer', + ), + ); + } + + protected function getExamplesMessages() { + return array( + 'action=checktoken&type=csrf&token=123ABC' + => 'apihelp-checktoken-example-simple', + ); + } +} -- cgit v1.2.3-54-g00ecf