From aadedadc7c14b737e76f541d0790c5f9a883389c Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Mon, 19 Aug 2024 20:15:34 +0800 Subject: [PATCH] Return early for cover images that are not found BookProvider::getCover() was already returning for no pages returned, so this switches to API formatversion 2 and also checks for the `missing` or `invalid` parameter in the first/only returned page. Bug: T370257 --- src/BookProvider.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/BookProvider.php b/src/BookProvider.php index 7b6dca1..d7ea296 100644 --- a/src/BookProvider.php +++ b/src/BookProvider.php @@ -302,8 +302,13 @@ public function getCover( $cover ): ?Picture { 'iiprop' => 'thumbmime|dimensions|url|canonicaltitle', 'iiurlparam' => $urlParam, 'iiurlwidth' => $width, + 'formatversion' => 2, ] )->wait(); - if ( !isset( $response['query']['pages'] ) ) { + // Give up for invalid cover titles or those that do not exist. + if ( !isset( $response['query']['pages'] ) + || isset( $response['query']['pages'][0]['missing'] ) + || isset( $response['query']['pages'][0]['invalid'] ) + ) { return null; }