45 parent::__construct( $main, $format );
47 $this->mIsHtml = ( substr( $format, -2, 2 ) ===
'fm' );
48 if ( $this->mIsHtml ) {
49 $this->mFormat = substr( $format, 0, -2 );
50 $this->mIsWrappedHtml = $this->
getMain()->getCheck(
'wrappedhtml' );
52 $this->mFormat = $format;
54 $this->mFormat = strtoupper( $this->mFormat );
77 return 'api-result-wrapped.json';
79 return 'api-result.html';
82 $ext = $exts ? strtok( $exts,
' ' ) : strtolower( $this->mFormat );
83 return "api-result.$ext";
120 $this->mDisabled =
true;
150 $this->mForceDefaultParams =
true;
159 if ( !$this->mForceDefaultParams ) {
160 return parent::getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
163 if ( !is_array( $paramSettings ) ) {
164 return $paramSettings;
165 } elseif ( isset( $paramSettings[self::PARAM_DFLT] ) ) {
178 if ( $this->mDisabled ) {
183 $this->mHttpStatus =
$code;
185 $this->
getMain()->getRequest()->response()->statusHeader(
$code );
194 if ( $this->mDisabled ) {
199 ?
'text/mediawiki-api-prettyprint-wrapped'
204 if (
$mime ===
null ) {
208 $this->
getMain()->getRequest()->response()->header(
"Content-Type: $mime; charset=utf-8" );
211 $apiFrameOptions = $this->
getConfig()->get(
'ApiFrameOptions' );
212 if ( $apiFrameOptions ) {
213 $this->
getMain()->getRequest()->response()->header(
"X-Frame-Options: $apiFrameOptions" );
219 $this->
getMain()->getRequest()->response()->header(
220 "Content-Disposition: inline; filename=\"{$filename}\""
228 if ( $this->mDisabled ) {
235 $lcformat = strtolower( $format );
239 $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin(
'apioutput' ) );
244 $out->addModuleStyles(
'mediawiki.apipretty' );
251 $nonHtmlUrl = strtok( $this->
getRequest()->getFullRequestURL(),
'?' )
252 .
'?' . $this->
getRequest()->appendQueryValue(
'format', $lcformat );
253 $msg =
$context->
msg(
'api-format-prettyprint-header-hyperlinked' )
254 ->params( $format, $lcformat, $nonHtmlUrl );
256 $msg =
$context->
msg(
'api-format-prettyprint-header' )->params( $format, $lcformat );
259 $msg =
$context->
msg(
'api-format-prettyprint-header-only-html' )->params( $format );
262 $header = $msg->parseAsBlock();
264 Html::rawElement(
'div', [
'class' =>
'api-pretty-header' ],
269 if ( $this->mHttpStatus && $this->mHttpStatus !== 200 ) {
271 Html::rawElement(
'div', [
'class' =>
'api-pretty-header api-pretty-status' ],
273 'api-format-prettyprint-status',
282 if ( Hooks::run(
'ApiFormatHighlight', [
$context, $result,
$mime, $format ] ) ) {
284 Html::element(
'pre', [
'class' =>
'api-pretty-content' ], $result )
290 $time = microtime(
true ) - $this->
getConfig()->get(
'RequestTime' );
291 $json = FormatJson::encode(
293 'status' => (
int)( $this->mHttpStatus ?: 200 ),
295 'html' =>
$out->getHTML(),
296 'modules' => array_values( array_unique( array_merge(
298 $out->getModuleScripts(),
299 $out->getModuleStyles()
301 'continue' => $this->
getResult()->getResultData(
'continue' ),
302 'time' => round(
$time * 1000 ),
304 false, FormatJson::ALL_OK
310 if ( preg_match(
'/<\s*cross-domain-policy\s*>/i', $json ) ) {
311 $json = preg_replace(
312 '/<(\s*cross-domain-policy\s*)>/i',
'\\u003C$1\\u003E', $json
320 $out->allowClickjacking();
337 $this->mBuffer .= $text;
351 $ret[
'wrappedhtml'] = [
362 'action=query&meta=siteinfo&siprop=namespaces&format=' . $this->
getModuleName()
363 => [
'apihelp-format-example-generic', $this->
getFormat() ]
368 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()
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
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.
static singleton()
Get an instance of this class.
This class should be covered by a general architecture document which does not exist as of January 20...
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,...
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