Wikia code/includes/specials/SpecialSearch.php

--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\specials\SpecialSearch.php	2011-07-18 22:31:17.799804700 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\specials\SpecialSearch.php	2011-08-17 15:28:16.450195300 +0100
@@ -30,12 +30,14 @@
  */
 function wfSpecialSearch( $par = '' ) {
 	global $wgRequest, $wgUser;
+	global $wgUseWikiaSearchUI;
 	// Strip underscores from title parameter; most of the time we'll want
 	// text form here. But don't strip underscores from actual text params!
 	$titleParam = str_replace( '_', ' ', $par );
 	// Fetch the search term
 	$search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
-	$searchPage = new SpecialSearch( $wgRequest, $wgUser );
+	$class = $wgUseWikiaSearchUI ? 'SpecialWikiaSearch' : 'SpecialSearch';
+	$searchPage = new $class( $wgRequest, $wgUser );
 	if( $wgRequest->getVal( 'fulltext' )
 		|| !is_null( $wgRequest->getVal( 'offset' ))
 		|| !is_null( $wgRequest->getVal( 'searchx' )) )
@@ -128,6 +130,16 @@
 
 		$this->setupPage( $term );
 
+		// Wikia change /Begin (ADi)
+		if(($search instanceof SearchErrorReporting) && $search->getError()) {
+			$wgOut->addWikiText( '==' . $search->getError() . '==' );
+			$wgOut->addHTML( $search->getErrorTracker());
+			$wgOut->addHTML( $this->powerSearchBox( $term ) );
+			wfProfileOut( __METHOD__ );
+			return;
+		}
+		// Wikia change /End (ADi)
+
 		if( $wgDisableTextSearch ) {
 			global $wgSearchForwardUrl;
 			if( $wgSearchForwardUrl ) {
@@ -201,15 +213,6 @@
 				)
 			)
 		);
-		$wgOut->addHtml(
-			Xml::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
-			Xml::openElement( 'tr' ) .
-			Xml::openElement( 'td' ) . "\n"	.
-			$this->shortDialog( $term ) .
-			Xml::closeElement('td') .
-			Xml::closeElement('tr') .
-			Xml::closeElement('table')
-		);
 
 		// Sometimes the search engine knows there are too many hits
 		if( $titleMatches instanceof SearchResultTooMany ) {
@@ -251,12 +254,17 @@
 			$totalRes += $textMatches->getTotalHits();
 			
 		// show number of results and current offset
+		/* Wikia change begin - @author: Macbre */
+		if (!Wikia::isOasis()) {
 		$wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
 		if( $this->searchAdvanced ) {
 			$wgOut->addHTML( $this->powerSearchBox( $term ) );
 		}
+		}
+
+		//$wgOut->addHtml( Xml::closeElement( 'form' ) );
+		/* Wikia change end */
 		
-		$wgOut->addHtml( Xml::closeElement( 'form' ) );
 		$wgOut->addHtml( "<div class='searchresults'>" );
 
 		// prev/next links
@@ -313,12 +321,32 @@
 		if( $num || $this->offset ) {
 			$wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
 		}
+
+		// show number of results and current offset
+		/* Wikia change begin - @author: Macbre */
+		if (Wikia::isOasis()) {
+			$wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
+			if( $this->searchAdvanced ) {
+				$wgOut->addHTML( $this->powerSearchBox( $term ) );
+			}
+		}
+
+		$wgOut->addHtml( Xml::closeElement( 'form' ) );
+		/* Wikia change end */
+
 		wfProfileOut( __METHOD__ );
 	}
 	
 	protected function showCreateLink( $t ) {
 		global $wgOut;
 		
+		/* Wikia change begin - @author: Macbre */
+		/* Don't show "create an article" link in Oasis */
+		if (Wikia::isOasis()) {
+			return '';
+		}
+		/* Wikia change end */
+
 		// show direct page/create link if applicable
 		$messageName = null;
 		if( !is_null($t) ) {
@@ -418,8 +446,13 @@
 		}
 		$off = $this->offset + 1;
 		$out .= "<ul class='mw-search-results'>\n";
+		$num = 0;
 		while( $result = $matches->next() ) {
+			// Wikia change /Begin (ADi)
+			wfRunHooks( 'SpecialSearchShowHit', array( &$out, $result, $terms, $num ) );
+			// Wikia change /End (ADi)
 			$out .= $this->showHit( $result, $terms );
+			$num++;
 		}
 		$out .= "</ul>\n";
 
@@ -568,6 +600,12 @@
 				$thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
 				if( $thumb ) {
 					$desc = $img->getShortDesc();
+
+					// Wikia change /Begin (ADi)
+					$resultData = "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>";
+					wfRunHooks( 'SearchShowHit', array( $result, &$link, &$redirect, &$section, &$extract, &$resultData ) );
+					// Wikia change /End
+
 					wfProfileOut( __METHOD__ );
 					// Float doesn't seem to interact well with the bullets.
 					// Table messes up vertical alignment of the bullets.
@@ -581,7 +619,7 @@
 						'<td valign="top">' .
 						$link .
 						$extract .
-						"<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
+						$resultData .
 						'</td>' .
 						'</tr>' .
 						'</table>' .
@@ -590,11 +628,13 @@
 			}
 		}
 
-		wfProfileOut( __METHOD__ );
-		return "<li>{$link} {$redirect} {$section} {$extract}\n" .
-			"<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
-			"</li>\n";
+		// Wikia change /Begin (ADi)
+		$resultData = "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>";
+		wfRunHooks( 'SearchShowHit', array( $result, &$link, &$redirect, &$section, &$extract, &$resultData ) );
+		// Wikia change /End
 
+		wfProfileOut( __METHOD__ );
+		return "<li>{$link} {$redirect} {$section} {$extract}\n{$resultData}</li>\n";
 	}
 
 	/**
@@ -874,7 +914,17 @@
 	protected function formHeader( $term, $resultsShown, $totalNum ) {
 		global $wgContLang, $wgLang;
 		
-		$out = Xml::openElement('div', array( 'class' =>  'mw-search-formheader' ) );
+		/* Wikia change begin - @author: Macbre */
+		$out = Xml::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
+			Xml::openElement( 'tr' ) .
+			Xml::openElement( 'td' ) . "\n"	.
+			$this->shortDialog( $term ) .
+			Xml::closeElement('td') .
+			Xml::closeElement('tr') .
+			Xml::closeElement('table');
+		/* Wikia change end */
+
+		$out .= Xml::openElement('div', array( 'class' =>  'mw-search-formheader' ) );
 		
 		$bareterm = $term;
 		if( $this->startsWithImage( $term ) ) {
@@ -951,7 +1000,7 @@
 		$out .= Html::input( 'search', $term, 'search', array(
 			'id' => $this->searchAdvanced ? 'powerSearchText' : 'searchText',
 			'size' => '50',
-			'autofocus'
+			#'autofocus' // Wikia - commented out due to BugId:4016
 		) ) . "\n";
 		$out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
 		$out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";