MediaWiki master
ApiFormatPhp.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Api;
10
12
18
20 public function getMimeType() {
21 return 'application/vnd.php.serialized';
22 }
23
24 public function execute() {
25 $params = $this->extractRequestParams();
26 $transforms = match ( $params['formatversion'] ) {
27 '1' => [
28 'BC' => [],
29 'Types' => [],
30 'Strip' => 'all',
31 ],
32 '2', 'latest' => [
33 'Types' => [],
34 'Strip' => 'all',
35 ],
36 // Should have been caught during parameter validation
37 // @phan-suppress-next-line PhanUseReturnValueOfNever
38 default => self::dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' )
39 };
40 $this->printText( serialize( $this->getResult()->getResultData( null, $transforms ) ) );
41 }
42
44 public function getAllowedParams() {
45 return parent::getAllowedParams() + [
46 'formatversion' => [
47 ParamValidator::PARAM_TYPE => [ '1', '2', 'latest' ],
48 ParamValidator::PARAM_DEFAULT => '1',
49 ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
51 '1' => 'apihelp-php-paramvalue-formatversion-1',
52 '2' => 'apihelp-php-paramvalue-formatversion-2',
53 'latest' => 'apihelp-php-paramvalue-formatversion-latest',
54 ],
55 ],
56 ];
57 }
58}
59
61class_alias( ApiFormatPhp::class, 'ApiFormatPhp' );
getResult()
Get the result object.
Definition ApiBase.php:682
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:207
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1748
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:167
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:823
This is the abstract base class for API formatters.
printText( $text)
Append text to the output buffer.
API Serialized PHP output formatter.
getMimeType()
Overriding class returns the MIME type that should be sent to the client.When getIsHtml() returns tru...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Service for formatting and validating API parameters.