X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/widget/search/BasicSearchResultSetWidget.php diff --git a/includes/widget/search/BasicSearchResultSetWidget.php b/includes/widget/search/BasicSearchResultSetWidget.php new file mode 100644 index 00000000..bf59fe9e --- /dev/null +++ b/includes/widget/search/BasicSearchResultSetWidget.php @@ -0,0 +1,135 @@ +specialPage = $specialPage; + $this->resultWidget = $resultWidget; + $this->sidebarWidget = $sidebarWidget; + } + + /** + * @param string $term The search term to highlight + * @param int $offset The offset of the first result in the result set + * @param SearchResultSet|null $titleResultSet Results of searching only page titles + * @param SearchResultSet|null $textResultSet Results of general full text search. + * @return string HTML + */ + public function render( + $term, + $offset, + SearchResultSet $titleResultSet = null, + SearchResultSet $textResultSet = null + ) { + global $wgContLang; + + $hasTitle = $titleResultSet ? $titleResultSet->numRows() > 0 : false; + $hasText = $textResultSet ? $textResultSet->numRows() > 0 : false; + $hasSecondary = $textResultSet + ? $textResultSet->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) + : false; + $hasSecondaryInline = $textResultSet + ? $textResultSet->hasInterwikiResults( SearchResultSet::INLINE_RESULTS ) + : false; + + if ( !$hasTitle && !$hasText && !$hasSecondary && !$hasSecondaryInline ) { + return ''; + } + + $out = ''; + if ( $hasTitle ) { + $out .= $this->header( $this->specialPage->msg( 'titlematches' ) ) + . $this->renderResultSet( $titleResultSet, $offset ); + } + + if ( $hasText ) { + if ( $hasTitle ) { + $out .= "
" . + $this->header( $this->specialPage->msg( 'textmatches' ) ); + } + $out .= $this->renderResultSet( $textResultSet, $offset ); + } + + if ( $hasSecondaryInline ) { + $iwResults = $textResultSet->getInterwikiResults( SearchResultSet::INLINE_RESULTS ); + foreach ( $iwResults as $interwiki => $results ) { + if ( $results instanceof Status || $results->numRows() === 0 ) { + // ignore bad interwikis for now + continue; + } + $out .= + "