moved release notes for r113737 to 1.19 (a 1.19-regression fix)
[lhc/web/wiklou.git] / includes / specials / SpecialMIMEsearch.php
1 <?php
2 /**
3 * Implements Special:MIMESearch
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 Ævar Arnfjörð Bjarmason <avarab@gmail.com>
23 */
24
25 /**
26 * Searches the database for files of the requested MIME type, comparing this with the
27 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
28 * @ingroup SpecialPage
29 */
30 class MIMEsearchPage extends QueryPage {
31 protected $major, $minor;
32
33 function __construct( $name = 'MIMEsearch' ) {
34 parent::__construct( $name );
35 }
36
37 function isExpensive() { return true; }
38 function isSyndicated() { return false; }
39 function isCacheable() { return false; }
40
41 function linkParameters() {
42 return array( 'mime' => "{$this->major}/{$this->minor}" );
43 }
44
45 public function getQueryInfo() {
46 return array(
47 'tables' => array( 'image' ),
48 'fields' => array( "'" . NS_FILE . "' AS namespace",
49 'img_name AS title',
50 'img_major_mime AS value',
51 'img_size',
52 'img_width',
53 'img_height',
54 'img_user_text',
55 'img_timestamp' ),
56 'conds' => array( 'img_major_mime' => $this->major,
57 'img_minor_mime' => $this->minor )
58 );
59 }
60
61 function execute( $par ) {
62 $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
63
64 $this->setHeaders();
65 $this->outputHeader();
66 $this->getOutput()->addHTML(
67 Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
68 Xml::openElement( 'fieldset' ) .
69 Html::hidden( 'title', SpecialPage::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
70 Xml::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
71 Xml::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
72 Xml::submitButton( wfMsg( 'ilsubmit' ) ) .
73 Xml::closeElement( 'fieldset' ) .
74 Xml::closeElement( 'form' )
75 );
76
77 list( $this->major, $this->minor ) = File::splitMime( $mime );
78 if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
79 !self::isValidType( $this->major ) ) {
80 return;
81 }
82 parent::execute( $par );
83 }
84
85
86 function formatResult( $skin, $result ) {
87 global $wgContLang;
88
89 $nt = Title::makeTitle( $result->namespace, $result->title );
90 $text = $wgContLang->convert( $nt->getText() );
91 $plink = Linker::link(
92 Title::newFromText( $nt->getPrefixedText() ),
93 htmlspecialchars( $text )
94 );
95
96 $download = Linker::makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
97 $lang = $this->getLanguage();
98 $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
99 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
100 $lang->formatNum( $result->img_width ),
101 $lang->formatNum( $result->img_height )
102 ) );
103 $user = Linker::link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
104 $time = htmlspecialchars( $lang->timeanddate( $result->img_timestamp ) );
105
106 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
107 }
108
109 /**
110 * @param $type string
111 * @return bool
112 */
113 protected static function isValidType( $type ) {
114 // From maintenance/tables.sql => img_major_mime
115 $types = array(
116 'unknown',
117 'application',
118 'audio',
119 'image',
120 'text',
121 'video',
122 'message',
123 'model',
124 'multipart'
125 );
126 return in_array( $type, $types );
127 }
128 }