From d089ca524fe6592813d503ed6119db0410ef3fbf Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 9 Mar 2008 03:10:28 +0000 Subject: [PATCH] Slowly merge in a few rev_deleted checks --- includes/filerepo/File.php | 11 +++++++++++ includes/filerepo/FileRepo.php | 11 ++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 5172ad0fc6..c129ae3c4e 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -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; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index ee7691a6e0..bd2caf003b 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -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; } /** -- 2.20.1