Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / api / ApiTokens.php
blob79640953e9a80d0c5346f0a4047ce1815a3333bb
1 <?php
2 /**
5 * Created on Jul 29, 2011
7 * Copyright © 2011 John Du Hart john@johnduhart.me
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
28 /**
29 * @ingroup API
31 class ApiTokens extends ApiBase {
33 public function __construct( $main, $action ) {
34 parent::__construct( $main, $action );
37 public function execute() {
38 $params = $this->extractRequestParams();
39 $res = array();
41 foreach ( $params['type'] as $type ) {
42 $type = strtolower( $type );
43 $func = 'get' .
44 ucfirst( $type ) .
45 'Token';
46 if ( $type === 'patrol' ) {
47 $val = call_user_func( array( 'ApiQueryRecentChanges', $func ), null, null );
48 } else {
49 $val = call_user_func( array( 'ApiQueryInfo', $func ), null, null );
51 if ( $val === false ) {
52 $this->setWarning( "Action '$type' is not allowed for the current user" );
53 } else {
54 $res[$type . 'token'] = $val;
58 $this->getResult()->addValue( null, $this->getModuleName(), $res );
61 public function getAllowedParams() {
62 return array(
63 'type' => array(
64 ApiBase::PARAM_DFLT => 'edit',
65 ApiBase::PARAM_ISMULTI => true,
66 ApiBase::PARAM_TYPE => array(
67 'edit', 'delete', 'protect', 'move', 'block', 'unblock',
68 'email', 'import', 'watch', 'patrol'
74 public function getParamDescription() {
75 return array(
76 'type' => 'Type of token(s) to request'
80 public function getDescription() {
81 return 'Gets tokens for data-modifying actions';
84 protected function getExamples() {
85 return array(
86 'api.php?action=tokens' => 'Retrieve an edit token (the default)',
87 'api.php?action=tokens&type=email|move' => 'Retrieve an email token and a move token'
91 public function getVersion() {
92 return __CLASS__ . ': $Id$';