MediaWiki REL1_31
BasicSearchResultSetWidget.php
Go to the documentation of this file.
1<?php
2
4
5use Message;
8use Status;
9
16 protected $specialPage;
18 protected $resultWidget;
20 protected $sidebarWidget;
21
22 public function __construct(
26 ) {
27 $this->specialPage = $specialPage;
28 $this->resultWidget = $resultWidget;
29 $this->sidebarWidget = $sidebarWidget;
30 }
31
39 public function render(
40 $term,
41 $offset,
42 SearchResultSet $titleResultSet = null,
43 SearchResultSet $textResultSet = null
44 ) {
45 global $wgContLang;
46
47 $hasTitle = $titleResultSet ? $titleResultSet->numRows() > 0 : false;
48 $hasText = $textResultSet ? $textResultSet->numRows() > 0 : false;
49 $hasSecondary = $textResultSet
50 ? $textResultSet->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS )
51 : false;
52 $hasSecondaryInline = $textResultSet
53 ? $textResultSet->hasInterwikiResults( SearchResultSet::INLINE_RESULTS )
54 : false;
55
56 if ( !$hasTitle && !$hasText && !$hasSecondary && !$hasSecondaryInline ) {
57 return '';
58 }
59
60 $out = '';
61 if ( $hasTitle ) {
62 $out .= $this->header( $this->specialPage->msg( 'titlematches' ) )
63 . $this->renderResultSet( $titleResultSet, $offset );
64 }
65
66 if ( $hasText ) {
67 if ( $hasTitle ) {
68 $out .= "<div class='mw-search-visualclear'></div>" .
69 $this->header( $this->specialPage->msg( 'textmatches' ) );
70 }
71 $out .= $this->renderResultSet( $textResultSet, $offset );
72 }
73
74 if ( $hasSecondaryInline ) {
75 $iwResults = $textResultSet->getInterwikiResults( SearchResultSet::INLINE_RESULTS );
76 foreach ( $iwResults as $interwiki => $results ) {
77 if ( $results instanceof Status || $results->numRows() === 0 ) {
78 // ignore bad interwikis for now
79 continue;
80 }
81 $out .=
82 "<h2 class='mw-search-interwiki-header mw-search-visualclear'>" .
83 $this->specialPage->msg( "search-interwiki-results-{$interwiki}" )->parse() .
84 "</h2>";
85 $out .= $this->renderResultSet( $results, $offset );
86 }
87 }
88
89 if ( $hasSecondary ) {
90 $out .= $this->sidebarWidget->render(
91 $term,
92 $textResultSet->getInterwikiResults( SearchResultSet::SECONDARY_RESULTS )
93 );
94 }
95
96 // Convert the whole thing to desired language variant
97 // TODO: Move this up to Special:Search?
98 return $wgContLang->convert( $out );
99 }
100
109 protected function header( Message $msg ) {
110 return "<h2>" .
111 "<span class='mw-headline'>" . $msg->escaped() . "</span>" .
112 "</h2>";
113 }
114
120 protected function renderResultSet( SearchResultSet $resultSet, $offset ) {
121 global $wgContLang;
122
123 $terms = $wgContLang->convertForSearchResult( $resultSet->termMatches() );
124
125 $hits = [];
126 $result = $resultSet->next();
127 while ( $result ) {
128 $hits[] .= $this->resultWidget->render( $result, $terms, $offset++ );
129 $result = $resultSet->next();
130 }
131
132 return "<ul class='mw-search-results'>" . implode( '', $hits ) . "</ul>";
133 }
134}
header(Message $msg)
Generate a headline for a section of the search results.
render( $term, $offset, SearchResultSet $titleResultSet=null, SearchResultSet $textResultSet=null)
__construct(SpecialSearch $specialPage, SearchResultWidget $resultWidget, SearchResultSetWidget $sidebarWidget)
Renders one or more SearchResultSets into a sidebar grouped by interwiki prefix.
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
next()
Fetches next search result, or false.
termMatches()
Fetch an array of regular expression fragments for matching the search terms as parsed by this engine...
implements Special:Search - Run text & title search and display the output
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
For QUnit the mediawiki tests qunit testrunner dependency will be added to any module whereas SearchGetNearMatch runs after $term
Definition hooks.txt:2845
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:864
Renders a set of search results to HTML.
Renders a single search result to HTML.