MediaWiki REL1_35
SimpleSearchResultSetWidget.php
Go to the documentation of this file.
1<?php
2
4
5use Html;
10use Title;
11
21 protected $specialSearch;
23 protected $resultWidget;
25 protected $customCaptions;
27 protected $linkRenderer;
29 protected $iwLookup;
30
31 public function __construct(
36 ) {
37 wfDeprecated( __METHOD__, '1.31' );
38 $this->specialSearch = $specialSearch;
39 $this->resultWidget = $resultWidget;
40 $this->linkRenderer = $linkRenderer;
41 $this->iwLookup = $iwLookup;
42 }
43
50 public function render( $term, $resultSets ) {
51 if ( !is_array( $resultSets ) ) {
52 $resultSets = [ $resultSets ];
53 }
54
55 $this->loadCustomCaptions();
56
57 $iwResults = [];
58 foreach ( $resultSets as $resultSet ) {
59 foreach ( $resultSet as $result ) {
60 if ( !$result->isBrokenTitle() ) {
61 $iwResults[$result->getTitle()->getInterwiki()][] = $result;
62 }
63 }
64 }
65
66 $out = '';
67 foreach ( $iwResults as $iwPrefix => $results ) {
68 $out .= $this->headerHtml( $iwPrefix, $term );
69 $out .= "<ul class='mw-search-iwresults'>";
70 // TODO: Assumes interwiki results are never paginated
71 $position = 0;
72 foreach ( $results as $result ) {
73 $out .= $this->resultWidget->render( $result, $position++ );
74 }
75 $out .= "</ul>";
76 }
77
78 return "<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 "<div class='mw-search-interwiki-project'>" .
112 "<span class='mw-search-interwiki-more'>{$searchLink}</span>" .
113 $caption .
114 "</div>";
115 }
116
117 protected function loadCustomCaptions() {
118 if ( $this->customCaptions !== null ) {
119 return;
120 }
121
122 $this->customCaptions = [];
123 $customLines = explode( "\n", $this->specialSearch->msg( 'search-interwiki-custom' )->escaped() );
124 foreach ( $customLines as $line ) {
125 $parts = explode( ':', $line, 2 );
126 if ( count( $parts ) === 2 ) {
127 $this->customCaptions[$parts[0]] = $parts[1];
128 }
129 }
130 }
131}
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
This class is a collection of static functions that serve two purposes:
Definition Html.php:49
Class that generates HTML links for pages.
Renders one or more ISearchResultSets into a sidebar grouped by interwiki prefix.
__construct(SpecialSearch $specialSearch, SearchResultWidget $resultWidget, LinkRenderer $linkRenderer, InterwikiLookup $iwLookup)
headerHtml( $iwPrefix, $term)
Generates an appropriate HTML header for the given interwiki prefix.
implements Special:Search - Run text & title search and display the output
Represents a title within MediaWiki.
Definition Title.php:42
const NS_SPECIAL
Definition Defines.php:59
A set of SearchEngine results.
Service interface for looking up Interwiki records.
Renders a single search result to HTML.
$line
Definition mcc.php:119