4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * A special page to search for files by hash value as defined in the
22 * img_sha1 field in the image table
25 * @ingroup SpecialPage
27 * @author Raimond Spekking, based on Special:MIMESearch by Ævar Arnfjörð Bjarmason
31 * Searches the database for files of the requested hash, comparing this with the
32 * 'img_sha1' field in the image table.
33 * @ingroup SpecialPage
35 class FileDuplicateSearchPage
extends QueryPage
{
38 function FileDuplicateSearchPage( $hash, $filename ) {
40 $this->filename
= $filename;
43 function getName() { return 'FileDuplicateSearch'; }
44 function isExpensive() { return false; }
45 function isSyndicated() { return false; }
47 function linkParameters() {
48 return array( 'filename' => $this->filename
);
52 $dbr = wfGetDB( DB_SLAVE
);
53 $image = $dbr->tableName( 'image' );
54 $hash = $dbr->addQuotes( $this->hash
);
56 return "SELECT 'FileDuplicateSearch' AS type,
62 WHERE img_sha1 = $hash
66 function formatResult( $skin, $result ) {
67 global $wgContLang, $wgLang;
69 $nt = Title
::makeTitle( NS_FILE
, $result->title
);
70 $text = $wgContLang->convert( $nt->getText() );
72 Title
::newFromText( $nt->getPrefixedText() ),
76 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
77 $time = $wgLang->timeanddate( $result->img_timestamp
);
79 return "$plink . . $user . . $time";
84 * Output the HTML search form, and constructs the FileDuplicateSearch object.
86 function wfSpecialFileDuplicateSearch( $par = null ) {
87 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
90 $filename = isset( $par ) ?
$par : $wgRequest->getText( 'filename' );
92 $title = Title
::newFromText( $filename );
93 if( $title && $title->getText() != '' ) {
94 $dbr = wfGetDB( DB_SLAVE
);
95 $image = $dbr->tableName( 'image' );
96 $encFilename = $dbr->addQuotes( htmlspecialchars( $title->getDBkey() ) );
97 $sql = "SELECT img_sha1 from $image where img_name = $encFilename";
98 $res = $dbr->query( $sql );
99 $row = $dbr->fetchRow( $res );
100 if( $row !== false ) {
105 # Create the input form
107 Xml
::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
108 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'FileDuplicateSearch' )->getPrefixedDbKey() ) .
109 Xml
::openElement( 'fieldset' ) .
110 Xml
::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
111 Xml
::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $filename ) . ' ' .
112 Xml
::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
113 Xml
::closeElement( 'fieldset' ) .
114 Xml
::closeElement( 'form' )
118 $align = $wgContLang->alignEnd();
120 # Show a thumbnail of the file
121 $img = wfFindFile( $title );
123 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
125 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
126 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
127 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
128 $wgLang->formatNum( $img->getWidth() ),
129 $wgLang->formatNum( $img->getHeight() ),
130 $wgLang->formatSize( $img->getSize() ),
138 $wpp = new FileDuplicateSearchPage( $hash, $filename );
139 list( $limit, $offset ) = wfCheckLimits();
140 $count = $wpp->doQuery( $offset, $limit );
142 # Show a short summary
145 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
146 array( 'fileduplicatesearch-result-1', $filename )
148 } elseif ( $count > 1 ) {
150 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
151 array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) )