*/
protected $runSuggestion = true;
+ /**
+ * Names of the wikis, in format: Interwiki prefix -> caption
+ * @var array
+ */
+ protected $customCaptions;
+
const NAMESPACES_CURRENT = 'sense';
public function __construct() {
return;
}
+ $out->addJsConfigVars( array( 'searchTerm' => $search ) );
$this->searchEngineType = $request->getVal( 'srbackend' );
if ( $request->getVal( 'fulltext' )
if ( $numTextMatches > 0 ) {
$out->addHTML( $this->showMatches( $textMatches ) );
}
- // show interwiki results if any
- if ( $textMatches->hasInterwikiResults() ) {
- $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(), $term ) );
+
+ // show secondary interwiki results if any
+ if ( $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) {
+ $out->addHTML( $this->showInterwiki( $textMatches->getInterwikiResults(
+ SearchResultSet::SECONDARY_RESULTS ), $term ) );
}
$textMatches->free();
}
+
+ $hasOtherResults = $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
+
if ( $num === 0 ) {
if ( $textStatus ) {
$out->addHTML( '<div class="error">' .
$textStatus->getMessage( 'search-error' ) . '</div>' );
} else {
- $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
- array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
$this->showCreateLink( $title, $num, $titleMatches, $textMatches );
+ $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
+ array( $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
+ wfEscapeWikiText( $term )
+ ) );
}
}
- $out->addHTML( '<div class="visualClear"></div>\n' );
+ if ( $hasOtherResults ) {
+ foreach ( $textMatches->getInterwikiResults( SearchResultSet::INLINE_RESULTS )
+ as $interwiki => $interwikiResult ) {
+ if ( $interwikiResult instanceof Status || $interwikiResult->numRows() == 0 ) {
+ // ignore bad interwikis for now
+ continue;
+ }
+ // TODO: wiki header
+ $out->addHTML( $this->showMatches( $interwikiResult, $interwiki ) );
+ }
+ }
+
+ $out->addHTML( '<div class="visualClear"></div>' );
+
if ( $prevnext ) {
$out->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
}
$out->addHtml( "</div>" );
- Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out ) );
+ Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
}
+ /**
+ * Produce wiki header for interwiki results
+ * @param string $interwiki Interwiki name
+ * @param SearchResultSet $interwikiResult The result set
+ */
+ protected function interwikiHeader( $interwiki, $interwikiResult ) {
+ // TODO: we need to figure out how to name wikis correctly
+ $wikiMsg = $this->msg( 'search-interwiki-results-' . $interwiki )->parse();
+ return "<p class=\"mw-search-interwiki-header\">\n$wikiMsg</p>";
+ }
+
/**
* Decide if the suggested query should be run, and it's results returned
* instead of the provided $textMatches
return false;
}
- // Generate a random number between 0 and 1. If the
- // number is less than the desired percentages run it.
- $rand = rand( 0, getrandmax() ) / getrandmax();
- return $this->getConfig()->get( 'SearchRunSuggestedQueryPercent' ) > $rand;
+ return $this->getConfig()->get( 'SearchRunSuggestedQuery' );
}
/**
$suggest = Linker::linkKnown(
$this->getPageTitle(),
$textMatches->getSuggestionSnippet() ?: null,
- array(),
+ array( 'id' => 'mw-search-DYM-suggestion' ),
$stParams
);
- # html of did you mean... search suggestion link
+ # HTML of did you mean... search suggestion link
return Html::rawElement(
'div',
array( 'class' => 'searchdidyoumean' ),
$rewritten = Linker::linkKnown(
$this->getPageTitle(),
$textMatches->getQueryAfterRewriteSnippet() ?: null,
- array(),
+ array( 'id' => 'mw-search-DYM-rewritten' ),
$stParams
);
$original = Linker::linkKnown(
$this->getPageTitle(),
htmlspecialchars( $term ),
- array(),
+ array( 'id' => 'mw-search-DYM-original' ),
$stParams
);
* Show whole set of results
*
* @param SearchResultSet $matches
+ * @param string $interwiki Interwiki name
*
* @return string
*/
- protected function showMatches( &$matches ) {
+ protected function showMatches( &$matches, $interwiki = null ) {
global $wgContLang;
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
-
- $out = "<ul class='mw-search-results'>\n";
+ $out = '';
$result = $matches->next();
+ $pos = $this->offset;
+
+ if ( $result && $interwiki ) {
+ $out .= $this->interwikiHeader( $interwiki, $result );
+ }
+
+ $out .= "<ul class='mw-search-results'>\n";
while ( $result ) {
- $out .= $this->showHit( $result, $terms );
+ $out .= $this->showHit( $result, $terms, ++$pos );
$result = $matches->next();
}
$out .= "</ul>\n";
*
* @param SearchResult $result
* @param array $terms Terms to highlight
+ * @param int $position Position within the search results, including offset.
*
* @return string
*/
- protected function showHit( $result, $terms ) {
+ protected function showHit( $result, $terms, $position ) {
if ( $result->isBrokenTitle() ) {
return '';
}
$link_t = clone $title;
+ $query = array();
Hooks::run( 'ShowSearchHitTitle',
- array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
+ array( &$link_t, &$titleSnippet, $result, $terms, $this, &$query ) );
$link = Linker::linkKnown(
$link_t,
- $titleSnippet
+ $titleSnippet,
+ array( 'data-serp-pos' => $position ), // HTML attributes
+ $query
);
- //If page content is not readable, just return the title.
- //This is not quite safe, but better than showing excerpts from non-readable pages
- //Note that hiding the entry entirely would screw up paging.
+ // If page content is not readable, just return the title.
+ // This is not quite safe, but better than showing excerpts from non-readable pages
+ // Note that hiding the entry entirely would screw up paging.
if ( !$title->userCan( 'read', $this->getUser() ) ) {
return "<li>{$link}</li>\n";
}
return $html;
}
+ /**
+ * Extract custom captions from search-interwiki-custom message
+ */
+ protected function getCustomCaptions() {
+ if ( is_null( $this->customCaptions ) ) {
+ $this->customCaptions = array();
+ // format per line <iwprefix>:<caption>
+ $customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() );
+ foreach ( $customLines as $line ) {
+ $parts = explode( ":", $line, 2 );
+ if ( count( $parts ) == 2 ) { // validate line
+ $this->customCaptions[$parts[0]] = $parts[1];
+ }
+ }
+ }
+ }
+
/**
* Show results from other wikis
*
$out .= "<ul class='mw-search-iwresults'>\n";
// work out custom project captions
- $customCaptions = array();
- // format per line <iwprefix>:<caption>
- $customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() );
- foreach ( $customLines as $line ) {
- $parts = explode( ":", $line, 2 );
- if ( count( $parts ) == 2 ) { // validate line
- $customCaptions[$parts[0]] = $parts[1];
- }
- }
+ $this->getCustomCaptions();
if ( !is_array( $matches ) ) {
$matches = array( $matches );
$prev = null;
$result = $set->next();
while ( $result ) {
- $out .= $this->showInterwikiHit( $result, $prev, $query, $customCaptions );
+ $out .= $this->showInterwikiHit( $result, $prev, $query );
$prev = $result->getInterwikiPrefix();
$result = $set->next();
}
* @param SearchResult $result
* @param string $lastInterwiki
* @param string $query
- * @param array $customCaptions Interwiki prefix -> caption
*
* @return string
*/
- protected function showInterwikiHit( $result, $lastInterwiki, $query, $customCaptions ) {
+ protected function showInterwikiHit( $result, $lastInterwiki, $query ) {
if ( $result->isBrokenTitle() ) {
return '';
$out = "";
// display project name
if ( is_null( $lastInterwiki ) || $lastInterwiki != $title->getInterwiki() ) {
- if ( array_key_exists( $title->getInterwiki(), $customCaptions ) ) {
+ if ( array_key_exists( $title->getInterwiki(), $this->customCaptions ) ) {
// captions from 'search-interwiki-custom'
- $caption = $customCaptions[$title->getInterwiki()];
+ $caption = $this->customCaptions[$title->getInterwiki()];
} else {
// default is to show the hostname of the other wiki which might suck
// if there are many wikis on one hostname