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
7 * @subpackage SpecialPage
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 require_once 'QueryPage.php';
18 * @subpackage SpecialPage
20 class MIMEsearchPage
extends QueryPage
{
23 function MIMEsearchPage( $major, $minor ) {
24 $this->major
= $major;
25 $this->minor
= $minor;
28 function getName() { return 'MIMEsearch'; }
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
34 function isExpensive() { return true; }
35 function isSyndicated() { return false; }
37 function linkParameters() {
38 $arr = array( $this->major
, $this->minor
);
39 $mime = implode( '/', $arr );
40 return array( 'mime' => $mime );
44 $dbr =& wfGetDB( DB_SLAVE
);
45 $image = $dbr->tableName( 'image' );
46 $major = $dbr->addQuotes( $this->major
);
47 $minor = $dbr->addQuotes( $this->minor
);
50 "SELECT 'MIMEsearch' AS type,
51 " . NS_IMAGE
. " AS namespace,
53 img_major_mime AS value,
61 WHERE img_major_mime = $major AND img_minor_mime = $minor
65 function formatResult( $skin, $result ) {
66 global $wgContLang, $wgLang;
68 $nt = Title
::makeTitle( $result->namespace, $result->title
);
69 $text = $wgContLang->convert( $nt->getText() );
70 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
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', $result->img_width
, $result->img_height
);
76 $user = $skin->makeLinkObj( Title
::makeTitle( NS_USER
, $result->img_user_text
), $result->img_user_text
);
77 $time = $wgLang->timeanddate( $result->img_timestamp
);
79 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
86 function wfSpecialMIMEsearch( $par = null ) {
87 global $wgRequest, $wgTitle, $wgOut;
89 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
94 'id' => 'specialmimesearch',
96 'action' => $wgTitle->escapeLocalUrl()
100 wfOpenElement( 'label' ) .
101 wfMsgHtml( 'mimetype' ) .
102 wfElement( 'input', array(
111 wfElement( 'input', array(
113 'value' => wfMsg( 'ilsubmit' )
117 wfCloseElement( 'label' ) .
118 wfCloseElement( 'form' )
121 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
122 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
124 $wpp = new MIMEsearchPage( $major, $minor );
126 list( $limit, $offset ) = wfCheckLimits();
127 $wpp->doQuery( $offset, $limit );
130 function wfSpecialMIMEsearchParse( $str ) {
131 wfSuppressWarnings();
132 list( $major, $minor ) = explode( '/', $str, 2 );
136 ltrim( $major, ' ' ),
141 function wfSpecialMIMEsearchValidType( $type ) {
142 // From maintenance/tables.sql => img_major_mime
155 return in_array( $type, $types );