From c6e6dd0764ab3088e41ad8fb687b9c626f0f656c Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Thu, 1 May 2008 22:16:23 +0000 Subject: [PATCH] Refactor ImagePage::checkSharedConflict() --- includes/ImagePage.php | 23 ++++++++++++++++------- includes/filerepo/RepoGroup.php | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/includes/ImagePage.php b/includes/ImagePage.php index ddb8512441..3b8a1f5e20 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -376,19 +376,21 @@ EOT } function checkSharedConflict() { - global $wgOut, $wgUser, $wgUseSharedUploads; - if( !$wgUseSharedUploads ) { + global $wgOut, $wgUser; + $repoGroup = RepoGroup::singleton(); + if( !$repoGroup->hasForeignRepos() ) { return; } - if( $this->repo->getName() != 'local' ) { + if( !$this->img->isLocal() ) { return; } - $repo = RepoGroup::singleton()->getRepoByName( 'shared' ); - $dupfile = $repo->newFile( $this->img->getTitle() ); - if( !$dupfile->exists() ) { + $this->dupFile = null; + $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) ); + + if( !$this->dupFile ) return; - } + $dupfile = $this->dupFile; $same = ( ($this->img->getSha1() == $dupfile->getSha1()) && ($this->img->getSize() == $dupfile->getSize()) @@ -405,6 +407,13 @@ EOT } } + function checkSharedConflictCallback( $repo ) { + $dupfile = $repo->newFile( $this->img->getTitle() ); + if( $dupfile->exists() ) + $this->dupFile = $dupfile; + return $dupfile->exists(); + } + function getUploadUrl() { $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) ); diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index d96e5024b5..39e56883f3 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -134,6 +134,20 @@ class RepoGroup { return $this->getRepo( 'local' ); } + function forEachForeignRepo( $callback, $params = array() ) { + foreach( $this->foreignRepos as $repo ) { + $args = array_merge( array( $repo ), $params ); + if( call_user_func_array( $callback, $args ) ) { + return true; + } + } + return false; + } + + function hasForeignRepos() { + return !empty( $this->foreignRepos ); + } + /** * Initialise the $repos array */ -- 2.20.1