Merge "Drop outdated "documentation reviewed" tags"
[lhc/web/wiklou.git] / includes / api / ApiTokens.php
1 <?php
2 /**
3 *
4 *
5 * Created on Jul 29, 2011
6 *
7 * Copyright © 2011 John Du Hart john@johnduhart.me
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * @deprecated since 1.24
29 * @ingroup API
30 */
31 class ApiTokens extends ApiBase {
32
33 public function execute() {
34 $this->setWarning(
35 "action=tokens has been deprecated. Please use action=query&meta=tokens instead."
36 );
37 $this->logFeatureUsage( "action=tokens" );
38
39 $params = $this->extractRequestParams();
40 $res = array();
41
42 $types = $this->getTokenTypes();
43 foreach ( $params['type'] as $type ) {
44 $val = call_user_func( $types[$type], null, null );
45
46 if ( $val === false ) {
47 $this->setWarning( "Action '$type' is not allowed for the current user" );
48 } else {
49 $res[$type . 'token'] = $val;
50 }
51 }
52
53 $this->getResult()->addValue( null, $this->getModuleName(), $res );
54 }
55
56 private function getTokenTypes() {
57 // If we're in a mode that breaks the same-origin policy, no tokens can
58 // be obtained
59 if ( $this->lacksSameOriginSecurity() ) {
60 return array();
61 }
62
63 static $types = null;
64 if ( $types ) {
65 return $types;
66 }
67 $types = array( 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) );
68 $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock',
69 'email', 'import', 'watch', 'options' );
70 foreach ( $names as $name ) {
71 $types[$name] = array( 'ApiQueryInfo', 'get' . ucfirst( $name ) . 'Token' );
72 }
73 Hooks::run( 'ApiTokensGetTokenTypes', array( &$types ) );
74 ksort( $types );
75
76 return $types;
77 }
78
79 public function isDeprecated() {
80 return true;
81 }
82
83 public function getAllowedParams() {
84 return array(
85 'type' => array(
86 ApiBase::PARAM_DFLT => 'edit',
87 ApiBase::PARAM_ISMULTI => true,
88 ApiBase::PARAM_TYPE => array_keys( $this->getTokenTypes() ),
89 ),
90 );
91 }
92
93 protected function getExamplesMessages() {
94 return array(
95 'action=tokens'
96 => 'apihelp-tokens-example-edit',
97 'action=tokens&type=email|move'
98 => 'apihelp-tokens-example-emailmove',
99 );
100 }
101 }