41 parent::__construct( $main, $format );
43 $this->mIsHtml = ( substr( $format, -2, 2 ) ===
'fm' );
44 if ( $this->mIsHtml ) {
45 $this->mFormat = substr( $format, 0, -2 );
46 $this->mIsWrappedHtml = $this->
getMain()->getCheck(
'wrappedhtml' );
48 $this->mFormat = $format;
50 $this->mFormat = strtoupper( $this->mFormat );
72 return 'api-result-wrapped.json';
74 return 'api-result.html';
76 $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()
78 $ext = $exts ? strtok( $exts,
' ' ) : strtolower( $this->mFormat );
79 return "api-result.$ext";
116 $this->mDisabled =
true;
146 $this->mForceDefaultParams =
true;
155 if ( !$this->mForceDefaultParams ) {
156 return parent::getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
159 if ( !is_array( $paramSettings ) ) {
160 return $paramSettings;
161 } elseif ( isset( $paramSettings[self::PARAM_DFLT] ) ) {
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 );
227 '%21' =>
'!',
'%23' =>
'#',
'%24' =>
'$',
'%26' =>
'&',
'%2B' =>
'+',
'%5E' =>
'^',
228 '%60' =>
'`',
'%7C' =>
'|',
239 if ( $this->mDisabled ) {
246 $lcformat = strtolower( $format );
250 $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin(
'apioutput' ) );
251 $context->setTitle( SpecialPage::getTitleFor(
'ApiHelp' ) );
255 $out->addModuleStyles(
'mediawiki.apipretty' );
262 $nonHtmlUrl = strtok( $this->
getRequest()->getFullRequestURL(),
'?' )
263 .
'?' . $this->
getRequest()->appendQueryValue(
'format', $lcformat );
264 $msg =
$context->
msg(
'api-format-prettyprint-header-hyperlinked' )
265 ->params( $format, $lcformat, $nonHtmlUrl );
267 $msg =
$context->
msg(
'api-format-prettyprint-header' )->params( $format, $lcformat );
270 $msg =
$context->
msg(
'api-format-prettyprint-header-only-html' )->params( $format );
273 $header = $msg->parseAsBlock();
275 Html::rawElement(
'div', [
'class' =>
'api-pretty-header' ],
280 if ( $this->mHttpStatus && $this->mHttpStatus !== 200 ) {
282 Html::rawElement(
'div', [
'class' =>
'api-pretty-header api-pretty-status' ],
284 'api-format-prettyprint-status',
293 if ( Hooks::run(
'ApiFormatHighlight', [
$context, $result,
$mime, $format ] ) ) {
295 Html::element(
'pre', [
'class' =>
'api-pretty-content' ], $result )
301 $time = $this->
getMain()->getRequest()->getElapsedTime();
302 $json = FormatJson::encode(
304 'status' => (
int)( $this->mHttpStatus ?: 200 ),
306 'html' =>
$out->getHTML(),
307 'modules' => array_values( array_unique( array_merge(
309 $out->getModuleScripts(),
310 $out->getModuleStyles()
312 'continue' => $this->
getResult()->getResultData(
'continue' ),
313 'time' => round(
$time * 1000 ),
315 false, FormatJson::ALL_OK
321 if ( preg_match(
'/<\s*cross-domain-policy\s*>/i', $json ) ) {
322 $json = preg_replace(
323 '/<(\s*cross-domain-policy\s*)>/i',
'\\u003C$1\\u003E', $json
331 $out->allowClickjacking();
348 $this->mBuffer .= $text;
362 $ret[
'wrappedhtml'] = [
373 'action=query&meta=siteinfo&siprop=namespaces&format=' . $this->
getModuleName()
374 => [
'apihelp-format-example-generic', $this->
getFormat() ]
379 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Data_formats';
This abstract class implements many basic API functions, and is the base of all API classes.
getModuleManager()
Get the module manager, or null if this module has no sub-modules.
getMain()
Get the main module.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getResult()
Get the result object.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
getModuleName()
Get the name of the module being executed by this instance.
static fixHelpLinks( $html, $helptitle=null, $localModules=[])
Replace Special:ApiHelp links with links to api.php.
This is the main API class, used for both external and internal processing.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
An IContextSource implementation which will inherit context from another source but allow individual ...
static getMessage( $code)
Get the message associated with an HTTP response status code.
This class should be covered by a general architecture document which does not exist as of January 20...
see documentation in includes Linker php for Linker::makeImageLink & $time
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
msg( $key)
This is the method for getting translated interface messages.
if( $ext=='php'|| $ext=='php5') $mime
if(!is_readable( $file)) $ext