32 parent::__construct( $main, $format );
33 $this->isRaw = ( $format ===
'rawfm' );
35 if ( $this->
getMain()->getCheck(
'callback' ) ) {
36 # T94015: jQuery appends a useless '_' parameter in jsonp mode.
37 # Mark the parameter as used in that case to avoid a warning that's
38 # outside the control of the end user.
39 # (and do it here because ApiMain::reportUnusedParams() gets called
40 # before our ::execute())
41 $this->
getMain()->markParamsUsed(
'_' );
48 if ( isset( $params[
'callback'] ) ) {
49 return 'text/javascript';
52 return 'application/json';
63 switch ( $params[
'formatversion'] ) {
68 'Types' => [
'AssocAsObject' =>
true ],
77 'Types' => [
'AssocAsObject' =>
true ],
85 $this->
dieDebug( __METHOD__,
'Unknown value for \'formatversion\'' );
89 $data = $this->
getResult()->getResultData(
null, $transform );
91 if ( $json ===
false ) {
95 $this->
dieDebug( __METHOD__,
'Unable to encode API result as JSON' );
102 if ( preg_match(
'/<\s*cross-domain-policy(?=\s|>)/i', $json ) ) {
103 $json = preg_replace(
104 '/<(\s*cross-domain-policy(?=\s|>))/i',
'\\u003C$1', $json
108 if ( isset( $params[
'callback'] ) ) {
109 $callback = preg_replace(
"/[^][.\\'\\\"_A-Za-z0-9]/",
'', $params[
'callback'] );
110 # Prepend a comment to try to avoid attacks against content
111 # sniffers, such as T70187.
112 $this->
printText(
"/**/$callback($json)" );
119 if ( $this->isRaw ) {
120 return parent::getAllowedParams();
123 return parent::getAllowedParams() + [
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, this is an array mapping those values to $msg...
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.