Merge "Various code style updates in ParserFileProcessingHookHandlers"

This commit is contained in:
jenkins-bot 2024-02-10 14:46:17 +00:00 committed by Gerrit Code Review
commit 9dce6063f3

View file

@ -196,7 +196,7 @@ class ParserFileProcessingHookHandlers implements
* @return array The best image, and the best free image * @return array The best image, and the best free image
*/ */
private function findBestImages( array $images ) { private function findBestImages( array $images ) {
if ( !count( $images ) ) { if ( !$images ) {
return [ false, false ]; return [ false, false ];
} }
@ -206,13 +206,9 @@ class ParserFileProcessingHookHandlers implements
$counter = 0; $counter = 0;
foreach ( $images as $image ) { foreach ( $images as $image ) {
$score = $this->getScore( $image, $counter++ );
$fileName = $image->getFileName(); $fileName = $image->getFileName();
$scores[$fileName] = max( $scores[$fileName] ?? -1, $score );
if ( !isset( $scores[$fileName] ) ) {
$scores[$fileName] = -1;
}
$scores[$fileName] = max( $scores[$fileName], $this->getScore( $image, $counter++ ) );
} }
$bestImageName = false; $bestImageName = false;
@ -257,11 +253,8 @@ class ParserFileProcessingHookHandlers implements
*/ */
private function processThisTitle( PageReference $pageReference ) { private function processThisTitle( PageReference $pageReference ) {
global $wgPageImagesNamespaces; global $wgPageImagesNamespaces;
static $flipped = false; static $flipped = null;
$flipped ??= array_flip( $wgPageImagesNamespaces );
if ( $flipped === false ) {
$flipped = array_flip( $wgPageImagesNamespaces );
}
return isset( $flipped[$pageReference->getNamespace()] ); return isset( $flipped[$pageReference->getNamespace()] );
} }
@ -307,9 +300,8 @@ class ParserFileProcessingHookHandlers implements
protected function getScore( PageImageCandidate $image, $position ) { protected function getScore( PageImageCandidate $image, $position ) {
global $wgPageImagesScores; global $wgPageImagesScores;
$classes = preg_split( '/\s+/', $image->getFrameClass(), -1, PREG_SPLIT_NO_EMPTY ); // Exclude images with class="notpageimage"
if ( in_array( 'notpageimage', $classes ) ) { if ( preg_match( '/(?:^|\s)notpageimage(?=\s|$)/', $image->getFrameClass() ) ) {
// Exclude images with class=nopageimage
return -1000; return -1000;
} }
@ -409,12 +401,7 @@ class ParserFileProcessingHookHandlers implements
protected function getRatio( PageImageCandidate $image ) { protected function getRatio( PageImageCandidate $image ) {
$width = $image->getFullWidth(); $width = $image->getFullWidth();
$height = $image->getFullHeight(); $height = $image->getFullHeight();
return $width > 0 && $height > 0 ? $width / $height : 0;
if ( !$width || !$height ) {
return 0;
}
return $width / $height;
} }
/** /**