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->link(
00069 Title::newFromText( $nt->getPrefixedText() ),
00070 htmlspecialchars( $text )
00071 );
00072
00073 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
00074 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
00075 $wgLang->formatNum( $result->img_size ) );
00076 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
00077 $wgLang->formatNum( $result->img_width ),
00078 $wgLang->formatNum( $result->img_height )
00079 ) );
00080 $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
00081 $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp ) );
00082
00083 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
00084 }
00085 }
00086
00090 function wfSpecialMIMEsearch( $par = null ) {
00091 global $wgRequest, $wgOut;
00092
00093 $mime = isset( $par ) ? $par : $wgRequest->getText( 'mime' );
00094
00095 $wgOut->addHTML(
00096 Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
00097 Xml::openElement( 'fieldset' ) .
00098 Xml::hidden( 'title', SpecialPage::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
00099 Xml::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
00100 Xml::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
00101 Xml::submitButton( wfMsg( 'ilsubmit' ) ) .
00102 Xml::closeElement( 'fieldset' ) .
00103 Xml::closeElement( 'form' )
00104 );
00105
00106 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
00107 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
00108 return;
00109 $wpp = new MIMEsearchPage( $major, $minor );
00110
00111 list( $limit, $offset ) = wfCheckLimits();
00112 $wpp->doQuery( $offset, $limit );
00113 }
00114
00115 function wfSpecialMIMEsearchParse( $str ) {
00116
00117 if( strpos( $str, '/' ) === false) {
00118 return array ('', '');
00119 }
00120
00121 list( $major, $minor ) = explode( '/', $str, 2 );
00122
00123 return array(
00124 ltrim( $major, ' ' ),
00125 rtrim( $minor, ' ' )
00126 );
00127 }
00128
00129 function wfSpecialMIMEsearchValidType( $type ) {
00130
00131 $types = array(
00132 'unknown',
00133 'application',
00134 'audio',
00135 'image',
00136 'text',
00137 'video',
00138 'message',
00139 'model',
00140 'multipart'
00141 );
00142
00143 return in_array( $type, $types );
00144 }