3 * Implements Special:FileDuplicateSearch
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
22 * @author Raimond Spekking, based on Special:MIMESearch by Ævar Arnfjörð Bjarmason
26 * Searches the database for files of the requested hash, comparing this with the
27 * 'img_sha1' field in the image table.
29 * @ingroup SpecialPage
31 class FileDuplicateSearchPage
extends QueryPage
{
34 function __construct( $hash, $filename ) {
36 $this->filename
= $filename;
39 function getName() { return 'FileDuplicateSearch'; }
40 function isExpensive() { return false; }
41 function isSyndicated() { return false; }
43 function linkParameters() {
44 return array( 'filename' => $this->filename
);
48 $dbr = wfGetDB( DB_SLAVE
);
49 $image = $dbr->tableName( 'image' );
50 $hash = $dbr->addQuotes( $this->hash
);
52 return "SELECT 'FileDuplicateSearch' AS type,
58 WHERE img_sha1 = $hash
62 function formatResult( $skin, $result ) {
63 global $wgContLang, $wgLang;
65 $nt = Title
::makeTitle( NS_FILE
, $result->title
);
66 $text = $wgContLang->convert( $nt->getText() );
68 Title
::newFromText( $nt->getPrefixedText() ),
72 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
73 $time = $wgLang->timeanddate( $result->img_timestamp
);
75 return "$plink . . $user . . $time";
80 * Output the HTML search form, and constructs the FileDuplicateSearch object.
82 function wfSpecialFileDuplicateSearch( $par = null ) {
83 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
86 $filename = isset( $par ) ?
$par : $wgRequest->getText( 'filename' );
88 $title = Title
::newFromText( $filename );
89 if( $title && $title->getText() != '' ) {
90 $dbr = wfGetDB( DB_SLAVE
);
91 $image = $dbr->tableName( 'image' );
92 $encFilename = $dbr->addQuotes( htmlspecialchars( $title->getDBkey() ) );
93 $sql = "SELECT img_sha1 from $image where img_name = $encFilename";
94 $res = $dbr->query( $sql );
95 $row = $dbr->fetchRow( $res );
96 if( $row !== false ) {
101 # Create the input form
103 Xml
::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
104 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'FileDuplicateSearch' )->getPrefixedDbKey() ) .
105 Xml
::openElement( 'fieldset' ) .
106 Xml
::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
107 Xml
::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $filename ) . ' ' .
108 Xml
::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
109 Xml
::closeElement( 'fieldset' ) .
110 Xml
::closeElement( 'form' )
114 $align = $wgContLang->alignEnd();
116 # Show a thumbnail of the file
117 $img = wfFindFile( $title );
119 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
121 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
122 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
123 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
124 $wgLang->formatNum( $img->getWidth() ),
125 $wgLang->formatNum( $img->getHeight() ),
126 $wgLang->formatSize( $img->getSize() ),
134 $wpp = new FileDuplicateSearchPage( $hash, $filename );
135 list( $limit, $offset ) = wfCheckLimits();
136 $count = $wpp->doQuery( $offset, $limit );
138 # Show a short summary
141 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
142 array( 'fileduplicatesearch-result-1', $filename )
144 } elseif ( $count > 1 ) {
146 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
147 array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) )