Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ApiWebappManifest | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
30 | |||
getCustomPrinter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiFormatJson; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\Title\Title; |
9 | |
10 | /** |
11 | * Return the webapp manifest for this wiki |
12 | */ |
13 | class ApiWebappManifest extends ApiBase { |
14 | |
15 | /** |
16 | * Execute the requested Api actions. |
17 | */ |
18 | public function execute() { |
19 | $services = MediaWikiServices::getInstance(); |
20 | |
21 | $config = $this->getConfig(); |
22 | $resultObj = $this->getResult(); |
23 | $resultObj->addValue( null, 'name', $config->get( 'Sitename' ) ); |
24 | $resultObj->addValue( null, 'orientation', 'portrait' ); |
25 | $resultObj->addValue( null, 'dir', $services->getContentLanguage()->getDir() ); |
26 | $resultObj->addValue( null, 'lang', $config->get( 'LanguageCode' ) ); |
27 | $resultObj->addValue( null, 'display', 'minimal-ui' ); |
28 | $resultObj->addValue( null, 'theme_color', $config->get( 'MFManifestThemeColor' ) ); |
29 | $resultObj->addValue( null, 'background_color', $config->get( 'MFManifestBackgroundColor' ) ); |
30 | $resultObj->addValue( null, 'start_url', Title::newMainPage()->getLocalURL() ); |
31 | |
32 | $icons = []; |
33 | |
34 | $appleTouchIcon = $config->get( 'AppleTouchIcon' ); |
35 | if ( $appleTouchIcon !== false ) { |
36 | $appleTouchIconUrl = wfExpandUrl( $appleTouchIcon, PROTO_CURRENT ); |
37 | $request = $services->getHttpRequestFactory()->create( $appleTouchIconUrl, [], __METHOD__ ); |
38 | $request->execute(); |
39 | $appleTouchIconContent = $request->getContent(); |
40 | if ( $appleTouchIconContent !== '' ) { |
41 | $appleTouchIconSize = getimagesizefromstring( $appleTouchIconContent ); |
42 | } |
43 | $icon = [ |
44 | 'src' => $appleTouchIcon |
45 | ]; |
46 | if ( isset( $appleTouchIconSize ) && $appleTouchIconSize !== false ) { |
47 | $icon['sizes'] = $appleTouchIconSize[0] . 'x' . $appleTouchIconSize[1]; |
48 | $icon['type'] = $appleTouchIconSize['mime']; |
49 | } |
50 | $icons[] = $icon; |
51 | } |
52 | |
53 | $resultObj->addValue( null, 'icons', $icons ); |
54 | |
55 | $main = $this->getMain(); |
56 | $main->setCacheControl( [ 's-maxage' => 86400, 'max-age' => 86400 ] ); |
57 | $main->setCacheMode( 'public' ); |
58 | } |
59 | |
60 | /** |
61 | * Get the JSON printer |
62 | * |
63 | * @return ApiFormatJson |
64 | */ |
65 | public function getCustomPrinter() { |
66 | return new ApiFormatJson( $this->getMain(), 'json' ); |
67 | } |
68 | |
69 | } |