4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * A special page to search for files by MIME type as defined in the
22 * img_major_mime and img_minor_mime fields in the image table
25 * @ingroup SpecialPage
27 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
28 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
32 * Searches the database for files of the requested MIME type, comparing this with the
33 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
34 * @ingroup SpecialPage
36 class MIMEsearchPage
extends QueryPage
{
39 function MIMEsearchPage( $major, $minor ) {
40 $this->major
= $major;
41 $this->minor
= $minor;
44 function getName() { return 'MIMEsearch'; }
47 * Due to this page relying upon extra fields being passed in the SELECT it
48 * will fail if it's set as expensive and misermode is on
50 function isExpensive() { return true; }
51 function isSyndicated() { return false; }
53 function linkParameters() {
54 $arr = array( $this->major
, $this->minor
);
55 $mime = implode( '/', $arr );
56 return array( 'mime' => $mime );
60 $dbr = wfGetDB( DB_SLAVE
);
61 $image = $dbr->tableName( 'image' );
62 $major = $dbr->addQuotes( $this->major
);
63 $minor = $dbr->addQuotes( $this->minor
);
66 "SELECT 'MIMEsearch' AS type,
67 " . NS_FILE
. " AS namespace,
69 img_major_mime AS value,
77 WHERE img_major_mime = $major AND img_minor_mime = $minor
81 function formatResult( $skin, $result ) {
82 global $wgContLang, $wgLang;
84 $nt = Title
::makeTitle( $result->namespace, $result->title
);
85 $text = $wgContLang->convert( $nt->getText() );
87 Title
::newFromText( $nt->getPrefixedText() ),
88 htmlspecialchars( $text )
91 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
92 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
93 $wgLang->formatNum( $result->img_size
) );
94 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
95 $wgLang->formatNum( $result->img_width
),
96 $wgLang->formatNum( $result->img_height
)
98 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), htmlspecialchars( $result->img_user_text
) );
99 $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp
) );
101 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
106 * Output the HTML search form, and constructs the MIMEsearchPage object.
108 function wfSpecialMIMEsearch( $par = null ) {
109 global $wgRequest, $wgOut;
111 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
114 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage
::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
115 Xml
::openElement( 'fieldset' ) .
116 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
117 Xml
::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
118 Xml
::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
119 Xml
::submitButton( wfMsg( 'ilsubmit' ) ) .
120 Xml
::closeElement( 'fieldset' ) .
121 Xml
::closeElement( 'form' )
124 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
125 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
127 $wpp = new MIMEsearchPage( $major, $minor );
129 list( $limit, $offset ) = wfCheckLimits();
130 $wpp->doQuery( $offset, $limit );
133 function wfSpecialMIMEsearchParse( $str ) {
134 // searched for an invalid MIME type.
135 if( strpos( $str, '/' ) === false) {
136 return array ('', '');
139 list( $major, $minor ) = explode( '/', $str, 2 );
142 ltrim( $major, ' ' ),
147 function wfSpecialMIMEsearchValidType( $type ) {
148 // From maintenance/tables.sql => img_major_mime
161 return in_array( $type, $types );