Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / includes / widget / search / SearchFormWidget.php
index 2302177..62ee9cb 100644 (file)
@@ -4,8 +4,8 @@ namespace MediaWiki\Widget\Search;
 
 use Hooks;
 use Html;
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Widget\SearchInputWidget;
-use MWNamespace;
 use SearchEngineConfig;
 use SpecialSearch;
 use Xml;
@@ -40,6 +40,7 @@ class SearchFormWidget {
         * @param int $totalResults The total estimated results found
         * @param int $offset Current offset in search results
         * @param bool $isPowerSearch Is the 'advanced' section open?
+        * @param array $options Widget options
         * @return string HTML
         */
        public function render(
@@ -48,18 +49,23 @@ class SearchFormWidget {
                $numResults,
                $totalResults,
                $offset,
-               $isPowerSearch
+               $isPowerSearch,
+               array $options = []
        ) {
-               return Xml::openElement(
+               $user = $this->specialSearch->getUser();
+
+               return '<div class="mw-search-form-wrapper">' .
+                       Xml::openElement(
                                'form',
                                [
                                        'id' => $isPowerSearch ? 'powersearch' : 'search',
-                                       'method' => 'get',
+                                       // T151903: default to POST in case JS is disabled
+                                       'method' => ( $isPowerSearch && $user->isLoggedIn() ) ? 'post' : 'get',
                                        'action' => wfScript(),
                                ]
                        ) .
                                '<div id="mw-search-top-table">' .
-                                       $this->shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset ) .
+                                       $this->shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset, $options ) .
                                '</div>' .
                                "<div class='mw-search-visualclear'></div>" .
                                "<div class='mw-search-profile-tabs'>" .
@@ -67,7 +73,8 @@ class SearchFormWidget {
                                        "<div style='clear:both'></div>" .
                                "</div>" .
                                $this->optionsHtml( $term, $isPowerSearch, $profile ) .
-                       '</form>';
+                       '</form>' .
+               '</div>';
        }
 
        /**
@@ -76,12 +83,20 @@ class SearchFormWidget {
         * @param int $numResults The number of results shown
         * @param int $totalResults The total estimated results found
         * @param int $offset Current offset in search results
+        * @param array $options Widget options
         * @return string HTML
         */
-       protected function shortDialogHtml( $profile, $term, $numResults, $totalResults, $offset ) {
+       protected function shortDialogHtml(
+               $profile,
+               $term,
+               $numResults,
+               $totalResults,
+               $offset,
+               array $options = []
+       ) {
                $html = '';
 
-               $searchWidget = new SearchInputWidget( [
+               $searchWidget = new SearchInputWidget( $options + [
                        'id' => 'searchText',
                        'name' => 'search',
                        'autofocus' => trim( $term ) === '',
@@ -169,11 +184,10 @@ class SearchFormWidget {
         * @return bool
         */
        protected function startsWithImage( $term ) {
-               global $wgContLang;
-
                $parts = explode( ':', $term );
                return count( $parts ) > 1
-                       ? $wgContLang->getNsIndex( $parts[0] ) === NS_FILE
+                       ? MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $parts[0] ) ===
+                               NS_FILE
                        : false;
        }
 
@@ -234,17 +248,17 @@ class SearchFormWidget {
         * @return string HTML
         */
        protected function powerSearchBox( $term, array $opts ) {
-               global $wgContLang;
-
                $rows = [];
                $activeNamespaces = $this->specialSearch->getNamespaces();
+               $langConverter = $this->specialSearch->getLanguage();
                foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) {
-                       $subject = MWNamespace::getSubject( $namespace );
+                       $subject = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               getSubject( $namespace );
                        if ( !isset( $rows[$subject] ) ) {
                                $rows[$subject] = "";
                        }
 
-                       $name = $wgContLang->getConverter()->convertNamespace( $namespace );
+                       $name = $langConverter->convertNamespace( $namespace );
                        if ( $name === '' ) {
                                $name = $this->specialSearch->msg( 'blanknamespace' )->text();
                        }
@@ -304,8 +318,14 @@ class SearchFormWidget {
                return "<fieldset id='mw-searchoptions'>" .
                        "<legend>" . $this->specialSearch->msg( 'powersearch-legend' )->escaped() . '</legend>' .
                        "<h4>" . $this->specialSearch->msg( 'powersearch-ns' )->parse() . '</h4>' .
-                       // populated by js if available
-                       "<div id='mw-search-togglebox'></div>" .
+                       // Handled by JavaScript if available
+                       '<div id="mw-search-togglebox">' .
+                       '<label>' . $this->specialSearch->msg( 'powersearch-togglelabel' )->escaped() . '</label>' .
+                       '<input type="button" id="mw-search-toggleall" value="' .
+                       $this->specialSearch->msg( 'powersearch-toggleall' )->escaped() . '"/>' .
+                       '<input type="button" id="mw-search-togglenone" value="' .
+                       $this->specialSearch->msg( 'powersearch-togglenone' )->escaped() . '"/>' .
+                       '</div>' .
                        $divider .
                        implode(
                                $divider,