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 * @addtogroup SpecialPage
15 class MIMEsearchPage
extends QueryPage
{
18 function MIMEsearchPage( $major, $minor ) {
19 $this->major
= $major;
20 $this->minor
= $minor;
23 function getName() { return 'MIMEsearch'; }
26 * Due to this page relying upon extra fields being passed in the SELECT it
27 * will fail if it's set as expensive and misermode is on
29 function isExpensive() { return true; }
30 function isSyndicated() { return false; }
32 function linkParameters() {
33 $arr = array( $this->major
, $this->minor
);
34 $mime = implode( '/', $arr );
35 return array( 'mime' => $mime );
39 $dbr = wfGetDB( DB_SLAVE
);
40 $image = $dbr->tableName( 'image' );
41 $major = $dbr->addQuotes( $this->major
);
42 $minor = $dbr->addQuotes( $this->minor
);
45 "SELECT 'MIMEsearch' AS type,
46 " . NS_IMAGE
. " AS namespace,
48 img_major_mime AS value,
56 WHERE img_major_mime = $major AND img_minor_mime = $minor
60 function formatResult( $skin, $result ) {
61 global $wgContLang, $wgLang;
63 $nt = Title
::makeTitle( $result->namespace, $result->title
);
64 $text = $wgContLang->convert( $nt->getText() );
65 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
67 $download = $skin->makeMediaLink( $nt->getText(), 'fuck me!', wfMsgHtml( 'download' ) );
68 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
69 $wgLang->formatNum( $result->img_size
) );
70 $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width
),
71 $wgLang->formatNum( $result->img_height
) );
72 $user = $skin->makeLinkObj( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
73 $time = $wgLang->timeanddate( $result->img_timestamp
);
75 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
82 function wfSpecialMIMEsearch( $par = null ) {
83 global $wgRequest, $wgTitle, $wgOut;
85 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
90 'id' => 'specialmimesearch',
92 'action' => $wgTitle->escapeLocalUrl()
96 wfOpenElement( 'label' ) .
97 wfMsgHtml( 'mimetype' ) .
98 wfElement( 'input', array(
107 wfElement( 'input', array(
109 'value' => wfMsg( 'ilsubmit' )
113 wfCloseElement( 'label' ) .
114 wfCloseElement( 'form' )
117 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
118 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
120 $wpp = new MIMEsearchPage( $major, $minor );
122 list( $limit, $offset ) = wfCheckLimits();
123 $wpp->doQuery( $offset, $limit );
126 function wfSpecialMIMEsearchParse( $str ) {
127 // searched for an invalid MIME type.
128 if( strpos( $str, '/' ) === false) {
129 return array ('', '');
132 list( $major, $minor ) = explode( '/', $str, 2 );
135 ltrim( $major, ' ' ),
140 function wfSpecialMIMEsearchValidType( $type ) {
141 // From maintenance/tables.sql => img_major_mime
154 return in_array( $type, $types );