Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.62% |
29 / 32 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiFormatPhp | |
93.55% |
29 / 31 |
|
66.67% |
2 / 3 |
7.01 | |
0.00% |
0 / 1 |
getMimeType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
5.03 | |||
getAllowedParams | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 |
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 | namespace MediaWiki\Api; |
24 | |
25 | use Wikimedia\ParamValidator\ParamValidator; |
26 | |
27 | /** |
28 | * API Serialized PHP output formatter |
29 | * @ingroup API |
30 | */ |
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 | self::dieDebug( __METHOD__, 'Unknown value for \'formatversion\'' ); |
60 | } |
61 | $this->printText( serialize( $this->getResult()->getResultData( null, $transforms ) ) ); |
62 | } |
63 | |
64 | public function getAllowedParams() { |
65 | return parent::getAllowedParams() + [ |
66 | 'formatversion' => [ |
67 | ParamValidator::PARAM_TYPE => [ '1', '2', 'latest' ], |
68 | ParamValidator::PARAM_DEFAULT => '1', |
69 | ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion', |
70 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [ |
71 | '1' => 'apihelp-php-paramvalue-formatversion-1', |
72 | '2' => 'apihelp-php-paramvalue-formatversion-2', |
73 | 'latest' => 'apihelp-php-paramvalue-formatversion-latest', |
74 | ], |
75 | ], |
76 | ]; |
77 | } |
78 | } |
79 | |
80 | /** @deprecated class alias since 1.43 */ |
81 | class_alias( ApiFormatPhp::class, 'ApiFormatPhp' ); |