Provide message/warning/error box abstraction
[lhc/web/wiklou.git] / includes / specials / SpecialMIMEsearch.php
index 1d02a4f..3290abd 100644 (file)
@@ -74,6 +74,7 @@ class MIMEsearchPage extends QueryPage {
                                'img_major_mime' => $this->major,
                                // This is in order to trigger using
                                // the img_media_mime index in "range" mode.
+                               // @todo how is order defined? use MimeAnalyzer::getMediaTypes?
                                'img_media_type' => [
                                        MEDIATYPE_BITMAP,
                                        MEDIATYPE_DRAWING,
@@ -85,6 +86,7 @@ class MIMEsearchPage extends QueryPage {
                                        MEDIATYPE_TEXT,
                                        MEDIATYPE_EXECUTABLE,
                                        MEDIATYPE_ARCHIVE,
+                                       MEDIATYPE_3D,
                                ],
                        ] + $minorType,
                ];
@@ -111,7 +113,8 @@ class MIMEsearchPage extends QueryPage {
        function getPageHeader() {
                $formDescriptor = [
                        'mime' => [
-                               'type' => 'text',
+                               'type' => 'combobox',
+                               'options' => $this->getSuggestionsForTypes(),
                                'name' => 'mime',
                                'label-message' => 'mimetype',
                                'required' => true,
@@ -119,8 +122,7 @@ class MIMEsearchPage extends QueryPage {
                        ],
                ];
 
-               $form = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
-                       ->setWrapperLegendMsg( 'mimesearch' )
+               HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
                        ->setSubmitTextMsg( 'ilsubmit' )
                        ->setAction( $this->getPageTitle()->getLocalURL() )
                        ->setMethod( 'get' )
@@ -128,6 +130,33 @@ class MIMEsearchPage extends QueryPage {
                        ->displayForm( false );
        }
 
+       protected function getSuggestionsForTypes() {
+               $dbr = wfGetDB( DB_REPLICA );
+               $lastMajor = null;
+               $suggestions = [];
+               $result = $dbr->select(
+                       [ 'image' ],
+                       // We ignore img_media_type, but using it in the query is needed for MySQL to choose a
+                       // sensible execution plan
+                       [ 'img_media_type', 'img_major_mime', 'img_minor_mime' ],
+                       [],
+                       __METHOD__,
+                       [ 'GROUP BY' => [ 'img_media_type', 'img_major_mime', 'img_minor_mime' ] ]
+               );
+               foreach ( $result as $row ) {
+                       $major = $row->img_major_mime;
+                       $minor = $row->img_minor_mime;
+                       $suggestions[ "$major/$minor" ] = "$major/$minor";
+                       if ( $lastMajor === $major ) {
+                               // If there are at least two with the same major mime type, also include the wildcard
+                               $suggestions[ "$major/*" ] = "$major/*";
+                       }
+                       $lastMajor = $major;
+               }
+               ksort( $suggestions );
+               return $suggestions;
+       }
+
        public function execute( $par ) {
                $this->mime = $par ? $par : $this->getRequest()->getText( 'mime' );
                $this->mime = trim( $this->mime );
@@ -153,11 +182,12 @@ class MIMEsearchPage extends QueryPage {
        function formatResult( $skin, $result ) {
                global $wgContLang;
 
+               $linkRenderer = $this->getLinkRenderer();
                $nt = Title::makeTitle( $result->namespace, $result->title );
                $text = $wgContLang->convert( $nt->getText() );
-               $plink = Linker::link(
+               $plink = $linkRenderer->makeLink(
                        Title::newFromText( $nt->getPrefixedText() ),
-                       htmlspecialchars( $text )
+                       $text
                );
 
                $download = Linker::makeMediaLinkObj( $nt, $this->msg( 'download' )->escaped() );
@@ -166,9 +196,9 @@ class MIMEsearchPage extends QueryPage {
                $bytes = htmlspecialchars( $lang->formatSize( $result->img_size ) );
                $dimensions = $this->msg( 'widthheight' )->numParams( $result->img_width,
                        $result->img_height )->escaped();
-               $user = Linker::link(
+               $user = $linkRenderer->makeLink(
                        Title::makeTitle( NS_USER, $result->img_user_text ),
-                       htmlspecialchars( $result->img_user_text )
+                       $result->img_user_text
                );
 
                $time = $lang->userTimeAndDate( $result->img_timestamp, $this->getUser() );