Merge "Use correct fields for LinkBatch on Special:NewPages"
[mediawiki.git] / includes / api / ApiTokens.php
blob4d7fc5a087f265d9b933bbc42401aef14aa0c88d
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
27 /**
28 * @deprecated since 1.24
29 * @ingroup API
31 class ApiTokens extends ApiBase {
33 public function execute() {
34 $this->setWarning(
35 "action=tokens has been deprecated. Please use action=query&meta=tokens instead."
37 $this->logFeatureUsage( "action=tokens" );
39 $params = $this->extractRequestParams();
40 $res = array(
41 ApiResult::META_TYPE => 'assoc',
44 $types = $this->getTokenTypes();
45 foreach ( $params['type'] as $type ) {
46 $val = call_user_func( $types[$type], null, null );
48 if ( $val === false ) {
49 $this->setWarning( "Action '$type' is not allowed for the current user" );
50 } else {
51 $res[$type . 'token'] = $val;
55 $this->getResult()->addValue( null, $this->getModuleName(), $res );
58 private function getTokenTypes() {
59 // If we're in a mode that breaks the same-origin policy, no tokens can
60 // be obtained
61 if ( $this->lacksSameOriginSecurity() ) {
62 return array();
65 static $types = null;
66 if ( $types ) {
67 return $types;
69 $types = array( 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) );
70 $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock',
71 'email', 'import', 'watch', 'options' );
72 foreach ( $names as $name ) {
73 $types[$name] = array( 'ApiQueryInfo', 'get' . ucfirst( $name ) . 'Token' );
75 Hooks::run( 'ApiTokensGetTokenTypes', array( &$types ) );
76 ksort( $types );
78 return $types;
81 public function isDeprecated() {
82 return true;
85 public function getAllowedParams() {
86 return array(
87 'type' => array(
88 ApiBase::PARAM_DFLT => 'edit',
89 ApiBase::PARAM_ISMULTI => true,
90 ApiBase::PARAM_TYPE => array_keys( $this->getTokenTypes() ),
95 protected function getExamplesMessages() {
96 return array(
97 'action=tokens'
98 => 'apihelp-tokens-example-edit',
99 'action=tokens&type=email|move'
100 => 'apihelp-tokens-example-emailmove',