MediaWiki
REL1_19
|
00001 <?php 00031 class FileDuplicateSearchPage extends QueryPage { 00032 protected $hash = '', $filename = ''; 00033 00037 protected $file = null; 00038 00039 function __construct( $name = 'FileDuplicateSearch' ) { 00040 parent::__construct( $name ); 00041 } 00042 00043 function isSyndicated() { return false; } 00044 function isCacheable() { return false; } 00045 function isCached() { return false; } 00046 00047 function linkParameters() { 00048 return array( 'filename' => $this->filename ); 00049 } 00050 00056 function getDupes() { 00057 return RepoGroup::singleton()->findBySha1( $this->hash ); 00058 } 00059 00064 function showList( $dupes ) { 00065 $html = array(); 00066 $html[] = $this->openList( 0 ); 00067 00068 foreach ( $dupes as $dupe ) { 00069 $line = $this->formatResult( null, $dupe ); 00070 $html[] = "<li>" . $line . "</li>"; 00071 } 00072 $html[] = $this->closeList(); 00073 00074 $this->getOutput()->addHtml( implode( "\n", $html ) ); 00075 } 00076 00077 function getQueryInfo() { 00078 return array( 00079 'tables' => array( 'image' ), 00080 'fields' => array( 00081 'img_name AS title', 00082 'img_sha1 AS value', 00083 'img_user_text', 00084 'img_timestamp' 00085 ), 00086 'conds' => array( 'img_sha1' => $this->hash ) 00087 ); 00088 } 00089 00090 function execute( $par ) { 00091 global $wgScript; 00092 00093 $this->setHeaders(); 00094 $this->outputHeader(); 00095 00096 $this->filename = isset( $par ) ? $par : $this->getRequest()->getText( 'filename' ); 00097 $this->file = null; 00098 $this->hash = ''; 00099 $title = Title::newFromText( $this->filename, NS_FILE ); 00100 if( $title && $title->getText() != '' ) { 00101 $this->file = wfFindFile( $title ); 00102 } 00103 00104 $out = $this->getOutput(); 00105 00106 # Create the input form 00107 $out->addHTML( 00108 Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) . 00109 Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . 00110 Xml::openElement( 'fieldset' ) . 00111 Xml::element( 'legend', null, $this->msg( 'fileduplicatesearch-legend' )->text() ) . 00112 Xml::inputLabel( $this->msg( 'fileduplicatesearch-filename' )->text(), 'filename', 'filename', 50, $this->filename ) . ' ' . 00113 Xml::submitButton( $this->msg( 'fileduplicatesearch-submit' )->text() ) . 00114 Xml::closeElement( 'fieldset' ) . 00115 Xml::closeElement( 'form' ) 00116 ); 00117 00118 if( $this->file ) { 00119 $this->hash = $this->file->getSha1(); 00120 } elseif( $this->filename !== '' ) { 00121 $out->wrapWikiMsg( 00122 "<p class='mw-fileduplicatesearch-noresults'>\n$1\n</p>", 00123 array( 'fileduplicatesearch-noresults', wfEscapeWikiText( $this->filename ) ) 00124 ); 00125 } 00126 00127 if( $this->hash != '' ) { 00128 # Show a thumbnail of the file 00129 $img = $this->file; 00130 if ( $img ) { 00131 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) ); 00132 if( $thumb ) { 00133 $out->addHTML( '<div id="mw-fileduplicatesearch-icon">' . 00134 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' . 00135 $this->msg( 'fileduplicatesearch-info' )->numParams( 00136 $img->getWidth(), $img->getHeight() )->params( 00137 $this->getLanguage()->formatSize( $img->getSize() ), 00138 $img->getMimeType() )->parseAsBlock() . 00139 '</div>' ); 00140 } 00141 } 00142 00143 $dupes = $this->getDupes(); 00144 $numRows = count( $dupes ); 00145 00146 # Show a short summary 00147 if( $numRows == 1 ) { 00148 $out->wrapWikiMsg( 00149 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>", 00150 array( 'fileduplicatesearch-result-1', wfEscapeWikiText( $this->filename ) ) 00151 ); 00152 } elseif ( $numRows ) { 00153 $out->wrapWikiMsg( 00154 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>", 00155 array( 'fileduplicatesearch-result-n', wfEscapeWikiText( $this->filename ), 00156 $this->getLanguage()->formatNum( $numRows - 1 ) ) 00157 ); 00158 } 00159 00160 $this->showList( $dupes ); 00161 } 00162 } 00163 00170 function formatResult( $skin, $result ) { 00171 global $wgContLang; 00172 00173 $nt = $result->getTitle(); 00174 $text = $wgContLang->convert( $nt->getText() ); 00175 $plink = Linker::link( 00176 Title::newFromText( $nt->getPrefixedText() ), 00177 $text 00178 ); 00179 00180 $userText = $result->getUser( 'text' ); 00181 $user = Linker::link( Title::makeTitle( NS_USER, $userText ), $userText ); 00182 $time = $this->getLanguage()->userTimeAndDate( $result->getTimestamp(), $this->getUser() ); 00183 00184 return "$plink . . $user . . $time"; 00185 } 00186 }