aboutsummaryrefslogtreecommitdiffstats
path: root/includes/linker/Linker.php
diff options
context:
space:
mode:
authorArlo Breault <abreault@wikimedia.org>2023-04-27 14:18:05 -0400
committerArlo Breault <abreault@wikimedia.org>2023-05-01 12:27:31 -0400
commitaeeaa4783d030b727bca12ed5759595f7cbf08d5 (patch)
treeb28f10c36ceca1402430a7469d894426c33d6237 /includes/linker/Linker.php
parente0035bbf5a14f6ba733df387875d35ab897860de (diff)
downloadmediawikicore-aeeaa4783d030b727bca12ed5759595f7cbf08d5.tar.gz
mediawikicore-aeeaa4783d030b727bca12ed5759595f7cbf08d5.zip
Pass whether current rev of file exists to Linker::makeBrokenImageLinkObj
A $time parameter was added to Linker::makeBrokenImageLinkObj in 2d22c85 to avoid checking if a file exists if we were fetching the current revision. The assumption being that the method would only be called if the current revision doesn't exist. A new parameter is added to indicate that the current revision exist so that a known link can be created. Bug: T329214 Change-Id: I9ae5b18c422ab7d1b2b3b599a1994c319fe37239
Diffstat (limited to 'includes/linker/Linker.php')
-rw-r--r--includes/linker/Linker.php22
1 files changed, 14 insertions, 8 deletions
diff --git a/includes/linker/Linker.php b/includes/linker/Linker.php
index 763b207d5d2f..ddebd1c2b988 100644
--- a/includes/linker/Linker.php
+++ b/includes/linker/Linker.php
@@ -469,13 +469,18 @@ class Linker {
if ( !$thumb ) {
$rdfaType = 'mw:Error ' . $rdfaType;
+ $currentExists = $file && $file->exists();
if ( $enableLegacyMediaDOM ) {
$label = $frameParams['title'];
} else {
- $label = $frameParams['alt'] ?? '';
+ if ( $currentExists ) {
+ $label = wfMessage( 'thumbnail_error', '' )->text();
+ } else {
+ $label = $frameParams['alt'] ?? '';
+ }
}
$s = self::makeBrokenImageLinkObj(
- $title, $label, '', '', '', (bool)$time, $handlerParams
+ $title, $label, '', '', '', (bool)$time, $handlerParams, $currentExists
);
} else {
self::processResponsiveImages( $file, $thumb, $handlerParams );
@@ -749,7 +754,7 @@ class Linker {
$label = $frameParams['alt'] ?? '';
}
$s .= self::makeBrokenImageLinkObj(
- $title, $label, '', '', '', (bool)$time, $handlerParams
+ $title, $label, '', '', '', (bool)$time, $handlerParams, false
);
$zoomIcon = '';
} elseif ( !$thumb ) {
@@ -757,9 +762,9 @@ class Linker {
if ( $enableLegacyMediaDOM ) {
$s .= wfMessage( 'thumbnail_error', '' )->escaped();
} else {
- $label = $frameParams['alt'] ?? '';
+ $label = wfMessage( 'thumbnail_error', '' )->text();
$s .= self::makeBrokenImageLinkObj(
- $title, $label, '', '', '', (bool)$time, $handlerParams
+ $title, $label, '', '', '', (bool)$time, $handlerParams, true
);
}
$zoomIcon = '';
@@ -861,11 +866,12 @@ class Linker {
* @param string $unused2 Unused parameter kept for b/c
* @param bool $time A file of a certain timestamp was requested
* @param array $handlerParams @since 1.36
+ * @param bool $currentExists @since 1.41
* @return string
*/
public static function makeBrokenImageLinkObj(
$title, $label = '', $query = '', $unused1 = '', $unused2 = '',
- $time = false, array $handlerParams = []
+ $time = false, array $handlerParams = [], bool $currentExists = false
) {
if ( !$title instanceof LinkTarget ) {
wfWarn( __METHOD__ . ': Requires $title to be a LinkTarget object.' );
@@ -894,8 +900,8 @@ class Linker {
}
$repoGroup = $services->getRepoGroup();
- $currentExists = $time
- && $repoGroup->findFile( $title ) !== false;
+ $currentExists = $currentExists ||
+ ( $time && $repoGroup->findFile( $title ) !== false );
if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
&& !$currentExists