* Create ForeignDBFile objects from ForeignDBRepo::findBySha1
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 14 May 2008 17:29:38 +0000 (17:29 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 14 May 2008 17:29:38 +0000 (17:29 +0000)
* Add foreign duplicates to ImagePage

includes/ImagePage.php
includes/filerepo/ForeignDBFile.php
includes/filerepo/ForeignDBRepo.php

index d9243bc..cede6b0 100644 (file)
@@ -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( "<li>{$link}</li>\n" );
                }
                $wgOut->addHTML( "</ul>\n" );
index a8174b7..882b276 100644 (file)
@@ -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);
index 3098b7a..017ded8 100644 (file)
@@ -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'];