MediaWiki  1.23.8
ApiTokens.php
Go to the documentation of this file.
1 <?php
30 class ApiTokens extends ApiBase {
31 
32  public function execute() {
33  $params = $this->extractRequestParams();
34  $res = array();
35 
36  $types = $this->getTokenTypes();
37  foreach ( $params['type'] as $type ) {
38  $val = call_user_func( $types[$type], null, null );
39 
40  if ( $val === false ) {
41  $this->setWarning( "Action '$type' is not allowed for the current user" );
42  } else {
43  $res[$type . 'token'] = $val;
44  }
45  }
46 
47  $this->getResult()->addValue( null, $this->getModuleName(), $res );
48  }
49 
50  private function getTokenTypes() {
51  // If we're in JSON callback mode, no tokens can be obtained
52  if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
53  return array();
54  }
55 
56  static $types = null;
57  if ( $types ) {
58  return $types;
59  }
60  wfProfileIn( __METHOD__ );
61  $types = array( 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) );
62  $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock',
63  'email', 'import', 'watch', 'options' );
64  foreach ( $names as $name ) {
65  $types[$name] = array( 'ApiQueryInfo', 'get' . ucfirst( $name ) . 'Token' );
66  }
67  wfRunHooks( 'ApiTokensGetTokenTypes', array( &$types ) );
68  ksort( $types );
69  wfProfileOut( __METHOD__ );
70 
71  return $types;
72  }
73 
74  public function getAllowedParams() {
75  return array(
76  'type' => array(
77  ApiBase::PARAM_DFLT => 'edit',
78  ApiBase::PARAM_ISMULTI => true,
79  ApiBase::PARAM_TYPE => array_keys( $this->getTokenTypes() ),
80  ),
81  );
82  }
83 
84  public function getResultProperties() {
85  $props = array(
86  '' => array(),
87  );
88 
89  self::addTokenProperties( $props, $this->getTokenTypes() );
90 
91  return $props;
92  }
93 
94  public function getParamDescription() {
95  return array(
96  'type' => 'Type of token(s) to request'
97  );
98  }
99 
100  public function getDescription() {
101  return 'Gets tokens for data-modifying actions.';
102  }
103 
104  protected function getExamples() {
105  return array(
106  'api.php?action=tokens' => 'Retrieve an edit token (the default)',
107  'api.php?action=tokens&type=email|move' => 'Retrieve an email token and a move token'
108  );
109  }
110 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiTokens\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiTokens.php:104
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
ApiTokens\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiTokens.php:94
ApiTokens\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiTokens.php:84
$params
$params
Definition: styleTest.css.php:40
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:77
ApiTokens\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiTokens.php:32
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiTokens\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiTokens.php:74
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiTokens\getTokenTypes
getTokenTypes()
Definition: ApiTokens.php:50
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
ApiBase\addTokenProperties
static addTokenProperties(&$props, $tokenFunctions)
Add token properties to the array used by getResultProperties, based on a token functions mapping.
Definition: ApiBase.php:646
ApiBase\setWarning
setWarning( $warning)
Set warning section for this module.
Definition: ApiBase.php:245
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiTokens
Definition: ApiTokens.php:30
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:188
$res
$res
Definition: database.txt:21
$type
$type
Definition: testCompression.php:46
ApiTokens\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiTokens.php:100