diff options
author | Arlo Breault <abreault@wikimedia.org> | 2023-04-27 14:18:05 -0400 |
---|---|---|
committer | Arlo Breault <abreault@wikimedia.org> | 2023-05-01 12:27:31 -0400 |
commit | 6f3b22c4100731a2eb181390558054feb0e62da4 (patch) | |
tree | 680b5c6e10000da456f826f5fb8b4b3c34344c18 | |
parent | aeeaa4783d030b727bca12ed5759595f7cbf08d5 (diff) | |
download | mediawikicore-6f3b22c4100731a2eb181390558054feb0e62da4.tar.gz mediawikicore-6f3b22c4100731a2eb181390558054feb0e62da4.zip |
Handle thumb errors when !$enableLegacyMediaDOM
MediaTransformError implements MediaTransformOutput and so it has a
::toHtml to call but the output of that isn't phrasing content, as would
be required in the context in which parser output uses it when
!$enableLegacyMediaDOM.
Bug: T334659
Change-Id: I38618552c4916dc96eac2cb181d9fbbc418187b0
-rw-r--r-- | includes/gallery/TraditionalImageGallery.php | 9 | ||||
-rw-r--r-- | includes/linker/Linker.php | 24 |
2 files changed, 28 insertions, 5 deletions
diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index d9c39d2e4da4..5c37b13eaf35 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -6,6 +6,7 @@ use MediaWiki\Linker\LinkRenderer; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use MediaWiki\Title\Title; +use Wikimedia\Assert\Assert; /** * Image gallery. @@ -117,7 +118,7 @@ class TraditionalImageGallery extends ImageGalleryBase { $isBadFile = $img && $thumb && $this->mHideBadImages && $badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() ); - if ( !$img || !$thumb || $isBadFile ) { + if ( !$img || !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) || $isBadFile ) { $rdfaType = 'mw:Error ' . $rdfaType; if ( $enableLegacyMediaDOM ) { @@ -130,6 +131,12 @@ class TraditionalImageGallery extends ImageGalleryBase { $currentExists = $img && $img->exists(); if ( $currentExists && !$thumb ) { $label = wfMessage( 'thumbnail_error', '' )->text(); + } elseif ( $thumb && $thumb->isError() ) { + Assert::invariant( + $thumb instanceof MediaTransformError, + 'Unknown MediaTransformOutput: ' . get_class( $thumb ) + ); + $label = $thumb->toText(); } else { $label = $alt ?? ''; } diff --git a/includes/linker/Linker.php b/includes/linker/Linker.php index ddebd1c2b988..d2310d525ddd 100644 --- a/includes/linker/Linker.php +++ b/includes/linker/Linker.php @@ -31,6 +31,7 @@ use Hooks; use HtmlArmor; use IContextSource; use Language; +use MediaTransformError; use MediaTransformOutput; use MediaWiki\Html\Html; use MediaWiki\Html\HtmlHelper; @@ -47,6 +48,7 @@ use SpecialPage; use TitleValue; use User; use WatchedItem; +use Wikimedia\Assert\Assert; use Wikimedia\IPUtils; use Wikimedia\Parsoid\Core\TOCData; use Wikimedia\Rdbms\SelectQueryBuilder; @@ -467,14 +469,20 @@ class Linker { $thumb = false; } - if ( !$thumb ) { + if ( !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) ) { $rdfaType = 'mw:Error ' . $rdfaType; $currentExists = $file && $file->exists(); if ( $enableLegacyMediaDOM ) { $label = $frameParams['title']; } else { - if ( $currentExists ) { + if ( $currentExists && !$thumb ) { $label = wfMessage( 'thumbnail_error', '' )->text(); + } elseif ( $thumb && $thumb->isError() ) { + Assert::invariant( + $thumb instanceof MediaTransformError, + 'Unknown MediaTransformOutput: ' . get_class( $thumb ) + ); + $label = $thumb->toText(); } else { $label = $frameParams['alt'] ?? ''; } @@ -757,12 +765,20 @@ class Linker { $title, $label, '', '', '', (bool)$time, $handlerParams, false ); $zoomIcon = ''; - } elseif ( !$thumb ) { + } elseif ( !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) ) { $rdfaType = 'mw:Error ' . $rdfaType; if ( $enableLegacyMediaDOM ) { $s .= wfMessage( 'thumbnail_error', '' )->escaped(); } else { - $label = wfMessage( 'thumbnail_error', '' )->text(); + if ( $thumb && $thumb->isError() ) { + Assert::invariant( + $thumb instanceof MediaTransformError, + 'Unknown MediaTransformOutput: ' . get_class( $thumb ) + ); + $label = $thumb->toText(); + } else { + $label = wfMessage( 'thumbnail_error', '' )->text(); + } $s .= self::makeBrokenImageLinkObj( $title, $label, '', '', '', (bool)$time, $handlerParams, true ); |