mediawiki-skins-Citizen/includes/SkinCitizen.php

125 lines
3.3 KiB
PHP
Raw Normal View History

2019-08-15 17:40:13 +00:00
<?php
/**
* SkinTemplate class for the Citizen skin
*
* @ingroup Skins
*/
class SkinCitizen extends SkinTemplate {
public $skinname = 'citizen',
$stylename = 'Citizen',
$template = 'CitizenTemplate';
/**
* ResourceLoader
*
* @param $out OutputPage
*/
public function initPage( OutputPage $out ) {
// Responsive layout
$out->addMeta( 'viewport',
'width=device-width, initial-scale=1.0'
2019-08-15 17:40:13 +00:00
);
// Theme color
$out->addMeta( 'theme-color',
$this->getConfig()->get( 'CitizenThemeColor' )
);
2019-12-11 03:59:10 +00:00
// Preconnect origin
if ( $this->getConfig()->get( 'CitizenEnablePreconnect' ) ) {
$out->addLink(
[
'rel' => 'preconnect',
2019-12-24 03:17:28 +00:00
'href' => $this->getConfig()->get( 'CitizenPreconnectURL' )
2019-12-11 03:59:10 +00:00
]
);
}
2019-08-15 17:40:13 +00:00
// Generate manifest
if ( $this->getConfig()->get( 'CitizenEnableManifest' ) ) {
$out->addLink(
[
'rel' => 'manifest',
'href' => wfExpandUrl(
wfAppendQuery(
wfScript( 'api' ),
[ 'action' => 'webapp-manifest' ]
),
PROTO_RELATIVE
)
]
);
}
2019-12-24 04:27:36 +00:00
// HTTP headers
2019-12-24 04:13:42 +00:00
// CSP
if ( $this->getConfig()->get( 'CitizenEnableCSP' ) ) {
$cspdirective = $this->getConfig()->get( 'CitizenCSPDirective' );
// Check if report mode is enabled
if ( $this->getConfig()->get( 'CitizenEnableCSPReportMode' ) ) {
$out->getRequest()->response()->header( 'Content-Security-Policy-Report-Only: ' . $cspdirective );
} else {
$out->getRequest()->response()->header( 'Content-Security-Policy: ' . $cspdirective );
}
}
2019-12-24 03:17:28 +00:00
// HSTS
if ( $this->getConfig()->get( 'CitizenEnableHSTS' ) ) {
$hstsmaxage = $this->getConfig()->get( 'CitizenHSTSMaxAge' );
$hstsincludesubdomains = $this->getConfig()->get( 'CitizenHSTSIncludeSubdomains' );
2019-12-24 03:43:11 +00:00
$hstspreload = $this->getConfig()->get( 'CitizenHSTSPreload' );
2019-12-24 03:17:28 +00:00
// HSTS max age
if ( is_int( $hstsmaxage ) ) {
$hstsmaxage = max($hstsmaxage, 0);
} else {
// Default to 5 mins if input is invalid
$hstsmaxage = 300;
}
2019-12-24 03:43:11 +00:00
$out->getRequest()->response()->header( 'Strict-Transport-Security: max-age=' . $hstsmaxage . ( $hstsincludesubdomains ? '; includeSubDomains' : '' ) . ( $hstspreload ? '; preload' : '' ) );
2019-12-24 03:17:28 +00:00
}
2019-12-24 02:10:13 +00:00
// Deny X-Frame-Options
2019-12-24 02:15:52 +00:00
if ( $this->getConfig()->get( 'CitizenEnableDenyXFrameOptions' ) ) {
2019-12-24 02:10:13 +00:00
$out->getRequest()->response()->header( 'X-Frame-Options: deny' );
}
// Strict referrer policy
if ( $this->getConfig()->get( 'CitizenEnableStrictReferrerPolicy' ) ) {
2019-12-24 01:26:26 +00:00
// iOS Safari, IE, Edge compatiblity
$out->addMeta( 'referrer',
'strict-origin'
);
$out->addMeta( 'referrer',
'strict-origin-when-cross-origin'
);
$out->getRequest()->response()->header( 'Referrer-Policy: strict-origin-when-cross-origin' );
}
2019-08-15 17:40:13 +00:00
$out->addModuleStyles( [
'mediawiki.skinning.content.externallinks',
'skins.citizen',
'skins.citizen.icons',
'skins.citizen.icons.ca',
'skins.citizen.icons.p',
'skins.citizen.icons.toc',
'skins.citizen.icons.es',
'skins.citizen.icons.n',
'skins.citizen.icons.t',
'skins.citizen.icons.pt',
'skins.citizen.icons.footer',
2019-12-12 02:10:34 +00:00
'skins.citizen.icons.badges',
'skins.citizen.icons.search'
2019-08-15 17:40:13 +00:00
] );
$out->addModules( [
2019-12-11 22:14:36 +00:00
'skins.citizen.js',
'skins.citizen.search'
2019-08-15 17:40:13 +00:00
] );
}
/**
* @param $out OutputPage
*/
function setupSkinUserCss( OutputPage $out ) {
parent::setupSkinUserCss( $out );
}
}