00001 <?php 00018 class FileDuplicateSearchPage extends QueryPage { 00019 var $hash, $filename; 00020 00021 function FileDuplicateSearchPage( $hash, $filename ) { 00022 $this->hash = $hash; 00023 $this->filename = $filename; 00024 } 00025 00026 function getName() { return 'FileDuplicateSearch'; } 00027 function isExpensive() { return false; } 00028 function isSyndicated() { return false; } 00029 00030 function linkParameters() { 00031 return array( 'filename' => $this->filename ); 00032 } 00033 00034 function getSQL() { 00035 $dbr = wfGetDB( DB_SLAVE ); 00036 $image = $dbr->tableName( 'image' ); 00037 $hash = $dbr->addQuotes( $this->hash ); 00038 00039 return "SELECT 'FileDuplicateSearch' AS type, 00040 img_name AS title, 00041 img_sha1 AS value, 00042 img_user_text, 00043 img_timestamp 00044 FROM $image 00045 WHERE img_sha1 = $hash 00046 "; 00047 } 00048 00049 function formatResult( $skin, $result ) { 00050 global $wgContLang, $wgLang; 00051 00052 $nt = Title::makeTitle( NS_FILE, $result->title ); 00053 $text = $wgContLang->convert( $nt->getText() ); 00054 $plink = $skin->makeLink( $nt->getPrefixedText(), $text ); 00055 00056 $user = $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text ); 00057 $time = $wgLang->timeanddate( $result->img_timestamp ); 00058 00059 return "$plink . . $user . . $time"; 00060 } 00061 } 00062 00066 function wfSpecialFileDuplicateSearch( $par = null ) { 00067 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript; 00068 00069 $hash = ''; 00070 $filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' ); 00071 00072 $title = Title::newFromText( $filename ); 00073 if( $title && $title->getText() != '' ) { 00074 $dbr = wfGetDB( DB_SLAVE ); 00075 $image = $dbr->tableName( 'image' ); 00076 $encFilename = $dbr->addQuotes( htmlspecialchars( $title->getDBKey() ) ); 00077 $sql = "SELECT img_sha1 from $image where img_name = $encFilename"; 00078 $res = $dbr->query( $sql ); 00079 $row = $dbr->fetchRow( $res ); 00080 if( $row !== false ) { 00081 $hash = $row[0]; 00082 } 00083 $dbr->freeResult( $res ); 00084 } 00085 00086 # Create the input form 00087 $wgOut->addHTML( 00088 Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) . 00089 Xml::hidden( 'title', SpecialPage::getTitleFor( 'FileDuplicateSearch' )->getPrefixedDbKey() ) . 00090 Xml::openElement( 'fieldset' ) . 00091 Xml::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) . 00092 Xml::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $filename ) . ' ' . 00093 Xml::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) . 00094 Xml::closeElement( 'fieldset' ) . 00095 Xml::closeElement( 'form' ) 00096 ); 00097 00098 if( $hash != '' ) { 00099 $align = $wgContLang->isRtl() ? 'left' : 'right'; 00100 00101 # Show a thumbnail of the file 00102 $img = wfFindFile( $title ); 00103 if ( $img ) { 00104 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) ); 00105 if( $thumb ) { 00106 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' . 00107 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' . 00108 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ), 00109 $wgLang->formatNum( $img->getWidth() ), 00110 $wgLang->formatNum( $img->getHeight() ), 00111 $wgLang->formatSize( $img->getSize() ), 00112 $img->getMimeType() 00113 ) . 00114 '</div>' ); 00115 } 00116 } 00117 00118 # Do the query 00119 $wpp = new FileDuplicateSearchPage( $hash, $filename ); 00120 list( $limit, $offset ) = wfCheckLimits(); 00121 $count = $wpp->doQuery( $offset, $limit ); 00122 00123 # Show a short summary 00124 if( $count == 1 ) { 00125 $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-1">' . 00126 wfMsgHtml( 'fileduplicatesearch-result-1', $filename ) . 00127 '</p>' 00128 ); 00129 } elseif ( $count > 1 ) { 00130 $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-n">' . 00131 wfMsgExt( 'fileduplicatesearch-result-n', array( 'parseinline' ), $filename, $wgLang->formatNum( $count - 1 ) ) . 00132 '</p>' 00133 ); 00134 } 00135 } 00136 }