From ab378ca864e12d5fb9ded715534721bbf823d0b5 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 10 Jun 2009 01:47:58 +0000 Subject: [PATCH] Followup to r51592: * Implement fileExistsBatch() in the ForeignAPIRepo. * Tweak fileExists() to return the boolean from the single file we checked, not the file we were given. --- includes/filerepo/FileRepo.php | 2 +- includes/filerepo/ForeignAPIRepo.php | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index f359c83afa..48f9e5506c 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -403,7 +403,7 @@ abstract class FileRepo { function fileExists( $file, $flags = 0 ) { $result = $this->fileExistsBatch( array( $file ), $flags ); - return $file; + return $result[0]; } /** diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index cf7428a89b..cda3500556 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -21,6 +21,7 @@ class ForeignAPIRepo extends FileRepo { var $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' ); var $apiThumbCacheExpiry = 0; protected $mQueryCache = array(); + protected $mFileExists = array(); function __construct( $info ) { parent::__construct( $info ); @@ -57,8 +58,32 @@ class ForeignAPIRepo extends FileRepo { function deleteBatch( $sourceDestPairs ) { return false; } + + function fileExistsBatch( $files, $flags = 0 ) { - return false; + $results = array(); + foreach ( $files as $k => $f ) { + if ( isset( $this->mFileExists[$k] ) ) { + $results[$k] = true; + unset( $files[$k] ); + } elseif( self::isVirtualUrl( $f ) ) { + # TODO! FIXME! We need to be able to handle virtual + # URLs better, at least when we know they refer to the + # same repo. + $results[$k] = false; + unset( $files[$k] ); + } + } + + $results = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ), + 'prop' => 'imageinfo' ) ); + if( isset( $data['query']['pages'] ) ) { + $i = 0; + foreach( $files as $key => $file ) { + $results[$key] = $this->mFileExists[$key] = !isset( $data['query']['pages'][$i]['missing'] ); + $i++; + } + } } function getFileProps( $virtualUrl ) { return false; -- 2.20.1