Refactor ImagePage::checkSharedConflict()
This commit is contained in:
parent
40da2bd661
commit
c6e6dd0764
2 changed files with 30 additions and 7 deletions
|
|
@ -376,19 +376,21 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSharedConflict() {
|
function checkSharedConflict() {
|
||||||
global $wgOut, $wgUser, $wgUseSharedUploads;
|
global $wgOut, $wgUser;
|
||||||
if( !$wgUseSharedUploads ) {
|
$repoGroup = RepoGroup::singleton();
|
||||||
|
if( !$repoGroup->hasForeignRepos() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( $this->repo->getName() != 'local' ) {
|
if( !$this->img->isLocal() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$repo = RepoGroup::singleton()->getRepoByName( 'shared' );
|
$this->dupFile = null;
|
||||||
$dupfile = $repo->newFile( $this->img->getTitle() );
|
$repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
|
||||||
if( !$dupfile->exists() ) {
|
|
||||||
|
if( !$this->dupFile )
|
||||||
return;
|
return;
|
||||||
}
|
$dupfile = $this->dupFile;
|
||||||
$same = (
|
$same = (
|
||||||
($this->img->getSha1() == $dupfile->getSha1()) &&
|
($this->img->getSha1() == $dupfile->getSha1()) &&
|
||||||
($this->img->getSize() == $dupfile->getSize())
|
($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() {
|
function getUploadUrl() {
|
||||||
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
|
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
|
||||||
return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
|
return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,20 @@ class RepoGroup {
|
||||||
return $this->getRepo( 'local' );
|
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
|
* Initialise the $repos array
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue