MediaWiki REL1_32
ApiFormatPhp.php
Go to the documentation of this file.
1<?php
28
29 public function getMimeType() {
30 return 'application/vnd.php.serialized';
31 }
32
33 public function execute() {
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 $ret = parent::getAllowedParams() + [
75 'formatversion' => [
76 ApiBase::PARAM_TYPE => [ '1', '2', 'latest' ],
78 ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
79 ],
80 ];
81 return $ret;
82 }
83}
serialize()
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1987
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition ApiBase.php:2167
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
getResult()
Get the result object.
Definition ApiBase.php:659
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:770
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
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.
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
Definition hooks.txt:2054
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params