Slowly merge in a few rev_deleted checks
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 9 Mar 2008 03:10:28 +0000 (03:10 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 9 Mar 2008 03:10:28 +0000 (03:10 +0000)
includes/filerepo/File.php
includes/filerepo/FileRepo.php

index 5172ad0..c129ae3 100644 (file)
@@ -378,6 +378,17 @@ abstract class File {
                return $this->getPath() && file_exists( $this->path );
        }
 
+       /**
+        * Returns true if file exists in the repository and can be included in a page.
+        * It would be unsafe to include private images, making public thumbnails inadvertently
+        *
+        * @return boolean Whether file exists in the repository and is includable.
+        * @public
+        */
+       function isVisible() { 
+               return $this->exists();
+       }
+
        function getTransformScript() {
                if ( !isset( $this->transformScript ) ) {
                        $this->transformScript = false;
index ee7691a..bd2caf0 100644 (file)
@@ -6,6 +6,7 @@
  */
 abstract class FileRepo {
        const DELETE_SOURCE = 1;
+       const FIND_PRIVATE = 1;
        const OVERWRITE = 2;
        const OVERWRITE_SAME = 4;
 
@@ -76,7 +77,7 @@ abstract class FileRepo {
         *
         * @param mixed $time 14-character timestamp, or false for the current version
         */
-       function findFile( $title, $time = false ) {
+       function findFile( $title, $time = false, $flags = 0 ) {
                # First try the current version of the file to see if it precedes the timestamp
                $img = $this->newFile( $title );
                if ( !$img ) {
@@ -88,9 +89,12 @@ abstract class FileRepo {
                # Now try an old version of the file
                $img = $this->newFile( $title, $time );
                if ( $img->exists() ) {
-                       return $img;
+                       if ( !$img->isDeleted(File::DELETED_FILE) ) {
+                               return $img;
+                       } else if ( ($flags & FileRepo::FIND_PRIVATE) && $img->userCan(File::DELETED_FILE) ) {
+                               return $img;
+                       }
                }
-
                # Now try redirects
                $redir = $this->checkRedirect( $title );
                if( $redir && $redir->getNamespace() == NS_IMAGE) {
@@ -103,6 +107,7 @@ abstract class FileRepo {
                                return $img;
                        }
                }
+               return false;
        }
 
        /**