Use appropriate HTML functions to create the tool links on image pages, so they don...
[lhc/web/wiklou.git] / includes / SpecialMIMEsearch.php
1 <?php
2 /**
3 * A special page to search for files by MIME type as defined in the
4 * img_major_mime and img_minor_mime fields in the image table
5 *
6 * @package MediaWiki
7 * @subpackage SpecialPage
8 *
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11 */
12
13 /* */
14 require_once 'QueryPage.php';
15
16 /**
17 * @package MediaWiki
18 * @subpackage SpecialPage
19 */
20 class MIMEsearchPage extends QueryPage {
21 var $major, $minor;
22
23 function MIMEsearchPage( $major, $minor ) {
24 $this->major = $major;
25 $this->minor = $minor;
26 }
27
28 function getName() { return 'MIMEsearch'; }
29
30 /**
31 * Due to this page relying upon extra fields being passed in the SELECT it
32 * will fail if it's set as expensive and misermode is on
33 */
34 function isExpensive() { return true; }
35 function isSyndicated() { return false; }
36
37 function linkParameters() {
38 $arr = array( $this->major, $this->minor );
39 $mime = implode( '/', $arr );
40 return array( 'mime' => $mime );
41 }
42
43 function getSQL() {
44 $dbr =& wfGetDB( DB_SLAVE );
45 $image = $dbr->tableName( 'image' );
46 $major = $dbr->addQuotes( $this->major );
47 $minor = $dbr->addQuotes( $this->minor );
48
49 return
50 "SELECT 'MIMEsearch' AS type,
51 " . NS_IMAGE . " AS namespace,
52 img_name AS title,
53 img_major_mime AS value,
54
55 img_size,
56 img_width,
57 img_height,
58 img_user_text,
59 img_timestamp
60 FROM $image
61 WHERE img_major_mime = $major AND img_minor_mime = $minor
62 ";
63 }
64
65 function formatResult( $skin, $result ) {
66 global $wgContLang, $wgLang;
67
68 $nt = Title::makeTitle( $result->namespace, $result->title );
69 $text = $wgContLang->convert( $nt->getText() );
70 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
71
72 $download = $skin->makeMediaLink( $nt->getText(), 'fuck me!', wfMsgHtml( 'download' ) );
73 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
74 $wgLang->formatNum( $result->img_size ) );
75 $dimensions = wfMsg( 'widthheight', $wgLang->formatNum( $result->img_width ),
76 $wgLang->formatNum( $result->img_height ) );
77 $user = $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
78 $time = $wgLang->timeanddate( $result->img_timestamp );
79
80 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
81 }
82 }
83
84 /**
85 * constructor
86 */
87 function wfSpecialMIMEsearch( $par = null ) {
88 global $wgRequest, $wgTitle, $wgOut;
89
90 $mime = isset( $par ) ? $par : $wgRequest->getText( 'mime' );
91
92 $wgOut->addHTML(
93 wfElement( 'form',
94 array(
95 'id' => 'specialmimesearch',
96 'method' => 'get',
97 'action' => $wgTitle->escapeLocalUrl()
98 ),
99 null
100 ) .
101 wfOpenElement( 'label' ) .
102 wfMsgHtml( 'mimetype' ) .
103 wfElement( 'input', array(
104 'type' => 'text',
105 'size' => 20,
106 'name' => 'mime',
107 'value' => $mime
108 ),
109 ''
110 ) .
111 ' ' .
112 wfElement( 'input', array(
113 'type' => 'submit',
114 'value' => wfMsg( 'ilsubmit' )
115 ),
116 ''
117 ) .
118 wfCloseElement( 'label' ) .
119 wfCloseElement( 'form' )
120 );
121
122 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
123 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
124 return;
125 $wpp = new MIMEsearchPage( $major, $minor );
126
127 list( $limit, $offset ) = wfCheckLimits();
128 $wpp->doQuery( $offset, $limit );
129 }
130
131 function wfSpecialMIMEsearchParse( $str ) {
132 wfSuppressWarnings();
133 list( $major, $minor ) = explode( '/', $str, 2 );
134 wfRestoreWarnings();
135
136 return array(
137 ltrim( $major, ' ' ),
138 rtrim( $minor, ' ' )
139 );
140 }
141
142 function wfSpecialMIMEsearchValidType( $type ) {
143 // From maintenance/tables.sql => img_major_mime
144 $types = array(
145 'unknown',
146 'application',
147 'audio',
148 'image',
149 'text',
150 'video',
151 'message',
152 'model',
153 'multipart'
154 );
155
156 return in_array( $type, $types );
157 }
158 ?>