MediaWiki master
SearchSuggestion.php
Go to the documentation of this file.
1<?php
2
11
19 private $text;
20
24 private $url;
25
29 private $suggestedTitle;
30
36 private $suggestedTitleID;
37
41 private $score;
42
49 public function __construct( $score, $text = null, ?Title $suggestedTitle = null,
50 $suggestedTitleID = null ) {
51 $this->score = $score;
52 $this->text = $text;
53 if ( $suggestedTitle ) {
54 $this->setSuggestedTitle( $suggestedTitle );
55 }
56 $this->suggestedTitleID = $suggestedTitleID;
57 }
58
63 public function getText() {
64 return $this->text;
65 }
66
72 public function setText( $text, $setTitle = true ) {
73 $this->text = $text;
74 if ( $setTitle && $text !== '' && $text !== null ) {
75 $this->setSuggestedTitle( Title::makeTitle( 0, $text ) );
76 }
77 }
78
84 public function getSuggestedTitle() {
85 return $this->suggestedTitle;
86 }
87
91 public function setSuggestedTitle( ?Title $title = null ) {
92 $this->suggestedTitle = $title;
93 if ( $title !== null ) {
94 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
95 $this->url = $urlUtils->expand( $title->getFullURL(), PROTO_CURRENT ) ?? false;
96 }
97 }
98
104 public function getSuggestedTitleID() {
105 return $this->suggestedTitleID;
106 }
107
111 public function setSuggestedTitleID( $suggestedTitleID = null ) {
112 $this->suggestedTitleID = $suggestedTitleID;
113 }
114
119 public function getScore() {
120 return $this->score;
121 }
122
127 public function setScore( $score ) {
128 $this->score = $score;
129 }
130
136 public function getURL() {
137 return $this->url;
138 }
139
144 public function setURL( $url ) {
145 $this->url = $url;
146 }
147
154 public static function fromTitle( $score, Title $title ) {
155 return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
156 }
157
165 public static function fromText( $score, $text ) {
166 $suggestion = new self( $score, $text );
167 if ( $text ) {
168 $suggestion->setSuggestedTitle( Title::newFromText( $text ) );
169 }
170 return $suggestion;
171 }
172
173}
const PROTO_CURRENT
Definition Defines.php:222
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:70
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2559
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1858
A search suggestion.
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
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)
getSuggestedTitle()
Title object in the case this suggestion is based on a title.
setSuggestedTitle(?Title $title=null)
setScore( $score)
Set the suggestion score.
getURL()
Suggestion URL, can be the link to the Title or maybe in the future a link to the search results for ...
__construct( $score, $text=null, ?Title $suggestedTitle=null, $suggestedTitleID=null)
getScore()
Suggestion score.
getText()
The suggestion text.
static fromTitle( $score, Title $title)
Create suggestion from Title.