MediaWiki  REL1_21
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() {
00038                 return true;
00039         }
00040 
00041         function isSyndicated() {
00042                 return false;
00043         }
00044 
00045         function isCacheable() {
00046                 return false;
00047         }
00048 
00049         function linkParameters() {
00050                 return array( 'mime' => "{$this->major}/{$this->minor}" );
00051         }
00052 
00053         public function getQueryInfo() {
00054                 return array(
00055                         'tables' => array( 'image' ),
00056                         'fields' => array( 'namespace' => NS_FILE,
00057                                         'title' => 'img_name',
00058                                         'value' => 'img_major_mime',
00059                                         'img_size',
00060                                         'img_width',
00061                                         'img_height',
00062                                         'img_user_text',
00063                                         'img_timestamp' ),
00064                         'conds' => array( 'img_major_mime' => $this->major,
00065                                         'img_minor_mime' => $this->minor )
00066                 );
00067         }
00068 
00069         function execute( $par ) {
00070                 global $wgScript;
00071 
00072                 $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
00073 
00074                 $this->setHeaders();
00075                 $this->outputHeader();
00076                 $this->getOutput()->addHTML(
00077                         Xml::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgScript ) ) .
00078                         Xml::openElement( 'fieldset' ) .
00079                         Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
00080                         Xml::element( 'legend', null, $this->msg( 'mimesearch' )->text() ) .
00081                         Xml::inputLabel( $this->msg( 'mimetype' )->text(), 'mime', 'mime', 20, $mime ) . ' ' .
00082                         Xml::submitButton( $this->msg( 'ilsubmit' )->text() ) .
00083                         Xml::closeElement( 'fieldset' ) .
00084                         Xml::closeElement( 'form' )
00085                 );
00086 
00087                 list( $this->major, $this->minor ) = File::splitMime( $mime );
00088                 if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
00089                         !self::isValidType( $this->major ) ) {
00090                         return;
00091                 }
00092                 parent::execute( $par );
00093         }
00094 
00095         function formatResult( $skin, $result ) {
00096                 global $wgContLang;
00097 
00098                 $nt = Title::makeTitle( $result->namespace, $result->title );
00099                 $text = $wgContLang->convert( $nt->getText() );
00100                 $plink = Linker::link(
00101                         Title::newFromText( $nt->getPrefixedText() ),
00102                         htmlspecialchars( $text )
00103                 );
00104 
00105                 $download = Linker::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
00106                 $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
00107                 $lang = $this->getLanguage();
00108                 $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
00109                 $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width,
00110                         $result->img_height )->escaped();
00111                 $user = Linker::link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
00112                 $time = htmlspecialchars( $lang->userTimeAndDate( $result->img_timestamp, $this->getUser() ) );
00113 
00114                 return "$download $plink . . $dimensions . . $bytes . . $user . . $time";
00115         }
00116 
00121         protected static function isValidType( $type ) {
00122                 // From maintenance/tables.sql => img_major_mime
00123                 $types = array(
00124                         'unknown',
00125                         'application',
00126                         'audio',
00127                         'image',
00128                         'text',
00129                         'video',
00130                         'message',
00131                         'model',
00132                         'multipart'
00133                 );
00134                 return in_array( $type, $types );
00135         }
00136 
00137         protected function getGroupName() {
00138                 return 'media';
00139         }
00140 }