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
{
32 protected $hash, $filename;
34 function __construct( $name = 'FileDuplicateSearch' ) {
35 parent
::__construct( $name );
38 function isSyndicated() { return false; }
39 function isCacheable() { return false; }
40 function isCached() { return false; }
42 function linkParameters() {
43 return array( 'filename' => $this->filename
);
46 function getQueryInfo() {
48 'tables' => array( 'image' ),
55 'conds' => array( 'img_sha1' => $this->hash
)
59 function execute( $par ) {
60 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
63 $this->outputHeader();
65 $this->filename
= isset( $par ) ?
$par : $wgRequest->getText( 'filename' );
67 $title = Title
::makeTitleSafe( NS_FILE
, $this->filename
);
68 if( $title && $title->getText() != '' ) {
69 $dbr = wfGetDB( DB_SLAVE
);
70 $this->hash
= $dbr->selectField( 'image', 'img_sha1', array( 'img_name' => $title->getDBkey() ), __METHOD__
);
73 # Create the input form
75 Xml
::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
76 Html
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
77 Xml
::openElement( 'fieldset' ) .
78 Xml
::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
79 Xml
::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $this->filename
) . ' ' .
80 Xml
::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
81 Xml
::closeElement( 'fieldset' ) .
82 Xml
::closeElement( 'form' )
85 if( $this->hash
!= '' ) {
86 $align = $wgContLang->alignEnd();
88 # Show a thumbnail of the file
89 $img = wfFindFile( $title );
91 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
93 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
94 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
95 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
96 $wgLang->formatNum( $img->getWidth() ),
97 $wgLang->formatNum( $img->getHeight() ),
98 $wgLang->formatSize( $img->getSize() ),
105 parent
::execute( $par );
107 # Show a short summary
108 if( $this->numRows
== 1 ) {
110 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
111 array( 'fileduplicatesearch-result-1', $this->filename
)
113 } elseif ( $this->numRows
> 1 ) {
115 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
116 array( 'fileduplicatesearch-result-n', $this->filename
,
117 $wgLang->formatNum( $this->numRows
- 1 ) )
123 function formatResult( $skin, $result ) {
124 global $wgContLang, $wgLang;
126 $nt = Title
::makeTitle( NS_FILE
, $result->title
);
127 $text = $wgContLang->convert( $nt->getText() );
128 $plink = $skin->link(
129 Title
::newFromText( $nt->getPrefixedText() ),
133 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
134 $time = $wgLang->timeanddate( $result->img_timestamp
);
136 return "$plink . . $user . . $time";