From: Bartosz DziewoƄski Date: Thu, 19 Jan 2017 19:56:47 +0000 (+0100) Subject: SpecialMIMEsearch: Add a dropdown with input suggestions X-Git-Tag: 1.31.0-rc.0~4261^2 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=4f79b0d11fc5503f64352fcb6cf2602686fbf34c;p=lhc%2Fweb%2Fwiklou.git SpecialMIMEsearch: Add a dropdown with input suggestions I think people usually distinguish file types by their extensions. We shouldn't expect them to know what the valid values are here. Change-Id: I854d48494e7b8c5eb1f49e364c5300df5cd73fe9 --- diff --git a/includes/specials/SpecialMIMEsearch.php b/includes/specials/SpecialMIMEsearch.php index 15696bcbd8..52cb30a1bc 100644 --- a/includes/specials/SpecialMIMEsearch.php +++ b/includes/specials/SpecialMIMEsearch.php @@ -111,7 +111,8 @@ class MIMEsearchPage extends QueryPage { function getPageHeader() { $formDescriptor = [ 'mime' => [ - 'type' => 'text', + 'type' => 'combobox', + 'options' => $this->getSuggestionsForTypes(), 'name' => 'mime', 'label-message' => 'mimetype', 'required' => true, @@ -127,6 +128,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 );