MediaWiki  REL1_20
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( 'namespace' => NS_FILE,
00049                                         'title' => 'img_name',
00050                                         'value' => 'img_major_mime',
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                 global $wgScript;
00063 
00064                 $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
00065 
00066                 $this->setHeaders();
00067                 $this->outputHeader();
00068                 $this->getOutput()->addHTML(
00069                         Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgScript ) ) .
00070                         Xml::openElement( 'fieldset' ) .
00071                         Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
00072                         Xml::element( 'legend', null, $this->msg( 'mimesearch' )->text() ) .
00073                         Xml::inputLabel( $this->msg( 'mimetype' )->text(), 'mime', 'mime', 20, $mime ) . ' ' .
00074                         Xml::submitButton( $this->msg( 'ilsubmit' )->text() ) .
00075                         Xml::closeElement( 'fieldset' ) .
00076                         Xml::closeElement( 'form' )
00077                 );
00078 
00079                 list( $this->major, $this->minor ) = File::splitMime( $mime );
00080                 if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
00081                         !self::isValidType( $this->major ) ) {
00082                         return;
00083                 }
00084                 parent::execute( $par );
00085         }
00086 
00087 
00088         function formatResult( $skin, $result ) {
00089                 global $wgContLang;
00090 
00091                 $nt = Title::makeTitle( $result->namespace, $result->title );
00092                 $text = $wgContLang->convert( $nt->getText() );
00093                 $plink = Linker::link(
00094                         Title::newFromText( $nt->getPrefixedText() ),
00095                         htmlspecialchars( $text )
00096                 );
00097 
00098                 $download = Linker::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
00099                 $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
00100                 $lang = $this->getLanguage();
00101                 $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
00102                 $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width,
00103                         $result->img_height )->escaped();
00104                 $user = Linker::link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
00105                 $time = htmlspecialchars( $lang->userTimeAndDate( $result->img_timestamp, $this->getUser() ) );
00106 
00107                 return "$download $plink . . $dimensions . . $bytes . . $user . . $time";
00108         }
00109 
00114         protected static function isValidType( $type ) {
00115                 // From maintenance/tables.sql => img_major_mime
00116                 $types = array(
00117                         'unknown',
00118                         'application',
00119                         'audio',
00120                         'image',
00121                         'text',
00122                         'video',
00123                         'message',
00124                         'model',
00125                         'multipart'
00126                 );
00127                 return in_array( $type, $types );
00128         }
00129 }