Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / SpecialFileDuplicateSearch.php
1 <?php
2 /**
3 * A special page to search for files by hash value as defined in the
4 * img_sha1 field in the image table
5 *
6 * @file
7 * @ingroup SpecialPage
8 *
9 * @author Raimond Spekking, based on Special:MIMESearch by Ævar Arnfjörð Bjarmason
10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11 */
12
13 /**
14 * Searches the database for files of the requested hash, comparing this with the
15 * 'img_sha1' field in the image table.
16 * @ingroup SpecialPage
17 */
18 class FileDuplicateSearchPage extends QueryPage {
19 var $hash, $filename;
20
21 function FileDuplicateSearchPage( $hash, $filename ) {
22 $this->hash = $hash;
23 $this->filename = $filename;
24 }
25
26 function getName() { return 'FileDuplicateSearch'; }
27 function isExpensive() { return false; }
28 function isSyndicated() { return false; }
29
30 function linkParameters() {
31 return array( 'filename' => $this->filename );
32 }
33
34 function getSQL() {
35 $dbr = wfGetDB( DB_SLAVE );
36 $image = $dbr->tableName( 'image' );
37 $hash = $dbr->addQuotes( $this->hash );
38
39 return "SELECT 'FileDuplicateSearch' AS type,
40 img_name AS title,
41 img_sha1 AS value,
42 img_user_text,
43 img_timestamp
44 FROM $image
45 WHERE img_sha1 = $hash
46 ";
47 }
48
49 function formatResult( $skin, $result ) {
50 global $wgContLang, $wgLang;
51
52 $nt = Title::makeTitle( NS_IMAGE, $result->title );
53 $text = $wgContLang->convert( $nt->getText() );
54 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
55
56 $user = $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
57 $time = $wgLang->timeanddate( $result->img_timestamp );
58
59 return "$plink . . $user . . $time";
60 }
61 }
62
63 /**
64 * Output the HTML search form, and constructs the FileDuplicateSearch object.
65 */
66 function wfSpecialFileDuplicateSearch( $par = null ) {
67 global $wgRequest, $wgTitle, $wgOut, $wgLang, $wgContLang;
68
69 $hash = '';
70 $filename = isset( $par ) ? $par : $wgRequest->getText( 'filename' );
71
72 $title = Title::newFromText( $filename );
73 if( $title && $title->getText() != '' ) {
74 $dbr = wfGetDB( DB_SLAVE );
75 $image = $dbr->tableName( 'image' );
76 $encFilename = $dbr->addQuotes( htmlspecialchars( $title->getDbKey() ) );
77 $sql = "SELECT img_sha1 from $image where img_name = $encFilename";
78 $res = $dbr->query( $sql );
79 $row = $dbr->fetchRow( $res );
80 if( $row !== false ) {
81 $hash = $row[0];
82 }
83 $dbr->freeResult( $res );
84 }
85
86 # Create the input form
87 $wgOut->addHTML(
88 Xml::openElement( 'form', array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => $wgTitle->getLocalUrl() ) ) .
89 Xml::openElement( 'fieldset' ) .
90 Xml::element( 'legend', null, wfMsg( 'fileduplicatesearch-legend' ) ) .
91 Xml::inputLabel( wfMsg( 'fileduplicatesearch-filename' ), 'filename', 'filename', 50, $filename ) . ' ' .
92 Xml::submitButton( wfMsg( 'fileduplicatesearch-submit' ) ) .
93 Xml::closeElement( 'fieldset' ) .
94 Xml::closeElement( 'form' )
95 );
96
97 if( $hash != '' ) {
98 $align = $wgContLang->isRtl() ? 'left' : 'right';
99
100 # Show a thumbnail of the file
101 $img = wfFindFile( $title );
102 if ( $img ) {
103 $thumb = $img->getThumbnail( 120, 120 );
104 if( $thumb ) {
105 $wgOut->addHTML( '<div style="float:' . $align . '" id="mw-fileduplicatesearch-icon">' .
106 $thumb->toHtml( array( 'desc-link' => false ) ) . '<br />' .
107 wfMsgExt( 'fileduplicatesearch-info', array( 'parse' ),
108 $wgLang->formatNum( $img->getWidth() ),
109 $wgLang->formatNum( $img->getHeight() ),
110 $wgLang->formatSize( $img->getSize() ),
111 $img->getMimeType()
112 ) .
113 '</div>' );
114 }
115 }
116
117 # Do the query
118 $wpp = new FileDuplicateSearchPage( $hash, $filename );
119 list( $limit, $offset ) = wfCheckLimits();
120 $count = $wpp->doQuery( $offset, $limit );
121
122 # Show a short summary
123 if( $count == 1 ) {
124 $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-1">' .
125 wfMsgHtml( 'fileduplicatesearch-result-1', $filename ) .
126 '</p>'
127 );
128 } elseif ( $count > 1 ) {
129 $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-n">' .
130 wfMsgExt( 'fileduplicatesearch-result-n', array( 'parseinline' ), $filename, $wgLang->formatNum( $count - 1 ) ) .
131 '</p>'
132 );
133 }
134 }
135 }