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->link(
00055 Title::newFromText( $nt->getPrefixedText() ),
00056 $text
00057 );
00058
00059 $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
00060 $time = $wgLang->timeanddate( $result->img_timestamp );
00061
00062 return "$plink . . $user . . $time";
00063 }
00064 }
00065
00069 function wfSpecialFileDuplicateSearch( $par = null ) {
00070 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
00071
00072 $hash = '';
00073 $filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' );
00074
00075 $title = Title::newFromText( $filename );
00076 if( $title && $title->getText() != '' ) {
00077 $dbr = wfGetDB( DB_SLAVE );
00078 $image = $dbr->tableName( 'image' );
00079 $encFilename = $dbr->addQuotes( htmlspecialchars( $title->getDBkey() ) );
00080 $sql = "SELECT img_sha1 from $image where img_name = $encFilename";
00081 $res = $dbr->query( $sql );
00082 $row = $dbr->fetchRow( $res );
00083 if( $row !== false ) {
00084 $hash = $row[0];
00085 }
00086 $dbr->freeResult( $res );
00087 }
00088
00089 # Create the input form
00090 $wgOut->addHTML(
00091 Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
00092 Xml::hidden( 'title', SpecialPage::getTitleFor( 'FileDuplicateSearch' )->getPrefixedDbKey() ) .
00093 Xml::openElement( 'fieldset' ) .
00094 Xml::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
00095 Xml::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $filename ) . ' ' .
00096 Xml::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
00097 Xml::closeElement( 'fieldset' ) .
00098 Xml::closeElement( 'form' )
00099 );
00100
00101 if( $hash != '' ) {
00102 $align = $wgContLang->alignEnd();
00103
00104 # Show a thumbnail of the file
00105 $img = wfFindFile( $title );
00106 if ( $img ) {
00107 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
00108 if( $thumb ) {
00109 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
00110 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
00111 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
00112 $wgLang->formatNum( $img->getWidth() ),
00113 $wgLang->formatNum( $img->getHeight() ),
00114 $wgLang->formatSize( $img->getSize() ),
00115 $img->getMimeType()
00116 ) .
00117 '</div>' );
00118 }
00119 }
00120
00121 # Do the query
00122 $wpp = new FileDuplicateSearchPage( $hash, $filename );
00123 list( $limit, $offset ) = wfCheckLimits();
00124 $count = $wpp->doQuery( $offset, $limit );
00125
00126 # Show a short summary
00127 if( $count == 1 ) {
00128 $wgOut->wrapWikiMsg(
00129 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
00130 array( 'fileduplicatesearch-result-1', $filename )
00131 );
00132 } elseif ( $count > 1 ) {
00133 $wgOut->wrapWikiMsg(
00134 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
00135 array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) )
00136 );
00137 }
00138 }
00139 }