wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / api / ApiQueryTokens.php
blobf88766461b3d5c9a067107aa643e323021d07645
1 <?php
2 /**
3 * Module to fetch tokens via action=query&meta=tokens
5 * Created on August 8, 2014
7 * Copyright © 2014 Brad Jorsch bjorsch@wikimedia.org
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
25 * @since 1.24
28 /**
29 * Module to fetch tokens via action=query&meta=tokens
31 * @ingroup API
32 * @since 1.24
34 class ApiQueryTokens extends ApiQueryBase {
36 public function execute() {
37 $params = $this->extractRequestParams();
38 $res = array(
39 ApiResult::META_TYPE => 'assoc',
42 if ( $this->lacksSameOriginSecurity() ) {
43 $this->setWarning( 'Tokens may not be obtained when the same-origin policy is not applied' );
44 return;
47 $salts = self::getTokenTypeSalts();
48 foreach ( $params['type'] as $type ) {
49 $salt = $salts[$type];
50 $val = $this->getUser()->getEditToken( $salt, $this->getRequest() );
51 $res[$type . 'token'] = $val;
54 $this->getResult()->addValue( 'query', $this->getModuleName(), $res );
57 public static function getTokenTypeSalts() {
58 static $salts = null;
59 if ( !$salts ) {
60 $salts = array(
61 'csrf' => '',
62 'watch' => 'watch',
63 'patrol' => 'patrol',
64 'rollback' => 'rollback',
65 'userrights' => 'userrights',
67 Hooks::run( 'ApiQueryTokensRegisterTypes', array( &$salts ) );
68 ksort( $salts );
71 return $salts;
74 public function getAllowedParams() {
75 return array(
76 'type' => array(
77 ApiBase::PARAM_DFLT => 'csrf',
78 ApiBase::PARAM_ISMULTI => true,
79 ApiBase::PARAM_TYPE => array_keys( self::getTokenTypeSalts() ),
84 protected function getExamplesMessages() {
85 return array(
86 'action=query&meta=tokens'
87 => 'apihelp-query+tokens-example-simple',
88 'action=query&meta=tokens&type=watch|patrol'
89 => 'apihelp-query+tokens-example-types',
93 public function getCacheMode( $params ) {
94 return 'private';
97 public function getHelpUrls() {
98 return 'https://www.mediawiki.org/wiki/API:Tokens';