Force isCached() to false; otherwise the result is "This page is disabled for perform...
[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 function isCached() { return false; }
41
42 function linkParameters() {
43 return array( 'filename' => $this->filename );
44 }
45
46 function getQueryInfo() {
47 return array(
48 'tables' => array( 'image' ),
49 'fields' => array(
50 'img_name AS title',
51 'img_sha1 AS value',
52 'img_user_text',
53 'img_timestamp'
54 ),
55 'conds' => array( 'img_sha1' => $this->hash )
56 );
57 }
58
59 function execute( $par ) {
60 global $wgRequest, $wgOut, $wgLang, $wgContLang, $wgScript;
61
62 $this->setHeaders();
63 $this->outputHeader();
64
65 $this->filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' );
66 $this->hash = '';
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__ );
71 }
72
73 # Create the input form
74 $wgOut->addHTML(
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' )
83 );
84
85 if( $this->hash != '' ) {
86 $align = $wgContLang->alignEnd();
87
88 # Show a thumbnail of the file
89 $img = wfFindFile( $title );
90 if ( $img ) {
91 $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
92 if( $thumb ) {
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() ),
99 $img->getMimeType()
100 ) .
101 '</div>' );
102 }
103 }
104
105 parent::execute( $par );
106
107 # Show a short summary
108 if( $this->numRows == 1 ) {
109 $wgOut->wrapWikiMsg(
110 "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
111 array( 'fileduplicatesearch-result-1', $this->filename )
112 );
113 } elseif ( $this->numRows > 1 ) {
114 $wgOut->wrapWikiMsg(
115 "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
116 array( 'fileduplicatesearch-result-n', $this->filename,
117 $wgLang->formatNum( $this->numRows - 1 ) )
118 );
119 }
120 }
121 }
122
123 function formatResult( $skin, $result ) {
124 global $wgContLang, $wgLang;
125
126 $nt = Title::makeTitle( NS_FILE, $result->title );
127 $text = $wgContLang->convert( $nt->getText() );
128 $plink = $skin->link(
129 Title::newFromText( $nt->getPrefixedText() ),
130 $text
131 );
132
133 $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
134 $time = $wgLang->timeanddate( $result->img_timestamp );
135
136 return "$plink . . $user . . $time";
137 }
138 }