MediaWiki master
ApiFormatPhp.php
Go to the documentation of this file.
1<?php
24
30
31 public function getMimeType() {
32 return 'application/vnd.php.serialized';
33 }
34
35 public function execute() {
37
38 switch ( $params['formatversion'] ) {
39 case 1:
40 $transforms = [
41 'BC' => [],
42 'Types' => [],
43 'Strip' => 'all',
44 ];
45 break;
46
47 case 2:
48 case 'latest':
49 $transforms = [
50 'Types' => [],
51 'Strip' => 'all',
52 ];
53 break;
54
55 default:
56 // Should have been caught during parameter validation
57 self::dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' );
58 }
59 $this->printText( serialize( $this->getResult()->getResultData( null, $transforms ) ) );
60 }
61
62 public function getAllowedParams() {
63 return parent::getAllowedParams() + [
64 'formatversion' => [
65 ParamValidator::PARAM_TYPE => [ '1', '2', 'latest' ],
66 ParamValidator::PARAM_DEFAULT => '1',
67 ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
69 '1' => 'apihelp-php-paramvalue-formatversion-1',
70 '2' => 'apihelp-php-paramvalue-formatversion-2',
71 'latest' => 'apihelp-php-paramvalue-formatversion-latest',
72 ],
73 ],
74 ];
75 }
76}
array $params
The job parameters.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:1777
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:211
getResult()
Get the result object.
Definition ApiBase.php:671
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:811
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:171
This is the abstract base class for API formatters.
printText( $text)
Append text to the output buffer.
API Serialized PHP output formatter.
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...
getMimeType()
Overriding class returns the MIME type that should be sent to the client.
Service for formatting and validating API parameters.