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