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