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