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
6 * @addtogroup SpecialPage
8 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
13 * Searches the database for files of the requested MIME type, comparing this with the
14 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
16 class MIMEsearchPage
extends QueryPage
{
19 function MIMEsearchPage( $major, $minor ) {
20 $this->major
= $major;
21 $this->minor
= $minor;
24 function getName() { return 'MIMEsearch'; }
27 * Due to this page relying upon extra fields being passed in the SELECT it
28 * will fail if it's set as expensive and misermode is on
30 function isExpensive() { return true; }
31 function isSyndicated() { return false; }
33 function linkParameters() {
34 $arr = array( $this->major
, $this->minor
);
35 $mime = implode( '/', $arr );
36 return array( 'mime' => $mime );
40 $dbr = wfGetDB( DB_SLAVE
);
41 $image = $dbr->tableName( 'image' );
42 $major = $dbr->addQuotes( $this->major
);
43 $minor = $dbr->addQuotes( $this->minor
);
46 "SELECT 'MIMEsearch' AS type,
47 " . NS_IMAGE
. " AS namespace,
49 img_major_mime AS value,
57 WHERE img_major_mime = $major AND img_minor_mime = $minor
61 function formatResult( $skin, $result ) {
62 global $wgContLang, $wgLang;
64 $nt = Title
::makeTitle( $result->namespace, $result->title
);
65 $text = $wgContLang->convert( $nt->getText() );
66 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
68 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
69 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
70 $wgLang->formatNum( $result->img_size
) );
71 $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width
),
72 $wgLang->formatNum( $result->img_height
) );
73 $user = $skin->makeLinkObj( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
74 $time = $wgLang->timeanddate( $result->img_timestamp
);
76 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
81 * Output the HTML search form, and constructs the MIMEsearchPage object.
83 function wfSpecialMIMEsearch( $par = null ) {
84 global $wgRequest, $wgTitle, $wgOut;
86 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
89 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgTitle->getLocalUrl() ) ) .
90 Xml
::openElement( 'fieldset' ) .
91 Xml
::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
92 Xml
::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
93 Xml
::submitButton( wfMsg( 'ilsubmit' ) ) .
94 Xml
::closeElement( 'fieldset' ) .
95 Xml
::closeElement( 'form' )
98 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
99 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
101 $wpp = new MIMEsearchPage( $major, $minor );
103 list( $limit, $offset ) = wfCheckLimits();
104 $wpp->doQuery( $offset, $limit );
107 function wfSpecialMIMEsearchParse( $str ) {
108 // searched for an invalid MIME type.
109 if( strpos( $str, '/' ) === false) {
110 return array ('', '');
113 list( $major, $minor ) = explode( '/', $str, 2 );
116 ltrim( $major, ' ' ),
121 function wfSpecialMIMEsearchValidType( $type ) {
122 // From maintenance/tables.sql => img_major_mime
135 return in_array( $type, $types );