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
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
14 * Searches the database for files of the requested MIME type, comparing this with the
15 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
16 * @ingroup SpecialPage
18 class MIMEsearchPage
extends QueryPage
{
21 function MIMEsearchPage( $major, $minor ) {
22 $this->major
= $major;
23 $this->minor
= $minor;
26 function getName() { return 'MIMEsearch'; }
29 * Due to this page relying upon extra fields being passed in the SELECT it
30 * will fail if it's set as expensive and misermode is on
32 function isExpensive() { return true; }
33 function isSyndicated() { return false; }
35 function linkParameters() {
36 $arr = array( $this->major
, $this->minor
);
37 $mime = implode( '/', $arr );
38 return array( 'mime' => $mime );
42 $dbr = wfGetDB( DB_SLAVE
);
43 $image = $dbr->tableName( 'image' );
44 $major = $dbr->addQuotes( $this->major
);
45 $minor = $dbr->addQuotes( $this->minor
);
48 "SELECT 'MIMEsearch' AS type,
49 " . NS_IMAGE
. " AS namespace,
51 img_major_mime AS value,
59 WHERE img_major_mime = $major AND img_minor_mime = $minor
63 function formatResult( $skin, $result ) {
64 global $wgContLang, $wgLang;
66 $nt = Title
::makeTitle( $result->namespace, $result->title
);
67 $text = $wgContLang->convert( $nt->getText() );
68 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
70 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
71 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
72 $wgLang->formatNum( $result->img_size
) );
73 $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width
),
74 $wgLang->formatNum( $result->img_height
) );
75 $user = $skin->makeLinkObj( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
76 $time = $wgLang->timeanddate( $result->img_timestamp
);
78 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
83 * Output the HTML search form, and constructs the MIMEsearchPage object.
85 function wfSpecialMIMEsearch( $par = null ) {
86 global $wgRequest, $wgTitle, $wgOut;
88 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
91 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgTitle->getLocalUrl() ) ) .
92 Xml
::openElement( 'fieldset' ) .
93 Xml
::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
94 Xml
::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
95 Xml
::submitButton( wfMsg( 'ilsubmit' ) ) .
96 Xml
::closeElement( 'fieldset' ) .
97 Xml
::closeElement( 'form' )
100 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
101 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
103 $wpp = new MIMEsearchPage( $major, $minor );
105 list( $limit, $offset ) = wfCheckLimits();
106 $wpp->doQuery( $offset, $limit );
109 function wfSpecialMIMEsearchParse( $str ) {
110 // searched for an invalid MIME type.
111 if( strpos( $str, '/' ) === false) {
112 return array ('', '');
115 list( $major, $minor ) = explode( '/', $str, 2 );
118 ltrim( $major, ' ' ),
123 function wfSpecialMIMEsearchValidType( $type ) {
124 // From maintenance/tables.sql => img_major_mime
137 return in_array( $type, $types );