Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / api / ApiCheckToken.php
blob3d2159cf50b36bf0c6cf60d7080c73c390ea7f3e
1 <?php
2 /**
3 * Created on Jan 29, 2015
5 * Copyright © 2015 Brad Jorsch bjorsch@wikimedia.org
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
25 /**
26 * @since 1.25
27 * @ingroup API
29 class ApiCheckToken extends ApiBase {
31 public function execute() {
32 $params = $this->extractRequestParams();
33 $token = $params['token'];
34 $maxage = $params['maxtokenage'];
35 $salts = ApiQueryTokens::getTokenTypeSalts();
37 $res = [];
39 $tokenObj = ApiQueryTokens::getToken(
40 $this->getUser(), $this->getRequest()->getSession(), $salts[$params['type']]
42 if ( $tokenObj->match( $token, $maxage ) ) {
43 $res['result'] = 'valid';
44 } elseif ( $maxage !== null && $tokenObj->match( $token ) ) {
45 $res['result'] = 'expired';
46 } else {
47 $res['result'] = 'invalid';
50 $ts = MediaWiki\Session\Token::getTimestamp( $token );
51 if ( $ts !== null ) {
52 $mwts = new MWTimestamp();
53 $mwts->timestamp->setTimestamp( $ts );
54 $res['generated'] = $mwts->getTimestamp( TS_ISO_8601 );
57 $this->getResult()->addValue( null, $this->getModuleName(), $res );
60 public function getAllowedParams() {
61 return [
62 'type' => [
63 ApiBase::PARAM_TYPE => array_keys( ApiQueryTokens::getTokenTypeSalts() ),
64 ApiBase::PARAM_REQUIRED => true,
66 'token' => [
67 ApiBase::PARAM_TYPE => 'string',
68 ApiBase::PARAM_REQUIRED => true,
70 'maxtokenage' => [
71 ApiBase::PARAM_TYPE => 'integer',
76 protected function getExamplesMessages() {
77 return [
78 'action=checktoken&type=csrf&token=123ABC'
79 => 'apihelp-checktoken-example-simple',