[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * 5 * Created on Jul 29, 2011 6 * 7 * Copyright © 2011 John Du Hart [email protected] 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 38 $params = $this->extractRequestParams(); 39 $res = array(); 40 41 $types = $this->getTokenTypes(); 42 foreach ( $params['type'] as $type ) { 43 $val = call_user_func( $types[$type], null, null ); 44 45 if ( $val === false ) { 46 $this->setWarning( "Action '$type' is not allowed for the current user" ); 47 } else { 48 $res[$type . 'token'] = $val; 49 } 50 } 51 52 $this->getResult()->addValue( null, $this->getModuleName(), $res ); 53 } 54 55 private function getTokenTypes() { 56 // If we're in JSON callback mode, no tokens can be obtained 57 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) { 58 return array(); 59 } 60 61 static $types = null; 62 if ( $types ) { 63 return $types; 64 } 65 wfProfileIn( __METHOD__ ); 66 $types = array( 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) ); 67 $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock', 68 'email', 'import', 'watch', 'options' ); 69 foreach ( $names as $name ) { 70 $types[$name] = array( 'ApiQueryInfo', 'get' . ucfirst( $name ) . 'Token' ); 71 } 72 wfRunHooks( 'ApiTokensGetTokenTypes', array( &$types ) ); 73 ksort( $types ); 74 wfProfileOut( __METHOD__ ); 75 76 return $types; 77 } 78 79 public function getAllowedParams() { 80 return array( 81 'type' => array( 82 ApiBase::PARAM_DFLT => 'edit', 83 ApiBase::PARAM_ISMULTI => true, 84 ApiBase::PARAM_TYPE => array_keys( $this->getTokenTypes() ), 85 ), 86 ); 87 } 88 89 public function getParamDescription() { 90 return array( 91 'type' => 'Type of token(s) to request' 92 ); 93 } 94 95 public function getDescription() { 96 return array( 97 'This module is deprecated in favor of action=query&meta=tokens.', 98 'Gets tokens for data-modifying actions.' 99 ); 100 } 101 102 protected function getExamples() { 103 return array( 104 'api.php?action=tokens' => 'Retrieve an edit token (the default)', 105 'api.php?action=tokens&type=email|move' => 'Retrieve an email token and a move token' 106 ); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |