Merge pull request #69 from octfx/feature/configurable_thumbsize

Allow to make thumbnail size configurable
This commit is contained in:
alistair3149 2020-01-11 15:35:57 -05:00 committed by GitHub
commit 3c3eb9c7a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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( 'CitizenThumbnailSize' );
} 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": {