Allow to make thumbnail size configurable

This commit is contained in:
Hannes 2020-01-11 21:27:39 +01:00
parent 85f1ea1e91
commit 423e7c0eea
No known key found for this signature in database
GPG key ID: 371029119C5F0D51
2 changed files with 17 additions and 1 deletions

View file

@ -88,6 +88,15 @@ class CitizenHooks {
* @return bool
*/
public static function onThumbnailBeforeProduceHTML( $thumb, &$attribs, &$linkAttribs ) {
try {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Citizen' );
$thumbSize = $config->get( 'ThumbnailSize' );
} catch ( ConfigException $e ) {
wfLogWarning( sprintf( 'Could not get config for "$wgThumbnailSize". Defaulting to "10". %s',
$e->getMessage() ) );
$thumbSize = 10;
}
$file = $thumb->getFile();
if ( $file !== null ) {
@ -112,7 +121,8 @@ class CitizenHooks {
$attribs['data-height'] = $attribs['height'];
// Replace src with small size image
$attribs['src'] = preg_replace( '#/\d+px-#', '/10px-', $attribs['src'] );
$attribs['src'] =
preg_replace( '#/\d+px-#', sprintf( '/%upx-', $thumbSize ), $attribs['src'] );
// So that the 10px thumbnail is enlarged to the right size
$attribs['width'] = $attribs['data-width'];

View file

@ -164,6 +164,12 @@
"description": "Page tools visibility condition",
"descriptionmsg": "citizen-config-showpagetools",
"public": true
},
"ThumbnailSize": {
"value": 10,
"description": "Thumbnail size to use for lazy-loading",
"descriptionmsg": "citizen-config-thumbnailsize",
"public": true
}
},
"ConfigRegistry": {