Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108062


Change subject: Extend FileRepo::findFile private option to accept a User object
......................................................................

Extend FileRepo::findFile private option to accept a User object

Callers may want to test visibility for a user other than $wgUser when
specifying the 'private' option. It seems a natural extension to allow
'private' to be a User object, with boolean true retaining its old
meaning of $wgUser.

Change-Id: Idbed0f3055c0135b5c11068de1bf1ef668e13456
---
M includes/filerepo/FileRepo.php
M includes/filerepo/LocalRepo.php
2 files changed, 15 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/62/108062/1

diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php
index cab5690..81529e7 100644
--- a/includes/filerepo/FileRepo.php
+++ b/includes/filerepo/FileRepo.php
@@ -416,7 +416,7 @@
         *   ignoreRedirect: If true, do not follow file redirects
         *   private:        If true, return restricted (deleted) files if the 
current
         *                   user is allowed to view them. Otherwise, such 
files will not
-        *                   be found.
+        *                   be found. If a User object, use that user instead 
of the current.
         * @return File|bool False on failure
         */
        public function findFile( $title, $options = array() ) {
@@ -439,7 +439,11 @@
                        if ( $img && $img->exists() ) {
                                if ( !$img->isDeleted( File::DELETED_FILE ) ) {
                                        return $img; // always OK
-                               } elseif ( !empty( $options['private'] ) && 
$img->userCan( File::DELETED_FILE ) ) {
+                               } elseif ( !empty( $options['private'] ) &&
+                                       $img->userCan( File::DELETED_FILE,
+                                               $options['private'] instanceof 
User ? $options['private'] : null
+                                       )
+                               ) {
                                        return $img;
                                }
                        }
@@ -536,7 +540,11 @@
                        if ( $img && $img->exists() ) {
                                if ( !$img->isDeleted( File::DELETED_FILE ) ) {
                                        return $img; // always OK
-                               } elseif ( !empty( $options['private'] ) && 
$img->userCan( File::DELETED_FILE ) ) {
+                               } elseif ( !empty( $options['private'] ) &&
+                                       $img->userCan( File::DELETED_FILE,
+                                               $options['private'] instanceof 
User ? $options['private'] : null
+                                       )
+                               ) {
                                        return $img;
                                }
                        }
diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php
index 1399c2b..99c0e09 100644
--- a/includes/filerepo/LocalRepo.php
+++ b/includes/filerepo/LocalRepo.php
@@ -260,6 +260,9 @@
 
                $fileMatchesSearch = function( File $file, array $search ) {
                        // Note: file name comparison done elsewhere (to handle 
redirects)
+                       $user = ( !empty( $search['private'] ) && 
$search['private'] instanceof User )
+                               ? $search['private']
+                               : null;
                        return (
                                $file->exists() &&
                                (
@@ -267,7 +270,7 @@
                                        ( !empty( $search['time'] ) && 
$search['time'] === $file->getTimestamp() )
                                ) &&
                                ( !empty( $search['private'] ) || 
!$file->isDeleted( File::DELETED_FILE ) ) &&
-                               $file->userCan( File::DELETED_FILE )
+                               $file->userCan( File::DELETED_FILE, $user )
                        );
                };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/108062
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idbed0f3055c0135b5c11068de1bf1ef668e13456
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to