jenkins-bot has submitted this change and it was merged.

Change subject: Fix badly cropped images when using page images
......................................................................


Fix badly cropped images when using page images

Skips generating of banner HTML code when image is not landscape.
This fix should also allow when the editor has specifically overriden the 
default.

Bug: T131424
Change-Id: I1261cca946e8e0e87ad9446233096da4511a1443
---
M includes/WikidataPageBanner.functions.php
M includes/WikidataPageBanner.hooks.php
2 files changed, 11 insertions(+), 5 deletions(-)

Approvals:
  Sumit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/WikidataPageBanner.functions.php 
b/includes/WikidataPageBanner.functions.php
old mode 100644
new mode 100755
index 3f2216e..dc8c812
--- a/includes/WikidataPageBanner.functions.php
+++ b/includes/WikidataPageBanner.functions.php
@@ -165,15 +165,20 @@
                        // use largest image url as src attribute
                        $bannerurl = $urls[count( $urls ) - 1];
                        $bannerfile = Title::newFromText( "File:$bannername" );
+                       $file = wfFindFile( $bannerfile );
+                       // don't auto generate banner if image is not 
landscape, see bug report T131424
+                       $fileWidth = $file->getWidth();
+                       $fileHeight = $file->getHeight();
+                       if ( isset( $options['isAutomatic'] ) && $fileWidth < 
1.5 * $fileHeight ) {
+                               return null;
+                       }
                        $templateParser = new TemplateParser( __DIR__ . 
'/../templates' );
                        $options['bannerfile'] = $bannerfile->getLocalUrl();
                        $options['banner'] = $bannerurl;
                        $options['srcset'] = $srcset;
-                       $file = wfFindFile( $bannerfile );
-                       $fileWidth = $file->getWidth();
                        $options['maxWidth'] = $fileWidth;
                        // Provide information to the logic-less template about 
whether it is a panorama or not.
-                       $options['isPanorama'] = $fileWidth > ( 
$file->getHeight() * 2 );
+                       $options['isPanorama'] = $fileWidth > ( $fileHeight * 2 
);
                        $options['isHeadingOverrideEnabled'] = $config->get( 
'WPBEnableHeadingOverride' );
                        $banner = $templateParser->processTemplate(
                                'banner',
diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
old mode 100644
new mode 100755
index a87290d..642248c
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -98,6 +98,7 @@
                        $banner = $wpbFunctionsClass::getBannerHtml( 
$bannername, $params );
                        // attempt to get an automatic banner
                        if ( $banner === null ) {
+                               $params['isAutomatic'] = true;
                                $bannername = 
$wpbFunctionsClass::getAutomaticBanner( $title );
                                $banner = $wpbFunctionsClass::getBannerHtml( 
$bannername, $params );
                        }
@@ -123,8 +124,8 @@
                        if ( $wpbFunctionsClass::validateNamespace( $ns ) && 
!$title->isMainPage() ) {
                                // first try to obtain bannername from Wikidata
                                $bannername = 
$wpbFunctionsClass::getAutomaticBanner( $title );
-                               // add title to template parameters
-                               $paramsForBannerTemplate = [ 'title' => $title 
];
+                               // add title and whether the banner is auto 
generated to template parameters
+                               $paramsForBannerTemplate = [ 'title' => $title, 
'isAutomatic' => true ];
                                $banner = $wpbFunctionsClass::
                                        getBannerHtml( $bannername, 
$paramsForBannerTemplate );
                                // only add banner and styling if valid banner 
generated

-- 
To view, visit https://gerrit.wikimedia.org/r/324775
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1261cca946e8e0e87ad9446233096da4511a1443
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Divadsn <divad.nnamtd...@gmail.com>
Gerrit-Reviewer: Divadsn <divad.nnamtd...@gmail.com>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Sumit <asthana.sumi...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to