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;
72 return 'api-result-wrapped.json';
74 return 'api-result.html';
76 $exts = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer()
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 ) ) {
172 if ( $this->mDisabled ) {
177 $this->mHttpStatus =
$code;
179 $this->
getMain()->getRequest()->response()->statusHeader(
$code );
188 if ( $this->mDisabled ) {
193 ?
'text/mediawiki-api-prettyprint-wrapped'
198 if ( $mime ===
null ) {
202 $this->
getMain()->getRequest()->response()->header(
"Content-Type: $mime; charset=utf-8" );
205 $apiFrameOptions = $this->
getConfig()->get(
'ApiFrameOptions' );
206 if ( $apiFrameOptions ) {
207 $this->
getMain()->getRequest()->response()->header(
"X-Frame-Options: $apiFrameOptions" );
212 $header =
'Content-Disposition: inline';
215 if (
preg_match(
'/^[0-9a-zA-Z!#$%&\'*+\-.^_`|~]+$/', $compatFilename ) ) {
219 .
preg_replace(
'/([\0-\x1f"\x5c\x7f])/',
'\\\\$1', $compatFilename ) .
'"';
221 if ( $compatFilename !== $filename ) {
225 '%21' =>
'!',
'%23' =>
'#',
'%24' =>
'$',
'%26' =>
'&',
'%2B' =>
'+',
'%5E' =>
'^',
226 '%60' =>
'`',
'%7C' =>
'|',
237 if ( $this->mDisabled ) {
242 if ( $this->
getIsHtml() && $mime !==
null ) {
248 $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin(
'apioutput' ) );
249 $context->setTitle( SpecialPage::getTitleFor(
'ApiHelp' ) );
253 $out->setRobotPolicy(
'noindex,nofollow' );
254 $out->addModuleStyles(
'mediawiki.apipretty' );
262 .
'?' . $this->
getRequest()->appendQueryValue(
'format', $lcformat );
263 $msg =
$context->
msg(
'api-format-prettyprint-header-hyperlinked' )
264 ->params( $format, $lcformat, $nonHtmlUrl );
266 $msg =
$context->
msg(
'api-format-prettyprint-header' )->params( $format, $lcformat );
269 $msg =
$context->
msg(
'api-format-prettyprint-header-only-html' )->params( $format );
272 $header = $msg->parseAsBlock();
274 Html::rawElement(
'div', [
'class' =>
'api-pretty-header' ],
279 if ( $this->mHttpStatus && $this->mHttpStatus !== 200 ) {
281 Html::rawElement(
'div', [
'class' =>
'api-pretty-header api-pretty-status' ],
283 'api-format-prettyprint-status',
292 if ( Hooks::run(
'ApiFormatHighlight', [
$context, $result, $mime, $format ] ) ) {
294 Html::element(
'pre', [
'class' =>
'api-pretty-content' ], $result )
300 $time = $this->
getMain()->getRequest()->getElapsedTime();
301 $json = FormatJson::encode(
303 'status' => (
int)( $this->mHttpStatus ?: 200 ),
305 'html' =>
$out->getHTML(),
308 $out->getModuleStyles()
310 'continue' => $this->
getResult()->getResultData(
'continue' ),
313 false, FormatJson::ALL_OK
319 if (
preg_match(
'/<\s*cross-domain-policy\s*>/i', $json ) ) {
321 '/<(\s*cross-domain-policy\s*)>/i',
'\\u003C$1\\u003E', $json
329 $out->allowClickjacking();
346 $this->mBuffer .= $text;
360 $ret[
'wrappedhtml'] = [
371 'action=query&meta=siteinfo&siprop=namespaces&format=' . $this->
getModuleName()
372 => [
'apihelp-format-example-generic', $this->
getFormat() ]
377 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Data_formats';
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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 When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
msg( $key)
This is the method for getting translated interface messages.
if(!is_readable( $file)) $ext