From 14c580577413106b98e307ad36ca6fe782d42f00 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 3 Aug 2014 01:10:01 -0300 Subject: [PATCH] Making missing old files not try to render a thumbnail Unfortunately there's a couple files on commons where the old version of the file is missing. They can be found by looking for an oi_archive_name of an empty string. In the case of such a file, make sure that the exists method returns false (since it doesn't exist on disk). Additionally make canRender() return false if the file does not exist (Can't render what doesn't exist). Last of all make ImagePage not link to the original file if exist() is false. This will make pages like [[File:Resilient_Barnstar.png]], [[File:GeorgeWBush.jpg]] etc not link to the old version if the link would be broken, and not show a thumbnail (Sometimes this is already the case, since lots of these broken files have a width and height of 0). There are currently 12,895 broken old versions of files on commons. Bug: 22847 Change-Id: Ic376a9996d95a1218eee4da5800dac9ada7b7725 --- includes/filerepo/file/File.php | 2 +- includes/filerepo/file/OldLocalFile.php | 14 ++++++++++++++ includes/page/ImagePage.php | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index c6da1f18b4..d81bedcf65 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -714,7 +714,7 @@ abstract class File { */ function canRender() { if ( !isset( $this->canRender ) ) { - $this->canRender = $this->getHandler() && $this->handler->canRender( $this ); + $this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists(); } return $this->canRender; diff --git a/includes/filerepo/file/OldLocalFile.php b/includes/filerepo/file/OldLocalFile.php index 0adcc73c62..710058fba6 100644 --- a/includes/filerepo/file/OldLocalFile.php +++ b/includes/filerepo/file/OldLocalFile.php @@ -404,4 +404,18 @@ class OldLocalFile extends LocalFile { return true; } + + /** + * If archive name is an empty string, then file does not "exist" + * + * This is the case for a couple files on Wikimedia servers where + * the old version is "lost". + */ + public function exists() { + $archiveName = $this->getArchiveName(); + if ( $archiveName === '' || !is_string( $archiveName ) ) { + return false; + } + return parent::exists(); + } } diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 380252f58a..5811f63185 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -1329,6 +1329,9 @@ class ImageHistoryList extends ContextSource { $url = $lang->userTimeAndDate( $timestamp, $user ); } $row .= '' . $url . ''; + } elseif ( !$file->exists() ) { + $row .= '' + . $lang->userTimeAndDate( $timestamp, $user ) . ''; } else { $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); $row .= Xml::element( -- 2.20.1