Stop profiling before ending the function
[lhc/web/wiklou.git] / includes / ImagePage.php
index 6206b1c..3b8a1f5 100644 (file)
@@ -81,6 +81,8 @@ class ImagePage extends Article {
                                $wgOut->addWikiText( $fol );
                        }
                        $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
+               } else {
+                       $this->checkSharedConflict();
                }
 
                $this->closeShowImage();
@@ -373,6 +375,45 @@ EOT
                }
        }
 
+       function checkSharedConflict() {
+               global $wgOut, $wgUser;
+               $repoGroup = RepoGroup::singleton();
+               if( !$repoGroup->hasForeignRepos() ) {
+                       return;
+               }
+               if( !$this->img->isLocal() ) {
+                       return;
+               }
+
+               $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())
+               );
+
+               $sk = $wgUser->getSkin();
+               $descUrl = $dupfile->getDescriptionUrl();
+               if( $same ) {
+                       $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
+                       $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
+               } else {
+                       $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
+                       $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
+               }
+       }
+
+       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() ) );