Merge pull request #141 from StarCitizenTools/dev

Various improvement and clean up
This commit is contained in:
alistair3149 2020-06-15 22:56:47 -04:00 committed by GitHub
commit f9ac569796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 30 deletions

View file

@ -1,8 +1,10 @@
<?php
/**
* Citizen - A responsive skin developed for the Star Citizen Wiki
*
* This program 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 2 of the License, or
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@ -23,9 +25,7 @@ namespace Citizen;
use ConfigException;
use Exception;
use MediaWiki\MediaWikiServices;
use OutputPage;
use RequestContext;
use Skin;
use ThumbnailImage;
/**
@ -35,27 +35,6 @@ use ThumbnailImage;
* on<HookName>()
*/
class CitizenHooks {
/**
* @param OutputPage $out
* @param Skin $skin
* @return bool
*/
public static function onBeforePageDisplay( $out, $skin ) {
try {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Citizen' );
$lazyloadEnabled = $config->get( 'CitizenEnableLazyload' );
} catch ( Exception $e ) {
return false;
}
if ( $lazyloadEnabled === true ) {
$out->addModules( 'skins.citizen.styles.lazyload' );
$out->addModules( 'skins.citizen.scripts.lazyload' );
}
return true;
}
/**
* ResourceLoaderGetConfigVars hook handler for setting a config variable
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars

View file

@ -1,4 +1,25 @@
<?php
/**
* Citizen - A responsive skin developed for the Star Citizen Wiki
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Skins
*/
use MediaWiki\MediaWikiServices;

View file

@ -1,8 +1,28 @@
<?php
/**
* Citizen - A responsive skin developed for the Star Citizen Wiki
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Skins
*/
/**
* SkinTemplate class for the Citizen skin
*
* @ingroup Skins
*/
class SkinCitizen extends SkinTemplate {
@ -211,6 +231,7 @@ class SkinCitizen extends SkinTemplate {
*/
public function getDefaultModules() {
$modules = parent::getDefaultModules();
$out = $this->getOutput();
// Replace the search module
if ( $this->getConfigValue( 'CitizenEnableSearch' ) === true ) {
@ -221,17 +242,25 @@ class SkinCitizen extends SkinTemplate {
];
}
if ( $out->isTOCEnabled() ) {
// Disable style condition loading due to pop in
// $modules['content'][] = 'skins.citizen.styles.toc';
$modules['content'][] = 'skins.citizen.scripts.toc';
}
return $modules;
}
/**
* Adds all needed skin modules
* TODO: Replace with getDefaultModules() when we move to min 1.35
*/
private function addModules() {
$this->out->addModuleStyles( [
'mediawiki.skinning.content.externallinks',
'skins.citizen.styles',
'skins.citizen.styles.fonts',
'skins.citizen.styles.toc',
'skins.citizen.icons',
'skins.citizen.icons.ca',
'skins.citizen.icons.es',
@ -242,6 +271,11 @@ class SkinCitizen extends SkinTemplate {
'skins.citizen.icons.badges',
] );
// Add lazyload-related modules
if ( $this->getConfigValue( 'CitizenEnableLazyload' ) === true ) {
$this->out->addModuleStyles( [ 'skins.citizen.styles.lazyload' ] );
$this->out->addModules( [ 'skins.citizen.scripts.lazyload' ] );
}
$this->out->addModules( [
'skins.citizen.scripts',
] );

View file

@ -1,3 +1,6 @@
@import '../variables.less';
@import '../mixins.less';
.toc {
position: fixed;
z-index: -1; // So that it is below float objects in content

View file

@ -8,7 +8,6 @@
@import 'common/content.less';
@import 'common/typography.less';
@import 'common/hacks.less';
@import 'common/toc.less';
@import 'common/wikitable.less';
@import 'common/scrollbar.less';
@import 'common/reducemotion.less';

View file

@ -188,6 +188,14 @@
],
"styles": [ "resources/skins.citizen.styles.fonts/font-face.less" ]
},
"skins.citizen.styles.toc": {
"class": "ResourceLoaderSkinModule",
"targets": [
"desktop",
"mobile"
],
"styles": [ "resources/skins.citizen.styles.toc/toc.less" ]
},
"skins.citizen.styles.search": {
"class": "ResourceLoaderSkinModule",
"targets": [
@ -206,10 +214,14 @@
},
"skins.citizen.scripts": {
"scripts": [
"resources/skins.citizen.scripts/toc.js",
"resources/skins.citizen.scripts/search.js"
]
},
"skins.citizen.scripts.toc": {
"scripts": [
"resources/skins.citizen.scripts.toc/toc.js"
]
},
"skins.citizen.scripts.search": {
"scripts": [
"resources/skins.citizen.scripts.search/underscore.partial.js",
@ -517,9 +529,6 @@
}
},
"Hooks": {
"BeforePageDisplay": [
"Citizen\\CitizenHooks::onBeforePageDisplay"
],
"ResourceLoaderGetConfigVars": [
"Citizen\\CitizenHooks::onResourceLoaderGetConfigVars"
],