Index: trunk/phase3/includes/ImagePage.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | /* private */ var $img; // Image object this page is shown for |
20 | 20 | /* private */ var $repo; |
21 | 21 | var $mExtraDescription = false; |
| 22 | + var $dupes; |
22 | 23 | |
23 | 24 | function __construct( $title, $time = false ) { |
24 | 25 | parent::__construct( $title ); |
— | — | @@ -28,7 +29,8 @@ |
29 | 30 | } else { |
30 | 31 | $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img; |
31 | 32 | } |
32 | | - $this->repo = $this->img->repo; |
| 33 | + $this->repo = $this->img->getRepo(); |
| 34 | + $this->dupes = null; |
33 | 35 | } |
34 | 36 | |
35 | 37 | /** |
— | — | @@ -104,11 +106,15 @@ |
105 | 107 | $this->closeShowImage(); |
106 | 108 | $this->imageHistory(); |
107 | 109 | // TODO: Cleanup the following |
108 | | - $this->imageLinks(); |
| 110 | + |
| 111 | + $wgOut->addHTML( Xml::element( 'h2', |
| 112 | + array( 'id' => 'filelinks' ), |
| 113 | + wfMsg( 'imagelinks' ) ) . "\n" ); |
109 | 114 | $this->imageDupes(); |
110 | 115 | // TODO: We may want to find local images redirecting to a foreign |
111 | 116 | // file: "The following local files redirect to this file" |
112 | | - if ( $this->img->isLocal() ) $this->imageRedirects(); |
| 117 | + if ( $this->img->isLocal() ) $this->imageRedirects(); |
| 118 | + $this->imageLinks(); |
113 | 119 | |
114 | 120 | if ( $showmeta ) { |
115 | 121 | global $wgStylePath, $wgStyleVersion; |
— | — | @@ -155,6 +161,28 @@ |
156 | 162 | public function getFile() { |
157 | 163 | return $this->img; |
158 | 164 | } |
| 165 | + |
| 166 | + public function getDuplicates() { |
| 167 | + if ( !is_null($this->dupes) ) return $this->dupes; |
| 168 | + |
| 169 | + if ( !( $hash = $this->img->getSha1() ) ) |
| 170 | + return $this->dupes = array(); |
| 171 | + $dupes = RepoGroup::singleton()->findBySha1( $hash ); |
| 172 | + |
| 173 | + // Remove duplicates with self and non matching file sizes |
| 174 | + $self = $this->img->getRepoName().':'.$this->img->getName(); |
| 175 | + $size = $this->img->getSize(); |
| 176 | + foreach ( $dupes as $index => $file ) { |
| 177 | + $key = $file->getRepoName().':'.$file->getName(); |
| 178 | + if ( $key == $self ) |
| 179 | + unset( $dupes[$index] ); |
| 180 | + if ( $file->getSize() != $size ) |
| 181 | + unset( $dupes[$index] ); |
| 182 | + } |
| 183 | + return $this->dupes = $dupes; |
| 184 | + |
| 185 | + } |
| 186 | + |
159 | 187 | |
160 | 188 | /** |
161 | 189 | * Create the TOC |
— | — | @@ -438,6 +466,9 @@ |
439 | 467 | } |
440 | 468 | } |
441 | 469 | |
| 470 | + /* |
| 471 | + * Check for files with the same name on the foreign repos. |
| 472 | + */ |
442 | 473 | function checkSharedConflict() { |
443 | 474 | global $wgOut, $wgUser; |
444 | 475 | $repoGroup = RepoGroup::singleton(); |
— | — | @@ -561,8 +592,6 @@ |
562 | 593 | |
563 | 594 | $limit = 100; |
564 | 595 | |
565 | | - $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" ); |
566 | | - |
567 | 596 | $dbr = wfGetDB( DB_SLAVE ); |
568 | 597 | |
569 | 598 | $res = $dbr->select( |
— | — | @@ -603,53 +632,26 @@ |
604 | 633 | { |
605 | 634 | global $wgUser, $wgOut; |
606 | 635 | |
607 | | - $dbr = wfGetDB( DB_SLAVE ); |
608 | | - $res = $dbr->select( |
609 | | - array( 'redirect', 'page' ), |
610 | | - array( 'page_title' ), |
611 | | - array( |
612 | | - 'rd_namespace' => NS_IMAGE, |
613 | | - 'rd_title' => $this->mTitle->getDBkey(), |
614 | | - 'page_namespace' => NS_IMAGE, |
615 | | - 'rd_from = page_id' |
616 | | - ), |
617 | | - __METHOD__ |
618 | | - ); |
| 636 | + $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE ); |
| 637 | + if ( count( $redirects ) == 0 ) return; |
619 | 638 | |
620 | 639 | |
621 | | - if ( 0 == $dbr->numRows( $res ) ) |
622 | | - return; |
623 | | - |
624 | 640 | $wgOut->addWikiMsg( 'redirectstofile' ); |
625 | 641 | $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" ); |
626 | 642 | |
627 | 643 | $sk = $wgUser->getSkin(); |
628 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
629 | | - $name = Title::makeTitle( NS_IMAGE, $row->page_title ); |
630 | | - $link = $sk->makeKnownLinkObj( $name, "" ); |
631 | | - wfDebug("Image redirect: {$row->page_title}\n"); |
| 644 | + foreach ( $redirects as $title ) { |
| 645 | + $link = $sk->makeKnownLinkObj( $title, "" ); |
632 | 646 | $wgOut->addHTML( "<li>{$link}</li>\n" ); |
633 | 647 | } |
634 | 648 | $wgOut->addHTML( "</ul>\n" ); |
635 | | - |
636 | | - $res->free(); |
| 649 | + |
637 | 650 | } |
638 | 651 | |
639 | 652 | function imageDupes() { |
640 | 653 | global $wgOut, $wgUser; |
641 | 654 | |
642 | | - if ( !( $hash = $this->img->getSha1() ) ) return; |
643 | | - // Probably deprecates checkSharedConflict? |
644 | | - $dupes = RepoGroup::singleton()->findBySha1( $hash ); |
645 | | - //$dupes = RepoGroup::singleton()->getLocalRepo()->findBySha1( $hash ); |
646 | | - |
647 | | - // Don't dupe with self |
648 | | - $self = $this->img->getRepoName().':'.$this->img->getName(); |
649 | | - foreach ( $dupes as $index => $file ) { |
650 | | - $key = $file->getRepoName().':'.$file->getName(); |
651 | | - if ( $key == $self ) |
652 | | - unset( $dupes[$index] ); |
653 | | - } |
| 655 | + $dupes = $this->getDuplicates(); |
654 | 656 | if ( count( $dupes ) == 0 ) return; |
655 | 657 | |
656 | 658 | $wgOut->addWikiMsg( 'duplicatesoffile' ); |
Index: trunk/phase3/includes/filerepo/File.php |
— | — | @@ -904,6 +904,12 @@ |
905 | 905 | function getRepoName() { |
906 | 906 | return $this->repo ? $this->repo->getName() : 'unknown'; |
907 | 907 | } |
| 908 | + /* |
| 909 | + * Returns the repository |
| 910 | + */ |
| 911 | + function getRepo() { |
| 912 | + return $this->repo; |
| 913 | + } |
908 | 914 | |
909 | 915 | /** |
910 | 916 | * Returns true if the image is an old version |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -3126,12 +3126,25 @@ |
3127 | 3127 | return MWNamespace::isContent( $this->getNamespace() ); |
3128 | 3128 | } |
3129 | 3129 | |
3130 | | - public function getRedirectsHere() { |
| 3130 | + public function getRedirectsHere( $ns = null ) { |
3131 | 3131 | $redirs = array(); |
3132 | | - $dbr = wfGetDB( DB_SLAVE ); |
3133 | | - list($page,$redirect) = $dbr->tableNamesN( 'page', 'redirect' ); |
3134 | | - $result = $dbr->query( "SELECT page_title, page_namespace FROM $page JOIN $redirect ON page_id = rd_from WHERE rd_title = " |
3135 | | - . $dbr->addQuotes( $this->getDBKey() ) . " AND rd_namespace = " . $this->getNamespace(), __METHOD__ ); |
| 3132 | + |
| 3133 | + $dbr = wfGetDB( DB_SLAVE ); |
| 3134 | + $where = array( |
| 3135 | + 'rd_namespace' => $this->getNamespace(), |
| 3136 | + 'rd_title' => $this->getDBkey(), |
| 3137 | + 'rd_from = page_id' |
| 3138 | + ); |
| 3139 | + if ( !is_null($ns) ) $where['page_namespace'] = $ns; |
| 3140 | + |
| 3141 | + $result = $dbr->select( |
| 3142 | + array( 'redirect', 'page' ), |
| 3143 | + array( 'page_namespace', 'page_title' ), |
| 3144 | + $where, |
| 3145 | + __METHOD__ |
| 3146 | + ); |
| 3147 | + |
| 3148 | + |
3136 | 3149 | while( $row = $dbr->fetchObject( $result ) ) { |
3137 | 3150 | $redirs[] = self::newFromRow( $row ); |
3138 | 3151 | } |