MediaWiki  REL1_19
SpecialMIMEsearch.php
Go to the documentation of this file.
00001 <?php
00030 class MIMEsearchPage extends QueryPage {
00031         protected $major, $minor;
00032 
00033         function __construct( $name = 'MIMEsearch' ) {
00034                 parent::__construct( $name );
00035         }
00036 
00037         function isExpensive() { return true; }
00038         function isSyndicated() { return false; }
00039         function isCacheable() { return false; }
00040 
00041         function linkParameters() {
00042                 return array( 'mime' => "{$this->major}/{$this->minor}" );
00043         }
00044 
00045         public function getQueryInfo() {
00046                 return array(
00047                         'tables' => array( 'image' ),
00048                         'fields' => array( "'" . NS_FILE . "' AS namespace",
00049                                         'img_name AS title',
00050                                         'img_major_mime AS value',
00051                                         'img_size',
00052                                         'img_width',
00053                                         'img_height',
00054                                         'img_user_text',
00055                                         'img_timestamp' ),
00056                         'conds' => array( 'img_major_mime' => $this->major,
00057                                         'img_minor_mime' => $this->minor )
00058                 );
00059         }
00060 
00061         function execute( $par ) {
00062                 $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
00063 
00064                 $this->setHeaders();
00065                 $this->outputHeader();
00066                 $this->getOutput()->addHTML(
00067                         Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
00068                         Xml::openElement( 'fieldset' ) .
00069                         Html::hidden( 'title', SpecialPage::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
00070                         Xml::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
00071                         Xml::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
00072                         Xml::submitButton( wfMsg( 'ilsubmit' ) ) .
00073                         Xml::closeElement( 'fieldset' ) .
00074                         Xml::closeElement( 'form' )
00075                 );
00076 
00077                 list( $this->major, $this->minor ) = File::splitMime( $mime );
00078                 if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
00079                         !self::isValidType( $this->major ) ) {
00080                         return;
00081                 }
00082                 parent::execute( $par );
00083         }
00084 
00085 
00086         function formatResult( $skin, $result ) {
00087                 global $wgContLang;
00088 
00089                 $nt = Title::makeTitle( $result->namespace, $result->title );
00090                 $text = $wgContLang->convert( $nt->getText() );
00091                 $plink = Linker::link(
00092                         Title::newFromText( $nt->getPrefixedText() ),
00093                         htmlspecialchars( $text )
00094                 );
00095 
00096                 $download = Linker::makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
00097                 $lang = $this->getLanguage();
00098                 $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
00099                 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
00100                         $lang->formatNum( $result->img_width ),
00101                         $lang->formatNum( $result->img_height )
00102                 ) );
00103                 $user = Linker::link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
00104                 $time = htmlspecialchars( $lang->timeanddate( $result->img_timestamp ) );
00105 
00106                 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
00107         }
00108 
00113         protected static function isValidType( $type ) {
00114                 // From maintenance/tables.sql => img_major_mime
00115                 $types = array(
00116                         'unknown',
00117                         'application',
00118                         'audio',
00119                         'image',
00120                         'text',
00121                         'video',
00122                         'message',
00123                         'model',
00124                         'multipart'
00125                 );
00126                 return in_array( $type, $types );
00127         }
00128 }