2020-06-17 02:56:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Citizen;
|
|
|
|
|
|
|
|
use ConfigException;
|
|
|
|
use Exception;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use RequestContext;
|
|
|
|
use ThumbnailImage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook handlers for Citizen skin.
|
|
|
|
*
|
|
|
|
* Hook handler method names should be in the form of:
|
|
|
|
* on<HookName>()
|
|
|
|
*/
|
|
|
|
class CitizenHooks {
|
|
|
|
/**
|
|
|
|
* ResourceLoaderGetConfigVars hook handler for setting a config variable
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
|
|
|
|
*
|
|
|
|
* @param array &$vars Array of variables to be added into the output of the startup module.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars ) {
|
|
|
|
try {
|
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Citizen' );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$vars['wgCitizenSearchDescriptionSource'] = $config->get( 'CitizenSearchDescriptionSource' );
|
|
|
|
} catch ( ConfigException $e ) {
|
|
|
|
// Should not happen
|
|
|
|
$vars['wgCitizenSearchDescriptionSource'] = 'textextracts';
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$vars['wgCitizenMaxSearchResults'] = $config->get( 'CitizenMaxSearchResults' );
|
|
|
|
} catch ( ConfigException $e ) {
|
|
|
|
// Should not happen
|
|
|
|
$vars['wgCitizenMaxSearchResults'] = 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lazyload images
|
|
|
|
* Modified from the Lazyload extension
|
|
|
|
* Looks for thumbnail and swap src to data-src
|
|
|
|
*
|
2020-08-20 16:36:50 +00:00
|
|
|
* @param ThumbnailImage $thumbnail
|
2020-06-17 02:56:40 +00:00
|
|
|
* @param array &$attribs
|
|
|
|
* @param array &$linkAttribs
|
|
|
|
* @return bool
|
|
|
|
*/
|
2020-08-20 16:36:50 +00:00
|
|
|
public static function onThumbnailBeforeProduceHTML( $thumbnail, &$attribs, &$linkAttribs ) {
|
2020-06-17 02:56:40 +00:00
|
|
|
try {
|
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Citizen' );
|
|
|
|
$lazyloadEnabled = $config->get( 'CitizenEnableLazyload' );
|
|
|
|
} catch ( ConfigException $e ) {
|
2020-07-22 21:07:15 +00:00
|
|
|
$lazyloadEnabled = false;
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Replace thumbnail if lazyload is enabled
|
|
|
|
if ( $lazyloadEnabled === true ) {
|
2020-08-20 16:36:50 +00:00
|
|
|
$file = $thumbnail->getFile();
|
2020-06-17 02:56:40 +00:00
|
|
|
|
|
|
|
if ( $file !== null ) {
|
|
|
|
$request = RequestContext::getMain()->getRequest();
|
|
|
|
|
|
|
|
if ( defined( 'MW_API' ) && $request->getVal( 'action' ) === 'parse' ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set lazy class for the img
|
|
|
|
if ( isset( $attribs['class'] ) ) {
|
|
|
|
$attribs['class'] .= ' lazy';
|
|
|
|
} else {
|
|
|
|
$attribs['class'] = 'lazy';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Native API
|
|
|
|
$attribs['loading'] = 'lazy';
|
|
|
|
|
|
|
|
$attribs['data-src'] = $attribs['src'];
|
2020-08-20 16:36:50 +00:00
|
|
|
$attribs['src'] = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D';
|
2020-06-17 02:56:40 +00:00
|
|
|
|
|
|
|
if ( isset( $attribs['srcset'] ) ) {
|
|
|
|
$attribs['data-srcset'] = $attribs['srcset'];
|
2020-08-20 16:36:50 +00:00
|
|
|
$attribs['srcset'] = '';
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|