Follow-up r79964: Use the existing message 'parentheses' instead of introducing an...
[lhc/web/wiklou.git] / includes / specials / SpecialFileDuplicateSearch.php
1 <?php
2 /**
3 * Implements Special:FileDuplicateSearch
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 * @author Raimond Spekking, based on Special:MIMESearch by Ævar Arnfjörð Bjarmason
23 */
24
25 /**
26 * Searches the database for files of the requested hash, comparing this with the
27 * 'img_sha1' field in the image table.
28 *
29 * @ingroup SpecialPage
30 */
31 class FileDuplicateSearchPage extends QueryPage {
32 protected $hash, $filename;
33
34 function __construct( $name = 'FileDuplicateSearch' ) {
35 parent::__construct( $name );
36 }
37
38 function isSyndicated() { return false; }
39 function isCacheable() { return false; }
40
41 function linkParameters() {
42 return array( 'filename' => $this->filename );
43 }
44
45 function getQueryInfo() {
46 return array(
47 'tables' => array( 'image' ),
48 'fields' => array(
49 'img_name AS title',
50 'img_sha1 AS value',
51 'img_user_text',
52 'img_timestamp'
53 ),
54 'conds' => array( 'img_sha1' => $this->hash )
55 );
56 }
57
58 function execute( $par ) {
59 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
60
61 $this->setHeaders();
62 $this->outputHeader();
63
64 $this->filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' );
65 $this->hash = '';
66 $title = Title::makeTitleSafe( NS_FILE, $this->filename );
67 if( $title && $title->getText() != '' ) {
68 $dbr = wfGetDB( DB_SLAVE );
69 $this->hash = $dbr->selectField( 'image', 'img_sha1', array( 'img_name' => $title->getDBkey() ), __METHOD__ );
70 }
71
72 # Create the input form
73 $wgOut->addHTML(
74 Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgScript ) ) .
75 Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
76 Xml::openElement( 'fieldset' ) .
77 Xml::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
78 Xml::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $this->filename ) . ' ' .
79 Xml::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
80 Xml::closeElement( 'fieldset' ) .
81 Xml::closeElement( 'form' )
82 );
83
84 if( $this->hash != '' ) {
85 $align = $wgContLang->alignEnd();
86
87 # Show a thumbnail of the file
88 $img = wfFindFile( $title );
89 if ( $img ) {
90 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
91 if( $thumb ) {
92 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
93 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
94 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
95 $wgLang->formatNum( $img->getWidth() ),
96 $wgLang->formatNum( $img->getHeight() ),
97 $wgLang->formatSize( $img->getSize() ),
98 $img->getMimeType()
99 ) .
100 '</div>' );
101 }
102 }
103
104 parent::execute( $par );
105
106 # Show a short summary
107 if( $this->numRows == 1 ) {
108 $wgOut->wrapWikiMsg(
109 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
110 array( 'fileduplicatesearch-result-1', $this->filename )
111 );
112 } elseif ( $this->numRows > 1 ) {
113 $wgOut->wrapWikiMsg(
114 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
115 array( 'fileduplicatesearch-result-n', $this->filename,
116 $wgLang->formatNum( $this->numRows - 1 ) )
117 );
118 }
119 }
120 }
121
122 function formatResult( $skin, $result ) {
123 global $wgContLang, $wgLang;
124
125 $nt = Title::makeTitle( NS_FILE, $result->title );
126 $text = $wgContLang->convert( $nt->getText() );
127 $plink = $skin->link(
128 Title::newFromText( $nt->getPrefixedText() ),
129 $text
130 );
131
132 $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
133 $time = $wgLang->timeanddate( $result->img_timestamp );
134
135 return "$plink . . $user . . $time";
136 }
137 }