r56026 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56025‎ | r56026 | r56027 >
Date:11:50, 8 September 2009
Author:werdna
Status:ok (Comments)
Tags:
Comment:
Add "Discussions" option to search when LiquidThreads is active. Includes some fixes to SpecialSearch.php, to allow this sort of change
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1402,6 +1402,9 @@
14031403 target doesn't exist
14041404 $title: title object generated from the text entred by the user
14051405
 1406+'SpecialSearchProfiles': allows modification of search profiles
 1407+&$profiles: profiles, which can be modified.
 1408+
14061409 'SpecialSearchResults': called before search result display when there
14071410 are matches
14081411 $term: string of search term
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -334,16 +334,15 @@
335335 $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
336336 if( $this->searchAdvanced )
337337 $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+ }
348347 # Should advanced UI be used?
349348 $this->searchAdvanced = ($this->active === 'advanced');
350349 if( !empty( $term ) ) {
@@ -811,20 +810,11 @@
812811 "document.getElementById('searchText').focus();" .
813812 "});" );
814813 }
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)
826817 $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
827818
828 - // Builds list of Search Types (profiles)
829819 $profiles = array(
830820 'default' => array(
831821 'message' => 'searchprofile-articles',
@@ -859,6 +849,30 @@
860850 'parameters' => array( 'advanced' => 1 ),
861851 )
862852 );
 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+
863877 // Outputs XML for Search Types
864878 $out .= Xml::openElement( 'div', array( 'class' => 'search-types' ) );
865879 $out .= Xml::openElement( 'ul' );
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -237,6 +237,8 @@
238238 'lqt-search-legend' => 'Search discussions on this page',
239239 'lqt-search-label' => 'Search terms:',
240240 'lqt-search-button' => 'Search',
 241+ 'searchprofile-threads' => 'Discussions',
 242+ 'searchprofile-threads-tooltip' => 'Search threaded discussions and talk pages',
241243
242244 // Some AJAX stuff
243245 'lqt-ajax-updated' => 'This thread has new posts.',
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -72,6 +72,7 @@
7373
7474 // Search
7575 $wgHooks['ShowSearchHitTitle'][] = 'LqtHooks::customiseSearchResultTitle';
 76+$wgHooks['SpecialSearchProfiles'][] = 'LqtHooks::customiseSearchProfiles';
7677
7778 // Rename
7879 $wgHooks['RenameUserSQL'][] = 'LqtHooks::onUserRename';
Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -260,4 +260,31 @@
261261
262262 return true;
263263 }
 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+ }
264291 }

Comments

#Comment by Nikerabbit (talk | contribs)   11:42, 22 April 2011

Filed a bug about inssufficiently documented hook: bug 28660

Status & tagging log