Check whether title actually exists

Code a couple of lines below is dependant on $title
existing and having an id, but that's not explicitly
being checked.

If the result is not a valid title, there isn't going
to be a thumbnail for it.

Bug: T319798
Change-Id: I22c2ab886b3a1b1fdf2df062ffa76cd00d4d25fd
This commit is contained in:
Matthias Mullie 2022-10-06 22:32:30 +02:00
parent ab7849ed47
commit 58d9b4f8f0

View file

@ -279,7 +279,8 @@ class FullSearchResultWidget implements SearchResultWidget {
*/
protected function generateFileHtml( SearchResult $result ) {
$title = $result->getTitle();
if ( $title === null ) {
// don't assume that result is a valid title; e.g. could be interwiki page
if ( $title === null || !$title->canExist() || !$title->exists() ) {
return [ '', null, null ];
}
@ -317,7 +318,8 @@ class FullSearchResultWidget implements SearchResultWidget {
*/
private function getThumbnail( SearchResult $result, int $size ): ?SearchResultThumbnail {
$title = $result->getTitle();
if ( $title === null ) {
// don't assume that result is a valid title; e.g. could be interwiki page
if ( $title === null || !$title->canExist() || !$title->exists() ) {
return null;
}
@ -333,7 +335,8 @@ class FullSearchResultWidget implements SearchResultWidget {
*/
private function generateThumbnailHtml( SearchResult $result, SearchResultThumbnail $thumbnail = null ): ?string {
$title = $result->getTitle();
if ( $title === null ) {
// don't assume that result is a valid title; e.g. could be interwiki page
if ( $title === null || !$title->canExist() || !$title->exists() ) {
return null;
}