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';
60 $opt |= FormatJson::ALL_OK;
63 switch (
$params[
'formatversion'] ) {
65 $opt |=
$params[
'utf8'] ? FormatJson::ALL_OK : FormatJson::XMLMETA_OK;
68 'Types' => [
'AssocAsObject' =>
true ],
75 $opt |=
$params[
'ascii'] ? FormatJson::XMLMETA_OK : FormatJson::ALL_OK;
77 'Types' => [
'AssocAsObject' =>
true ],
84 $this->
dieDebug( __METHOD__,
'Unknown value for \'formatversion\'' );
87 $data = $this->
getResult()->getResultData(
null, $transform );
88 $json = FormatJson::encode( $data, $this->
getIsHtml(),
$opt );
93 if ( preg_match(
'/<\s*cross-domain-policy(?=\s|>)/i', $json ) ) {
95 '/<(\s*cross-domain-policy(?=\s|>))/i',
'\\u003C$1', $json
99 if ( isset(
$params[
'callback'] ) ) {
100 $callback = preg_replace(
"/[^][.\\'\\\"_A-Za-z0-9]/",
'',
$params[
'callback'] );
101 # Prepend a comment to try to avoid attacks against content
102 # sniffers, such as T70187.
103 $this->
printText(
"/**/$callback($json)" );
110 if ( $this->isRaw ) {
111 return parent::getAllowedParams();
114 $ret = parent::getAllowedParams() + [
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getResult()
Get the result object.
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.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret