2019-08-15 17:40:13 +00:00
|
|
|
<?php
|
2020-06-17 02:56:19 +00:00
|
|
|
/**
|
|
|
|
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
|
|
|
*
|
|
|
|
* This file is part of Citizen.
|
|
|
|
*
|
|
|
|
* Citizen is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Citizen is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:12:14 +00:00
|
|
|
namespace Citizen;
|
|
|
|
|
|
|
|
use ApiBase;
|
|
|
|
use ApiFormatJson;
|
2020-07-05 12:36:31 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-12-25 23:12:14 +00:00
|
|
|
use Title;
|
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
/**
|
|
|
|
* Extract and modified from MobileFrontend extension
|
|
|
|
* Return the webapp manifest for this wiki
|
|
|
|
*/
|
|
|
|
class ApiWebappManifest extends ApiBase {
|
|
|
|
/**
|
|
|
|
* Execute the requested Api actions.
|
|
|
|
*/
|
|
|
|
public function execute() {
|
2020-08-09 18:41:01 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2019-12-25 23:12:14 +00:00
|
|
|
|
2020-08-09 18:41:01 +00:00
|
|
|
$config = $this->getConfig();
|
|
|
|
$resultObj = $this->getResult();
|
|
|
|
$resultObj->addValue( null, 'name', $config->get( 'Sitename' ) );
|
2019-08-15 17:40:13 +00:00
|
|
|
$resultObj->addValue( null, 'orientation', 'portrait' );
|
2020-08-09 18:41:01 +00:00
|
|
|
$resultObj->addValue( null, 'dir', $services->getContentLanguage()->getDir() );
|
|
|
|
$resultObj->addValue( null, 'lang', $config->get( 'LanguageCode' ) );
|
2020-08-09 19:14:54 +00:00
|
|
|
$resultObj->addValue( null, 'display', 'standalone' );
|
2020-08-09 18:41:01 +00:00
|
|
|
$resultObj->addValue( null, 'theme_color', $config->get( 'CitizenManifestThemeColor' ) );
|
|
|
|
$resultObj->addValue( null, 'background_color', $config->get( 'CitizenManifestBackgroundColor' ) );
|
|
|
|
$resultObj->addValue( null, 'start_url', Title::newMainPage()->getLocalURL() );
|
2019-12-25 23:12:14 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
$icons = [];
|
|
|
|
|
2020-08-09 18:41:01 +00:00
|
|
|
$appleTouchIcon = $config->get( 'AppleTouchIcon' );
|
2019-08-15 17:40:13 +00:00
|
|
|
if ( $appleTouchIcon !== false ) {
|
2020-08-09 18:41:01 +00:00
|
|
|
$appleTouchIconUrl = wfExpandUrl( $appleTouchIcon, PROTO_CURRENT );
|
|
|
|
$request = $services->getHttpRequestFactory()->create( $appleTouchIconUrl, [], __METHOD__ );
|
2019-08-15 17:40:13 +00:00
|
|
|
$request->execute();
|
|
|
|
$appleTouchIconContent = $request->getContent();
|
|
|
|
if ( !empty( $appleTouchIconContent ) ) {
|
|
|
|
$appleTouchIconSize = getimagesizefromstring( $appleTouchIconContent );
|
|
|
|
}
|
|
|
|
$icon = [
|
2020-08-09 18:41:01 +00:00
|
|
|
'src' => $appleTouchIcon
|
2019-08-15 17:40:13 +00:00
|
|
|
];
|
|
|
|
if ( isset( $appleTouchIconSize ) && $appleTouchIconSize !== false ) {
|
2019-12-25 23:12:14 +00:00
|
|
|
$icon['sizes'] = $appleTouchIconSize[0] . 'x' . $appleTouchIconSize[1];
|
2019-08-15 17:40:13 +00:00
|
|
|
$icon['type'] = $appleTouchIconSize['mime'];
|
|
|
|
}
|
|
|
|
$icons[] = $icon;
|
|
|
|
}
|
|
|
|
|
2020-08-09 18:41:01 +00:00
|
|
|
$resultObj->addValue( null, 'icons', $icons );
|
|
|
|
|
|
|
|
$main = $this->getMain();
|
|
|
|
$main->setCacheControl( [ 's-maxage' => 86400, 'max-age' => 86400 ] );
|
|
|
|
$main->setCacheMode( 'public' );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the JSON printer
|
|
|
|
*
|
|
|
|
* @return ApiFormatJson
|
|
|
|
*/
|
|
|
|
public function getCustomPrinter() {
|
|
|
|
return new ApiFormatJson( $this->getMain(), 'json' );
|
|
|
|
}
|
|
|
|
}
|