43 parent::__construct( $main, $format );
45 $this->mIsHtml = ( substr( $format, -2, 2 ) ===
'fm' );
46 if ( $this->mIsHtml ) {
47 $this->mFormat = substr( $format, 0, -2 );
48 $this->mIsWrappedHtml = $this->
getMain()->getCheck(
'wrappedhtml' );
50 $this->mFormat = $format;
52 $this->mFormat = strtoupper( $this->mFormat );
74 return 'api-result-wrapped.json';
76 return 'api-result.html';
78 $exts = MediaWikiServices::getInstance()->getMimeAnalyzer()
80 $ext = $exts ? strtok( $exts,
' ' ) : strtolower( $this->mFormat );
81 return "api-result.$ext";
118 $this->mDisabled =
true;
148 $this->mForceDefaultParams =
true;
157 if ( !$this->mForceDefaultParams ) {
158 return parent::getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
161 if ( !is_array( $paramSettings ) ) {
162 return $paramSettings;
174 if ( $this->mDisabled ) {
179 $this->mHttpStatus = $code;
181 $this->
getMain()->getRequest()->response()->statusHeader( $code );
190 if ( $this->mDisabled ) {
195 ?
'text/mediawiki-api-prettyprint-wrapped'
200 if ( $mime ===
null ) {
204 $this->
getMain()->getRequest()->response()->header(
"Content-Type: $mime; charset=utf-8" );
207 $apiFrameOptions = $this->
getConfig()->get(
'ApiFrameOptions' );
208 if ( $apiFrameOptions ) {
209 $this->
getMain()->getRequest()->response()->header(
"X-Frame-Options: $apiFrameOptions" );
214 $header =
'Content-Disposition: inline';
216 $compatFilename = mb_convert_encoding( $filename,
'ISO-8859-1' );
217 if ( preg_match(
'/^[0-9a-zA-Z!#$%&\'*+\-.^_`|~]+$/', $compatFilename ) ) {
218 $header .=
'; filename=' . $compatFilename;
221 . preg_replace(
'/([\0-\x1f"\x5c\x7f])/',
'\\\\$1', $compatFilename ) .
'"';
223 if ( $compatFilename !== $filename ) {
224 $value =
"UTF-8''" . rawurlencode( $filename );
226 $value = strtr( $value, [
227 '%21' =>
'!',
'%23' =>
'#',
'%24' =>
'$',
'%26' =>
'&',
'%2B' =>
'+',
'%5E' =>
'^',
228 '%60' =>
'`',
'%7C' =>
'|',
230 $header .=
'; filename*=' . $value;
239 if ( $this->mDisabled ) {
244 if ( $this->
getIsHtml() && $mime !==
null ) {
246 $lcformat = strtolower( $format );
250 $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
251 $context->setSkin( $skinFactory->makeSkin(
'apioutput' ) );
256 $out->setRobotPolicy(
'noindex,nofollow' );
257 $out->addModuleStyles(
'mediawiki.apipretty' );
258 $out->setPageTitle(
$context->
msg(
'api-format-title' ) );
262 if ( $this->
getMain()->getModuleManager()->isDefined( $lcformat,
'format' ) ) {
264 $nonHtmlUrl = strtok( $this->
getRequest()->getFullRequestURL(),
'?' )
265 .
'?' . $this->
getRequest()->appendQueryValue(
'format', $lcformat );
266 $msg =
$context->
msg(
'api-format-prettyprint-header-hyperlinked' )
267 ->params( $format, $lcformat, $nonHtmlUrl );
269 $msg =
$context->
msg(
'api-format-prettyprint-header' )->params( $format, $lcformat );
272 $msg =
$context->
msg(
'api-format-prettyprint-header-only-html' )->params( $format );
275 $header = $msg->parseAsBlock();
277 Html::rawElement(
'div', [
'class' =>
'api-pretty-header' ],
282 if ( $this->mHttpStatus && $this->mHttpStatus !== 200 ) {
284 Html::rawElement(
'div', [
'class' =>
'api-pretty-header api-pretty-status' ],
286 'api-format-prettyprint-status',
297 Html::element(
'pre', [
'class' =>
'api-pretty-content' ], $result )
303 $time = $this->
getMain()->getRequest()->getElapsedTime();
306 'status' => (
int)( $this->mHttpStatus ?: 200 ),
308 'html' => $out->getHTML(),
309 'modules' => array_values( array_unique( array_merge(
311 $out->getModuleStyles()
313 'continue' => $this->
getResult()->getResultData(
'continue' ),
314 'time' => round( $time * 1000 ),
322 if ( preg_match(
'/<\s*cross-domain-policy\s*>/i', $json ) ) {
323 $json = preg_replace(
324 '/<(\s*cross-domain-policy\s*)>/i',
'\\u003C$1\\u003E', $json
332 $out->allowClickjacking();
349 $this->mBuffer .= $text;
363 $ret[
'wrappedhtml'] = [
374 'action=query&meta=siteinfo&siprop=namespaces&format=' . $this->
getModuleName()
375 => [
'apihelp-format-example-generic', $this->
getFormat() ]
380 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Data_formats';