From: Bryan Tong Minh Date: Wed, 14 May 2008 17:29:38 +0000 (+0000) Subject: * Create ForeignDBFile objects from ForeignDBRepo::findBySha1 X-Git-Tag: 1.31.0-rc.0~47631 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=b60e6666e9782191949e56dfab418b3d5decc64d;p=lhc%2Fweb%2Fwiklou.git * Create ForeignDBFile objects from ForeignDBRepo::findBySha1 * Add foreign duplicates to ImagePage --- diff --git a/includes/ImagePage.php b/includes/ImagePage.php index d9243bc2c2..cede6b0a60 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -639,19 +639,16 @@ EOT global $wgOut, $wgUser; if ( !( $hash = $this->img->getSha1() ) ) return; - // Should find a proper way to link to foreign files - // Deprecates checkSharedConflict - //$dupes = RepoGroup::singleton()->findBySha1( $hash ); - $dupes = RepoGroup::singleton()->getLocalRepo()->findBySha1( $hash ); + // Probably deprecates checkSharedConflict? + $dupes = RepoGroup::singleton()->findBySha1( $hash ); + //$dupes = RepoGroup::singleton()->getLocalRepo()->findBySha1( $hash ); // Don't dupe with self - $index = 0; $self = $this->img->getRepoName().':'.$this->img->getName(); - foreach ( $dupes as $file ) { + foreach ( $dupes as $index => $file ) { $key = $file->getRepoName().':'.$file->getName(); if ( $key == $self ) unset( $dupes[$index] ); - $index++; } if ( count( $dupes ) == 0 ) return; @@ -660,7 +657,11 @@ EOT $sk = $wgUser->getSkin(); foreach ( $dupes as $file ) { - $link = $sk->makeKnownLinkObj( $file->getTitle(), "" ); + if ( $file->isLocal() ) + $link = $sk->makeKnownLinkObj( $file->getTitle(), "" ); + else + $link = $sk->makeExternalLink( $file->getDescriptionUrl(), + $file->getTitle()->getPrefixedText() ); $wgOut->addHTML( "
  • {$link}
  • \n" ); } $wgOut->addHTML( "\n" ); diff --git a/includes/filerepo/ForeignDBFile.php b/includes/filerepo/ForeignDBFile.php index a8174b732e..882b276f7a 100644 --- a/includes/filerepo/ForeignDBFile.php +++ b/includes/filerepo/ForeignDBFile.php @@ -5,6 +5,17 @@ class ForeignDBFile extends LocalFile { return new self( $title, $repo ); } + /** + * Create a ForeignDBFile from a title + * Do not call this except from inside a repo class. + */ + static function newFromRow( $row, $repo ) { + $title = Title::makeTitle( NS_IMAGE, $row->img_name ); + $file = new self( $title, $repo ); + $file->loadFromRow( $row ); + return $file; + } + function getCacheKey() { if ( $this->repo->hasSharedCache ) { $hashedName = md5($this->name); diff --git a/includes/filerepo/ForeignDBRepo.php b/includes/filerepo/ForeignDBRepo.php index 3098b7acc5..017ded8cff 100644 --- a/includes/filerepo/ForeignDBRepo.php +++ b/includes/filerepo/ForeignDBRepo.php @@ -13,6 +13,12 @@ class ForeignDBRepo extends LocalRepo { var $dbConn; var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' ); + function newFileFromRow( $row ) { + if ( isset( $row->img_name ) ) + return ForeignDBFile::newFromRow( $row, $this ); + return parent::newFileFromRow( $row ); + } + function __construct( $info ) { parent::__construct( $info ); $this->dbType = $info['dbType'];