Go to the documentation of this file.
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' ) );
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();
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';
This is the main API class, used for both external and internal processing.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
This abstract class implements many basic API functions, and is the base of all API classes.
An IContextSource implementation which will inherit context from another source but allow individual ...
msg( $key,... $params)
This is the method for getting translated interface messages.
This is one of the Core classes and should be read at least once by any new developers.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static fixHelpLinks( $html, $helptitle=null, $localModules=[])
Replace Special:ApiHelp links with links to api.php.
static getMessage( $code)
Get the message associated with an HTTP response status code.
getModuleManager()
Get the module manager, or null if this module has no sub-modules.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
getModuleName()
Get the name of the module being executed by this instance.
getMain()
Get the main module.
if(!is_readable( $file)) $ext
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.