From: Andrew Garrett Date: Tue, 8 Sep 2009 11:50:31 +0000 (+0000) Subject: Add "Discussions" option to search when LiquidThreads is active. Includes some fixes... X-Git-Tag: 1.31.0-rc.0~39858 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=1ec4f9dbaa5d6893c345d1c8cd43441719e39f15;p=lhc%2Fweb%2Fwiklou.git Add "Discussions" option to search when LiquidThreads is active. Includes some fixes to SpecialSearch.php, to allow this sort of change --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 5d28c4743c..01fef856fe 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1402,6 +1402,9 @@ $opts: FormOptions for this request target doesn't exist $title: title object generated from the text entred by the user +'SpecialSearchProfiles': allows modification of search profiles +&$profiles: profiles, which can be modified. + 'SpecialSearchResults': called before search result display when there are matches $term: string of search term diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index dfdd25d033..0fc81ce293 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -334,16 +334,15 @@ class SpecialSearch { $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); if( $this->searchAdvanced ) $this->active = 'advanced'; - else if( $this->namespaces === array(NS_FILE) || $this->startsWithImage( $term ) ) - $this->active = 'images'; - elseif( $this->namespaces === $nsAllSet || $this->startsWithAll( $term ) ) - $this->active = 'all'; - elseif( $this->namespaces === SearchEngine::defaultNamespaces() ) - $this->active = 'default'; - elseif( $this->namespaces === SearchEngine::helpNamespaces() ) - $this->active = 'help'; - else - $this->active = 'advanced'; + else { + $profiles = $this->getSearchProfiles(); + + foreach( $profiles as $key => $data ) { + if ( $this->namespaces == $data['namespaces'] && $key != 'advanced') + $this->active = $key; + } + + } # Should advanced UI be used? $this->searchAdvanced = ($this->active === 'advanced'); if( !empty( $term ) ) { @@ -811,20 +810,11 @@ class SpecialSearch { "document.getElementById('searchText').focus();" . "});" ); } - - protected function formHeader( $term, $resultsShown, $totalNum ) { - global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; - - $out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) ); - - $bareterm = $term; - if( $this->startsWithImage( $term ) ) { - // Deletes prefixes - $bareterm = substr( $term, strpos( $term, ':' ) + 1 ); - } + + protected function getSearchProfiles() { + // Builds list of Search Types (profiles) $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); - // Builds list of Search Types (profiles) $profiles = array( 'default' => array( 'message' => 'searchprofile-articles', @@ -859,6 +849,30 @@ class SpecialSearch { 'parameters' => array( 'advanced' => 1 ), ) ); + + wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) ); + + foreach( $profiles as $key => &$data ) { + sort($data['namespaces']); + } + + return $profiles; + } + + protected function formHeader( $term, $resultsShown, $totalNum ) { + global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; + + $out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) ); + + $bareterm = $term; + if( $this->startsWithImage( $term ) ) { + // Deletes prefixes + $bareterm = substr( $term, strpos( $term, ':' ) + 1 ); + } + + + $profiles = $this->getSearchProfiles(); + // Outputs XML for Search Types $out .= Xml::openElement( 'div', array( 'class' => 'search-types' ) ); $out .= Xml::openElement( 'ul' );