MediaWiki  REL1_23
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 false;
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         $qi = array(
00055             'tables' => array( 'image' ),
00056             'fields' => array(
00057                 'namespace' => NS_FILE,
00058                 'title' => 'img_name',
00059                 // Still have a value field just in case,
00060                 // but it isn't actually used for sorting.
00061                 'value' => 'img_name',
00062                 'img_size',
00063                 'img_width',
00064                 'img_height',
00065                 'img_user_text',
00066                 'img_timestamp'
00067             ),
00068             'conds' => array(
00069                 'img_major_mime' => $this->major,
00070                 'img_minor_mime' => $this->minor,
00071                 // This is in order to trigger using
00072                 // the img_media_mime index in "range" mode.
00073                 'img_media_type' => array(
00074                     MEDIATYPE_BITMAP,
00075                     MEDIATYPE_DRAWING,
00076                     MEDIATYPE_AUDIO,
00077                     MEDIATYPE_VIDEO,
00078                     MEDIATYPE_MULTIMEDIA,
00079                     MEDIATYPE_UNKNOWN,
00080                     MEDIATYPE_OFFICE,
00081                     MEDIATYPE_TEXT,
00082                     MEDIATYPE_EXECUTABLE,
00083                     MEDIATYPE_ARCHIVE,
00084                 ),
00085             ),
00086         );
00087 
00088         return $qi;
00089     }
00090 
00099     function getOrderFields() {
00100         return array();
00101     }
00102 
00103     function execute( $par ) {
00104         global $wgScript;
00105 
00106         $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
00107 
00108         $this->setHeaders();
00109         $this->outputHeader();
00110         $this->getOutput()->addHTML(
00111             Xml::openElement(
00112                 'form',
00113                 array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgScript )
00114             ) .
00115                 Xml::openElement( 'fieldset' ) .
00116                 Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
00117                 Xml::element( 'legend', null, $this->msg( 'mimesearch' )->text() ) .
00118                 Xml::inputLabel( $this->msg( 'mimetype' )->text(), 'mime', 'mime', 20, $mime ) .
00119                 ' ' .
00120                 Xml::submitButton( $this->msg( 'ilsubmit' )->text() ) .
00121                 Xml::closeElement( 'fieldset' ) .
00122                 Xml::closeElement( 'form' )
00123         );
00124 
00125         list( $this->major, $this->minor ) = File::splitMime( $mime );
00126 
00127         if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
00128             !self::isValidType( $this->major )
00129         ) {
00130             return;
00131         }
00132 
00133         parent::execute( $par );
00134     }
00135 
00141     function formatResult( $skin, $result ) {
00142         global $wgContLang;
00143 
00144         $nt = Title::makeTitle( $result->namespace, $result->title );
00145         $text = $wgContLang->convert( $nt->getText() );
00146         $plink = Linker::link(
00147             Title::newFromText( $nt->getPrefixedText() ),
00148             htmlspecialchars( $text )
00149         );
00150 
00151         $download = Linker::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
00152         $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
00153         $lang = $this->getLanguage();
00154         $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
00155         $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width,
00156             $result->img_height )->escaped();
00157         $user = Linker::link(
00158             Title::makeTitle( NS_USER, $result->img_user_text ),
00159             htmlspecialchars( $result->img_user_text )
00160         );
00161 
00162         $time = $lang->userTimeAndDate( $result->img_timestamp, $this->getUser() );
00163         $time = htmlspecialchars( $time );
00164 
00165         return "$download $plink . . $dimensions . . $bytes . . $user . . $time";
00166     }
00167 
00172     protected static function isValidType( $type ) {
00173         // From maintenance/tables.sql => img_major_mime
00174         $types = array(
00175             'unknown',
00176             'application',
00177             'audio',
00178             'image',
00179             'text',
00180             'video',
00181             'message',
00182             'model',
00183             'multipart'
00184         );
00185 
00186         return in_array( $type, $types );
00187     }
00188 
00189     protected function getGroupName() {
00190         return 'media';
00191     }
00192 }