MediaWiki REL1_33
BasicSearchResultSetWidget.php
Go to the documentation of this file.
1<?php
2
4
6use Message;
9use Status;
10
17 protected $specialPage;
19 protected $resultWidget;
21 protected $sidebarWidget;
22
23 public function __construct(
27 ) {
28 $this->specialPage = $specialPage;
29 $this->resultWidget = $resultWidget;
30 $this->sidebarWidget = $sidebarWidget;
31 }
32
40 public function render(
41 $term,
42 $offset,
43 SearchResultSet $titleResultSet = null,
44 SearchResultSet $textResultSet = null
45 ) {
46 $hasTitle = $titleResultSet ? $titleResultSet->numRows() > 0 : false;
47 $hasText = $textResultSet ? $textResultSet->numRows() > 0 : false;
48 $hasSecondary = $textResultSet
49 ? $textResultSet->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS )
50 : false;
51 $hasSecondaryInline = $textResultSet
52 ? $textResultSet->hasInterwikiResults( SearchResultSet::INLINE_RESULTS )
53 : false;
54
55 if ( !$hasTitle && !$hasText && !$hasSecondary && !$hasSecondaryInline ) {
56 return '';
57 }
58
59 $out = '';
60 if ( $hasTitle ) {
61 $out .= $this->header( $this->specialPage->msg( 'titlematches' ) )
62 . $this->renderResultSet( $titleResultSet, $offset );
63 }
64
65 if ( $hasText ) {
66 if ( $hasTitle ) {
67 $out .= "<div class='mw-search-visualclear'></div>" .
68 $this->header( $this->specialPage->msg( 'textmatches' ) );
69 }
70 $out .= $this->renderResultSet( $textResultSet, $offset );
71 }
72
73 if ( $hasSecondaryInline ) {
74 $iwResults = $textResultSet->getInterwikiResults( SearchResultSet::INLINE_RESULTS );
75 foreach ( $iwResults as $interwiki => $results ) {
76 if ( $results instanceof Status || $results->numRows() === 0 ) {
77 // ignore bad interwikis for now
78 continue;
79 }
80 $out .=
81 "<h2 class='mw-search-interwiki-header mw-search-visualclear'>" .
82 $this->specialPage->msg( "search-interwiki-results-{$interwiki}" )->parse() .
83 "</h2>";
84 $out .= $this->renderResultSet( $results, $offset );
85 }
86 }
87
88 if ( $hasSecondary ) {
89 $out .= $this->sidebarWidget->render(
90 $term,
91 $textResultSet->getInterwikiResults( SearchResultSet::SECONDARY_RESULTS )
92 );
93 }
94
95 // Convert the whole thing to desired language variant
96 // TODO: Move this up to Special:Search?
97 return MediaWikiServices::getInstance()->getContentLanguage()->convert( $out );
98 }
99
108 protected function header( Message $msg ) {
109 return "<h2>" .
110 "<span class='mw-headline'>" . $msg->escaped() . "</span>" .
111 "</h2>";
112 }
113
119 protected function renderResultSet( SearchResultSet $resultSet, $offset ) {
120 $terms = MediaWikiServices::getInstance()->getContentLanguage()->
121 convertForSearchResult( $resultSet->termMatches() );
122
123 $hits = [];
124 foreach ( $resultSet as $result ) {
125 $hits[] = $this->resultWidget->render( $result, $terms, $offset++ );
126 }
127
128 return "<ul class='mw-search-results'>" . implode( '', $hits ) . "</ul>";
129 }
130}
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
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:160
escaped()
Returns the message text.
Definition Message.php:990
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 hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:855
whereas SearchGetNearMatch runs after $term
Definition hooks.txt:2889
Renders a set of search results to HTML.
Renders a single search result to HTML.