MediaWiki  REL1_22
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         return $qi;
00088     }
00089 
00098     function getOrderFields() {
00099         return array();
00100     }
00101 
00102     function execute( $par ) {
00103         global $wgScript;
00104 
00105         $mime = $par ? $par : $this->getRequest()->getText( 'mime' );
00106 
00107         $this->setHeaders();
00108         $this->outputHeader();
00109         $this->getOutput()->addHTML(
00110             Xml::openElement(
00111                 'form',
00112                 array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => $wgScript )
00113             ) .
00114                 Xml::openElement( 'fieldset' ) .
00115                 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
00116                 Xml::element( 'legend', null, $this->msg( 'mimesearch' )->text() ) .
00117                 Xml::inputLabel( $this->msg( 'mimetype' )->text(), 'mime', 'mime', 20, $mime ) .
00118                 ' ' .
00119                 Xml::submitButton( $this->msg( 'ilsubmit' )->text() ) .
00120                 Xml::closeElement( 'fieldset' ) .
00121                 Xml::closeElement( 'form' )
00122         );
00123 
00124         list( $this->major, $this->minor ) = File::splitMime( $mime );
00125 
00126         if ( $this->major == '' || $this->minor == '' || $this->minor == 'unknown' ||
00127             !self::isValidType( $this->major )
00128         ) {
00129             return;
00130         }
00131 
00132         parent::execute( $par );
00133     }
00134 
00140     function formatResult( $skin, $result ) {
00141         global $wgContLang;
00142 
00143         $nt = Title::makeTitle( $result->namespace, $result->title );
00144         $text = $wgContLang->convert( $nt->getText() );
00145         $plink = Linker::link(
00146             Title::newFromText( $nt->getPrefixedText() ),
00147             htmlspecialchars( $text )
00148         );
00149 
00150         $download = Linker::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
00151         $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
00152         $lang = $this->getLanguage();
00153         $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
00154         $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width,
00155             $result->img_height )->escaped();
00156         $user = Linker::link(
00157             Title::makeTitle( NS_USER, $result->img_user_text ),
00158             htmlspecialchars( $result->img_user_text )
00159         );
00160 
00161         $time = $lang->userTimeAndDate( $result->img_timestamp, $this->getUser() );
00162         $time = htmlspecialchars( $time );
00163 
00164         return "$download $plink . . $dimensions . . $bytes . . $user . . $time";
00165     }
00166 
00171     protected static function isValidType( $type ) {
00172         // From maintenance/tables.sql => img_major_mime
00173         $types = array(
00174             'unknown',
00175             'application',
00176             'audio',
00177             'image',
00178             'text',
00179             'video',
00180             'message',
00181             'model',
00182             'multipart'
00183         );
00184 
00185         return in_array( $type, $types );
00186     }
00187 
00188     protected function getGroupName() {
00189         return 'media';
00190     }
00191 }