MediaWiki REL1_30
SimpleSearchResultSetWidget.php
Go to the documentation of this file.
1<?php
2
4
9use Title;
10use Html;
11
19 protected $specialSearch;
21 protected $resultWidget;
23 protected $customCaptions;
25 protected $linkRenderer;
27 protected $iwLookup;
28
29 public function __construct(
34 ) {
35 $this->specialSearch = $specialSearch;
36 $this->resultWidget = $resultWidget;
37 $this->linkRenderer = $linkRenderer;
38 $this->iwLookup = $iwLookup;
39 }
40
47 public function render( $term, $resultSets ) {
48 if ( !is_array( $resultSets ) ) {
49 $resultSets = [ $resultSets ];
50 }
51
52 $this->loadCustomCaptions();
53
54 $iwResults = [];
55 foreach ( $resultSets as $resultSet ) {
56 $result = $resultSet->next();
57 while ( $result ) {
58 if ( !$result->isBrokenTitle() ) {
59 $iwResults[$result->getTitle()->getInterwiki()][] = $result;
60 }
61 $result = $resultSet->next();
62 }
63 }
64
65 $out = '';
66 foreach ( $iwResults as $iwPrefix => $results ) {
67 $out .= $this->headerHtml( $iwPrefix, $term );
68 $out .= "<ul class='mw-search-iwresults'>";
69 // TODO: Assumes interwiki results are never paginated
70 $position = 0;
71 foreach ( $results as $result ) {
72 $out .= $this->resultWidget->render( $result, $term, $position++ );
73 }
74 $out .= "</ul>";
75 }
76
77 return
78 "<div id='mw-search-interwiki'>" .
79 "<div id='mw-search-interwiki-caption'>" .
80 $this->specialSearch->msg( 'search-interwiki-caption' )->parse() .
81 '</div>' .
82 $out .
83 "</div>";
84 }
85
93 protected function headerHtml( $iwPrefix, $term ) {
94 if ( isset( $this->customCaptions[$iwPrefix] ) ) {
95 $caption = $this->customCaptions[$iwPrefix];
96 } else {
97 $interwiki = $this->iwLookup->fetch( $iwPrefix );
98 $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) );
99 $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
100 }
101
102 $href = Title::makeTitle( NS_SPECIAL, 'Search', null, $iwPrefix )->getLocalURL(
103 [ 'search' => $term, 'fulltext' => 1 ]
104 );
105 $searchLink = Html::rawElement(
106 'a',
107 [ 'href' => $href ],
108 $this->specialSearch->msg( 'search-interwiki-more' )->escaped()
109 );
110
111 return
112 "<div class='mw-search-interwiki-project'>" .
113 "<span class='mw-search-interwiki-more'>{$searchLink}</span>" .
114 $caption .
115 "</div>";
116 }
117
118 protected function loadCustomCaptions() {
119 if ( $this->customCaptions !== null ) {
120 return;
121 }
122
123 $this->customCaptions = [];
124 $customLines = explode( "\n", $this->specialSearch->msg( 'search-interwiki-custom' )->escaped() );
125 foreach ( $customLines as $line ) {
126 $parts = explode( ':', $line, 2 );
127 if ( count( $parts ) === 2 ) {
128 $this->customCaptions[$parts[0]] = $parts[1];
129 }
130 }
131 }
132}
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
$line
Definition cdb.php:58
This class is a collection of static functions that serve two purposes:
Definition Html.php:48
Class that generates HTML links for pages.
Renders one or more SearchResultSets into a sidebar grouped by interwiki prefix.
headerHtml( $iwPrefix, $term)
Generates an appropriate HTML header for the given interwiki prefix.
__construct(SpecialSearch $specialSearch, SearchResultWidget $resultWidget, LinkRenderer $linkRenderer, InterwikiLookup $iwLookup)
implements Special:Search - Run text & title search and display the output
Represents a title within MediaWiki.
Definition Title.php:39
external whereas SearchGetNearMatch runs after $term
Definition hooks.txt:2814
namespace being checked & $result
Definition hooks.txt:2293
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:862
const NS_SPECIAL
Definition Defines.php:54
Service interface for looking up Interwiki records.
Renders a set of search results to HTML.
Renders a single search result to HTML.