Merge "Fix sessionfailure i18n message during authentication"
[lhc/web/wiklou.git] / includes / api / ApiFormatPhp.php
1 <?php
2 /**
3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * API Serialized PHP output formatter
25 * @ingroup API
26 */
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: wfMangleFlashPolicy() is needed to avoid 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( 'wfOutputHandler', 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' ],
77 ApiBase::PARAM_DFLT => 1,
78 ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
79 ],
80 ];
81 return $ret;
82 }
83 }