Skip to content

Instantly share code, notes, and snippets.

@1v
Created May 10, 2014 20:14
Show Gist options
  • Save 1v/fb9cbe7bf30a63a6f309 to your computer and use it in GitHub Desktop.
Save 1v/fb9cbe7bf30a63a6f309 to your computer and use it in GitHub Desktop.
$wgImageLimits = array(
array(320, 3000),
array(640, 3000),
array(800, 3000),
array(1024, 3000),
array(1280, 3000),
array(1600, 3000),
array(1900, 3000)
);
I want limit only images widths, so I setted all heights to 3000. Now if image height less than 3000 then "Other resolutions" on image page (like https://www.mediawiki.org/wiki/File:Astronotus_ocellatus.jpg) is not displaying (only original size), because of this part in ImagePage.php https://github.com/wikimedia/mediawiki-core/blob/a3983418d5748fbccdda15e0e48af90c50ef1f67/includes/ImagePage.php#L386:
if ( $size[0] <= $width_orig && $size[1] <= $height_orig
&& $size[0] != $width && $size[1] != $height
) {
$sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
if ( $sizeLink ) {
$otherSizes[] = $sizeLink;
}
}
If one of this rules not true, size not included:
$size[0] <= $width_orig // if width from $wgImageLimits less than origin
$size[1] <= $height_orig // if height from $wgImageLimits less than origin
$size[0] != $width // almost always true
$size[1] != $height // almost always true
But size should be not included only if width OR height less than origin. So hotfix will be:
if ( ( $size[0] <= $width_orig || $size[1] <= $height_orig )
&& $size[0] != $width && $size[1] != $height
) {
$sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
if ( $sizeLink ) {
$otherSizes[] = $sizeLink;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment