MediaWiki REL1_31
SimpleSearchResultSetWidget.php
Go to the documentation of this file.
1<?php
2
4
9use Title;
10use Html;
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 $result = $resultSet->next();
60 while ( $result ) {
61 if ( !$result->isBrokenTitle() ) {
62 $iwResults[$result->getTitle()->getInterwiki()][] = $result;
63 }
64 $result = $resultSet->next();
65 }
66 }
67
68 $out = '';
69 foreach ( $iwResults as $iwPrefix => $results ) {
70 $out .= $this->headerHtml( $iwPrefix, $term );
71 $out .= "<ul class='mw-search-iwresults'>";
72 // TODO: Assumes interwiki results are never paginated
73 $position = 0;
74 foreach ( $results as $result ) {
75 $out .= $this->resultWidget->render( $result, $term, $position++ );
76 }
77 $out .= "</ul>";
78 }
79
80 return "<div id='mw-search-interwiki'>" .
81 "<div id='mw-search-interwiki-caption'>" .
82 $this->specialSearch->msg( 'search-interwiki-caption' )->parse() .
83 '</div>' .
84 $out .
85 "</div>";
86 }
87
95 protected function headerHtml( $iwPrefix, $term ) {
96 if ( isset( $this->customCaptions[$iwPrefix] ) ) {
97 $caption = $this->customCaptions[$iwPrefix];
98 } else {
99 $interwiki = $this->iwLookup->fetch( $iwPrefix );
100 $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) );
101 $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
102 }
103
104 $href = Title::makeTitle( NS_SPECIAL, 'Search', null, $iwPrefix )->getLocalURL(
105 [ 'search' => $term, 'fulltext' => 1 ]
106 );
107 $searchLink = Html::rawElement(
108 'a',
109 [ 'href' => $href ],
110 $this->specialSearch->msg( 'search-interwiki-more' )->escaped()
111 );
112
113 return "<div class='mw-search-interwiki-project'>" .
114 "<span class='mw-search-interwiki-more'>{$searchLink}</span>" .
115 $caption .
116 "</div>";
117 }
118
119 protected function loadCustomCaptions() {
120 if ( $this->customCaptions !== null ) {
121 return;
122 }
123
124 $this->customCaptions = [];
125 $customLines = explode( "\n", $this->specialSearch->msg( 'search-interwiki-custom' )->escaped() );
126 foreach ( $customLines as $line ) {
127 $parts = explode( ':', $line, 2 );
128 if ( count( $parts ) === 2 ) {
129 $this->customCaptions[$parts[0]] = $parts[1];
130 }
131 }
132 }
133}
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)
Throws a warning that $function is deprecated.
$line
Definition cdb.php:59
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
namespace being checked & $result
Definition hooks.txt:2323
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
const NS_SPECIAL
Definition Defines.php:63
Service interface for looking up Interwiki records.
Renders a set of search results to HTML.
Renders a single search result to HTML.