34 parent::__construct( $main, $format );
35 $this->isRaw = ( $format ===
'rawfm' );
37 if ( $this->
getMain()->getCheck(
'callback' ) ) {
38 # T94015: jQuery appends a useless '_' parameter in jsonp mode.
39 # Mark the parameter as used in that case to avoid a warning that's
40 # outside the control of the end user.
41 # (and do it here because ApiMain::reportUnusedParams() gets called
42 # before our ::execute())
43 $this->
getMain()->markParamsUsed(
'_' );
50 if ( isset( $params[
'callback'] ) ) {
51 return 'text/javascript';
54 return 'application/json';
65 switch ( $params[
'formatversion'] ) {
70 'Types' => [
'AssocAsObject' =>
true ],
79 'Types' => [
'AssocAsObject' =>
true ],
87 self::dieDebug( __METHOD__,
'Unknown value for \'formatversion\'' );
91 $data = $this->
getResult()->getResultData(
null, $transform );
93 if ( $json ===
false ) {
97 self::dieDebug( __METHOD__,
'Unable to encode API result as JSON' );
101 if ( isset( $params[
'callback'] ) ) {
102 $callback = preg_replace(
"/[^][.\\'\\\"_A-Za-z0-9]/",
'', $params[
'callback'] );
103 # Prepend a comment to try to avoid attacks against content
104 # sniffers, such as T70187.
105 $this->
printText(
"/**/$callback($json)" );
112 if ( $this->isRaw ) {
113 return parent::getAllowedParams();
116 return parent::getAllowedParams() + [
121 ParamValidator::PARAM_DEFAULT =>
false,
125 ParamValidator::PARAM_DEFAULT =>
false,
129 ParamValidator::PARAM_TYPE => [
'1',
'2',
'latest' ],
130 ParamValidator::PARAM_DEFAULT =>
'1',
133 '1' =>
'apihelp-json-paramvalue-formatversion-1',
134 '2' =>
'apihelp-json-paramvalue-formatversion-2',
135 'latest' =>
'apihelp-json-paramvalue-formatversion-latest',
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
getMain()
Get the main module.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
This is the main API class, used for both external and internal processing.