Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1402,6 +1402,9 @@ |
1403 | 1403 | target doesn't exist |
1404 | 1404 | $title: title object generated from the text entred by the user |
1405 | 1405 | |
| 1406 | +'SpecialSearchProfiles': allows modification of search profiles |
| 1407 | +&$profiles: profiles, which can be modified. |
| 1408 | + |
1406 | 1409 | 'SpecialSearchResults': called before search result display when there |
1407 | 1410 | are matches |
1408 | 1411 | $term: string of search term |
Index: trunk/phase3/includes/specials/SpecialSearch.php |
— | — | @@ -334,16 +334,15 @@ |
335 | 335 | $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); |
336 | 336 | if( $this->searchAdvanced ) |
337 | 337 | $this->active = 'advanced'; |
338 | | - else if( $this->namespaces === array(NS_FILE) || $this->startsWithImage( $term ) ) |
339 | | - $this->active = 'images'; |
340 | | - elseif( $this->namespaces === $nsAllSet || $this->startsWithAll( $term ) ) |
341 | | - $this->active = 'all'; |
342 | | - elseif( $this->namespaces === SearchEngine::defaultNamespaces() ) |
343 | | - $this->active = 'default'; |
344 | | - elseif( $this->namespaces === SearchEngine::helpNamespaces() ) |
345 | | - $this->active = 'help'; |
346 | | - else |
347 | | - $this->active = 'advanced'; |
| 338 | + else { |
| 339 | + $profiles = $this->getSearchProfiles(); |
| 340 | + |
| 341 | + foreach( $profiles as $key => $data ) { |
| 342 | + if ( $this->namespaces == $data['namespaces'] && $key != 'advanced') |
| 343 | + $this->active = $key; |
| 344 | + } |
| 345 | + |
| 346 | + } |
348 | 347 | # Should advanced UI be used? |
349 | 348 | $this->searchAdvanced = ($this->active === 'advanced'); |
350 | 349 | if( !empty( $term ) ) { |
— | — | @@ -811,20 +810,11 @@ |
812 | 811 | "document.getElementById('searchText').focus();" . |
813 | 812 | "});" ); |
814 | 813 | } |
815 | | - |
816 | | - protected function formHeader( $term, $resultsShown, $totalNum ) { |
817 | | - global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; |
818 | | - |
819 | | - $out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) ); |
820 | | - |
821 | | - $bareterm = $term; |
822 | | - if( $this->startsWithImage( $term ) ) { |
823 | | - // Deletes prefixes |
824 | | - $bareterm = substr( $term, strpos( $term, ':' ) + 1 ); |
825 | | - } |
| 814 | + |
| 815 | + protected function getSearchProfiles() { |
| 816 | + // Builds list of Search Types (profiles) |
826 | 817 | $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); |
827 | 818 | |
828 | | - // Builds list of Search Types (profiles) |
829 | 819 | $profiles = array( |
830 | 820 | 'default' => array( |
831 | 821 | 'message' => 'searchprofile-articles', |
— | — | @@ -859,6 +849,30 @@ |
860 | 850 | 'parameters' => array( 'advanced' => 1 ), |
861 | 851 | ) |
862 | 852 | ); |
| 853 | + |
| 854 | + wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) ); |
| 855 | + |
| 856 | + foreach( $profiles as $key => &$data ) { |
| 857 | + sort($data['namespaces']); |
| 858 | + } |
| 859 | + |
| 860 | + return $profiles; |
| 861 | + } |
| 862 | + |
| 863 | + protected function formHeader( $term, $resultsShown, $totalNum ) { |
| 864 | + global $wgContLang, $wgCanonicalNamespaceNames, $wgLang; |
| 865 | + |
| 866 | + $out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) ); |
| 867 | + |
| 868 | + $bareterm = $term; |
| 869 | + if( $this->startsWithImage( $term ) ) { |
| 870 | + // Deletes prefixes |
| 871 | + $bareterm = substr( $term, strpos( $term, ':' ) + 1 ); |
| 872 | + } |
| 873 | + |
| 874 | + |
| 875 | + $profiles = $this->getSearchProfiles(); |
| 876 | + |
863 | 877 | // Outputs XML for Search Types |
864 | 878 | $out .= Xml::openElement( 'div', array( 'class' => 'search-types' ) ); |
865 | 879 | $out .= Xml::openElement( 'ul' ); |
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php |
— | — | @@ -237,6 +237,8 @@ |
238 | 238 | 'lqt-search-legend' => 'Search discussions on this page', |
239 | 239 | 'lqt-search-label' => 'Search terms:', |
240 | 240 | 'lqt-search-button' => 'Search', |
| 241 | + 'searchprofile-threads' => 'Discussions', |
| 242 | + 'searchprofile-threads-tooltip' => 'Search threaded discussions and talk pages', |
241 | 243 | |
242 | 244 | // Some AJAX stuff |
243 | 245 | 'lqt-ajax-updated' => 'This thread has new posts.', |
Index: trunk/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -72,6 +72,7 @@ |
73 | 73 | |
74 | 74 | // Search |
75 | 75 | $wgHooks['ShowSearchHitTitle'][] = 'LqtHooks::customiseSearchResultTitle'; |
| 76 | +$wgHooks['SpecialSearchProfiles'][] = 'LqtHooks::customiseSearchProfiles'; |
76 | 77 | |
77 | 78 | // Rename |
78 | 79 | $wgHooks['RenameUserSQL'][] = 'LqtHooks::onUserRename'; |
Index: trunk/extensions/LiquidThreads/classes/Hooks.php |
— | — | @@ -260,4 +260,31 @@ |
261 | 261 | |
262 | 262 | return true; |
263 | 263 | } |
| 264 | + |
| 265 | + static function customiseSearchProfiles( &$profiles ) { |
| 266 | + wfLoadExtensionMessages( 'LiquidThreads' ); |
| 267 | + |
| 268 | + $namespaces = array( NS_LQT_THREAD, NS_LQT_SUMMARY ); |
| 269 | + |
| 270 | + // Add odd namespaces |
| 271 | + foreach( SearchEngine::searchableNamespaces() as $ns => $nsName ) { |
| 272 | + if ($ns % 2 == 1) { |
| 273 | + $namespaces[] = $ns; |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + $insert = array( |
| 278 | + 'threads' => |
| 279 | + array( |
| 280 | + 'message' => 'searchprofile-threads', |
| 281 | + 'tooltip' => 'searchprofile-threads-tooltip', |
| 282 | + 'namespaces' => $namespaces, |
| 283 | + 'namespace-messages' => SearchEngine::namespacesAsText( $namespaces ), |
| 284 | + ), |
| 285 | + ); |
| 286 | + |
| 287 | + $profiles = wfArrayInsertAfter( $profiles, $insert, 'help' ); |
| 288 | + |
| 289 | + return true; |
| 290 | + } |
264 | 291 | } |