MediaWiki  master
ApiFormatPhp.php
Go to the documentation of this file.
1 <?php
27 class ApiFormatPhp extends ApiFormatBase {
28 
29  public function getMimeType() {
30  return 'application/vnd.php.serialized';
31  }
32 
33  public function execute() {
34  $params = $this->extractRequestParams();
35 
36  switch ( $params['formatversion'] ) {
37  case 1:
38  $transforms = [
39  'BC' => [],
40  'Types' => [],
41  'Strip' => 'all',
42  ];
43  break;
44 
45  case 2:
46  case 'latest':
47  $transforms = [
48  'Types' => [],
49  'Strip' => 'all',
50  ];
51  break;
52 
53  default:
54  // Should have been caught during parameter validation
55  $this->dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' );
56  }
57  $text = serialize( $this->getResult()->getResultData( null, $transforms ) );
58 
59  // T68776: OutputHandler::mangleFlashPolicy() avoids a nasty bug in
60  // Flash, but what it does isn't friendly for the API. There's nothing
61  // we can do here that isn't actively broken in some manner, so let's
62  // just be broken in a useful manner.
63  if ( $this->getConfig()->get( 'MangleFlashPolicy' ) &&
64  in_array( 'MediaWiki\\OutputHandler::handle', ob_list_handlers(), true ) &&
65  preg_match( '/<\s*cross-domain-policy(?=\s|>)/i', $text )
66  ) {
67  $this->dieWithError( 'apierror-formatphp', 'internalerror' );
68  }
69 
70  $this->printText( $text );
71  }
72 
73  public function getAllowedParams() {
74  return parent::getAllowedParams() + [
75  'formatversion' => [
76  ApiBase::PARAM_TYPE => [ '1', '2', 'latest' ],
77  ApiBase::PARAM_DFLT => '1',
78  ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
80  ],
81  ];
82  }
83 }
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1436
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:162
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:81
ApiFormatBase
This is the abstract base class for API formatters.
Definition: ApiFormatBase.php:30
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:628
ApiFormatPhp\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiFormatPhp.php:33
serialize
serialize()
Definition: ApiMessageTrait.php:138
ApiFormatPhp\getMimeType
getMimeType()
Overriding class returns the MIME type that should be sent to the client.
Definition: ApiFormatPhp.php:29
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:764
ApiFormatBase\printText
printText( $text)
Append text to the output buffer.
Definition: ApiFormatBase.php:348
ApiFormatPhp\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiFormatPhp.php:73
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:73
ApiBase\PARAM_HELP_MSG_PER_VALUE
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition: ApiBase.php:195
ApiBase\dieDebug
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:1639
ApiFormatPhp
API Serialized PHP output formatter.
Definition: ApiFormatPhp.php:27