Page MenuHomePhabricator

0003-Handle-thumb-errors-when-enableLegacyMediaDOM.patch

Authored By
Arlolra
Jun 29 2023, 12:59 AM
Size
4 KB
Referenced Files
None
Subscribers
None

0003-Handle-thumb-errors-when-enableLegacyMediaDOM.patch

From fd3951c107a73c2deff2df9ff9d7a33ac93ccb86 Mon Sep 17 00:00:00 2001
From: Arlo Breault <abreault@wikimedia.org>
Date: Wed, 28 Jun 2023 20:15:10 -0400
Subject: [PATCH 3/5] 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
---
includes/Linker.php | 24 ++++++++++++++++----
includes/gallery/TraditionalImageGallery.php | 9 +++++++-
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/includes/Linker.php b/includes/Linker.php
index cf9fb5762f3..4638ec4ae71 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -21,11 +21,13 @@
*/
use HtmlFormatter\HtmlFormatter;
+use MediaTransformError;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\Authority;
use MediaWiki\Revision\RevisionRecord;
+use Wikimedia\Assert\Assert;
use Wikimedia\IPUtils;
use Wikimedia\Rdbms\SelectQueryBuilder;
@@ -448,7 +450,7 @@ class Linker {
$thumb = false;
}
- if ( !$thumb ) {
+ if ( !$thumb || ( !$enableLegacyMediaDOM && $thumb->isError() ) ) {
$rdfaType = 'mw:Error ' . $rdfaType;
$currentExists = $file && $file->exists();
if ( $enableLegacyMediaDOM ) {
@@ -456,8 +458,14 @@ class Linker {
// Parsoid stores in data-mw. See T273014
$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 = '';
}
@@ -732,12 +740,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
);
diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php
index 3cfcd1caea0..275df4fe2ae 100644
--- a/includes/gallery/TraditionalImageGallery.php
+++ b/includes/gallery/TraditionalImageGallery.php
@@ -3,6 +3,7 @@
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
+use Wikimedia\Assert\Assert;
/**
* Image gallery.
@@ -114,7 +115,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 ) {
@@ -127,6 +128,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 = '';
}
--
2.41.0

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10911443
Default Alt Text
0003-Handle-thumb-errors-when-enableLegacyMediaDOM.patch (4 KB)

Event Timeline