00001 <?php
00018 class MIMEsearchPage extends QueryPage {
00019 var $major, $minor;
00020
00021 function MIMEsearchPage( $major, $minor ) {
00022 $this->major = $major;
00023 $this->minor = $minor;
00024 }
00025
00026 function getName() { return 'MIMEsearch'; }
00027
00032 function isExpensive() { return true; }
00033 function isSyndicated() { return false; }
00034
00035 function linkParameters() {
00036 $arr = array( $this->major, $this->minor );
00037 $mime = implode( '/', $arr );
00038 return array( 'mime' => $mime );
00039 }
00040
00041 function getSQL() {
00042 $dbr = wfGetDB( DB_SLAVE );
00043 $image = $dbr->tableName( 'image' );
00044 $major = $dbr->addQuotes( $this->major );
00045 $minor = $dbr->addQuotes( $this->minor );
00046
00047 return
00048 "SELECT 'MIMEsearch' AS type,
00049 " . NS_FILE . " AS namespace,
00050 img_name AS title,
00051 img_major_mime AS value,
00052
00053 img_size,
00054 img_width,
00055 img_height,
00056 img_user_text,
00057 img_timestamp
00058 FROM $image
00059 WHERE img_major_mime = $major AND img_minor_mime = $minor
00060 ";
00061 }
00062
00063 function formatResult( $skin, $result ) {
00064 global $wgContLang, $wgLang;
00065
00066 $nt = Title::makeTitle( $result->namespace, $result->title );
00067 $text = $wgContLang->convert( $nt->getText() );
00068 $plink = $skin->makeLink( $nt->getPrefixedText(), $text );
00069
00070 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
00071 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
00072 $wgLang->formatNum( $result->img_size ) );
00073 $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width ),
00074 $wgLang->formatNum( $result->img_height ) );
00075 $user = $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text );
00076 $time = $wgLang->timeanddate( $result->img_timestamp );
00077
00078 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
00079 }
00080 }
00081
00085 function wfSpecialMIMEsearch( $par = null ) {
00086 global $wgRequest, $wgTitle, $wgOut;
00087
00088 $mime = isset( $par ) ? $par : $wgRequest->getText( 'mime' );
00089
00090 $wgOut->addHTML(
00091 Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgTitle->getLocalUrl() ) ) .
00092 Xml::openElement( 'fieldset' ) .
00093 Xml::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
00094 Xml::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
00095 Xml::submitButton( wfMsg( 'ilsubmit' ) ) .
00096 Xml::closeElement( 'fieldset' ) .
00097 Xml::closeElement( 'form' )
00098 );
00099
00100 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
00101 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
00102 return;
00103 $wpp = new MIMEsearchPage( $major, $minor );
00104
00105 list( $limit, $offset ) = wfCheckLimits();
00106 $wpp->doQuery( $offset, $limit );
00107 }
00108
00109 function wfSpecialMIMEsearchParse( $str ) {
00110
00111 if( strpos( $str, '/' ) === false) {
00112 return array ('', '');
00113 }
00114
00115 list( $major, $minor ) = explode( '/', $str, 2 );
00116
00117 return array(
00118 ltrim( $major, ' ' ),
00119 rtrim( $minor, ' ' )
00120 );
00121 }
00122
00123 function wfSpecialMIMEsearchValidType( $type ) {
00124
00125 $types = array(
00126 'unknown',
00127 'application',
00128 'audio',
00129 'image',
00130 'text',
00131 'video',
00132 'message',
00133 'model',
00134 'multipart'
00135 );
00136
00137 return in_array( $type, $types );
00138 }