MediaWiki master
SearchSuggestion.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
12
20 private $text;
21
25 private $url;
26
30 private $suggestedTitle;
31
37 private $suggestedTitleID;
38
42 private $score;
43
50 public function __construct( $score, $text = null, ?Title $suggestedTitle = null,
51 $suggestedTitleID = null ) {
52 $this->score = $score;
53 $this->text = $text;
54 if ( $suggestedTitle ) {
55 $this->setSuggestedTitle( $suggestedTitle );
56 }
57 $this->suggestedTitleID = $suggestedTitleID;
58 }
59
64 public function getText() {
65 return $this->text;
66 }
67
73 public function setText( $text, $setTitle = true ) {
74 $this->text = $text;
75 if ( $setTitle && $text !== '' && $text !== null ) {
76 $this->setSuggestedTitle( Title::makeTitle( 0, $text ) );
77 }
78 }
79
85 public function getSuggestedTitle() {
86 return $this->suggestedTitle;
87 }
88
92 public function setSuggestedTitle( ?Title $title = null ) {
93 $this->suggestedTitle = $title;
94 if ( $title !== null ) {
95 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
96 $this->url = $urlUtils->expand( $title->getFullURL(), PROTO_CURRENT ) ?? false;
97 }
98 }
99
105 public function getSuggestedTitleID() {
106 return $this->suggestedTitleID;
107 }
108
112 public function setSuggestedTitleID( $suggestedTitleID = null ) {
113 $this->suggestedTitleID = $suggestedTitleID;
114 }
115
120 public function getScore() {
121 return $this->score;
122 }
123
128 public function setScore( $score ) {
129 $this->score = $score;
130 }
131
137 public function getURL() {
138 return $this->url;
139 }
140
145 public function setURL( $url ) {
146 $this->url = $url;
147 }
148
155 public static function fromTitle( $score, Title $title ) {
156 return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
157 }
158
166 public static function fromText( $score, $text ) {
167 $suggestion = new self( $score, $text );
168 if ( $text ) {
169 $suggestion->setSuggestedTitle( Title::newFromText( $text ) );
170 }
171 return $suggestion;
172 }
173
174}
175
177class_alias( SearchSuggestion::class, 'SearchSuggestion' );
const PROTO_CURRENT
Definition Defines.php:222
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
getSuggestedTitle()
Title object in the case this suggestion is based on a title.
getSuggestedTitleID()
Title ID in the case this suggestion is based on a title.
setText( $text, $setTitle=true)
Set the suggestion text.
setURL( $url)
Set the suggestion URL.
setSuggestedTitleID( $suggestedTitleID=null)
__construct( $score, $text=null, ?Title $suggestedTitle=null, $suggestedTitleID=null)
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
static fromTitle( $score, Title $title)
Create suggestion from Title.
getURL()
Suggestion URL, can be the link to the Title or maybe in the future a link to the search results for ...
setScore( $score)
Set the suggestion score.
Represents a title within MediaWiki.
Definition Title.php:69
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2558
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1857
Definition of a mapping for the search index field.