Making missing old files not try to render a thumbnail
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 3 Aug 2014 04:10:01 +0000 (01:10 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Sun, 3 Aug 2014 04:18:45 +0000 (01:18 -0300)
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
includes/filerepo/file/OldLocalFile.php
includes/page/ImagePage.php

index c6da1f1..d81bedc 100644 (file)
@@ -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;
index 0adcc73..710058f 100644 (file)
@@ -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();
+       }
 }
index 380252f..5811f63 100644 (file)
@@ -1329,6 +1329,9 @@ class ImageHistoryList extends ContextSource {
                                $url = $lang->userTimeAndDate( $timestamp, $user );
                        }
                        $row .= '<span class="history-deleted">' . $url . '</span>';
+               } elseif ( !$file->exists() ) {
+                       $row .= '<span class="mw-file-missing">'
+                               . $lang->userTimeAndDate( $timestamp, $user ) . '</span>';
                } else {
                        $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
                        $row .= Xml::element(