MediaWiki master
SearchSuggestion.php
Go to the documentation of this file.
1<?php
2
24
32 private $text;
33
37 private $url;
38
42 private $suggestedTitle;
43
49 private $suggestedTitleID;
50
54 private $score;
55
62 public function __construct( $score, $text = null, Title $suggestedTitle = null,
63 $suggestedTitleID = null ) {
64 $this->score = $score;
65 $this->text = $text;
66 if ( $suggestedTitle ) {
67 $this->setSuggestedTitle( $suggestedTitle );
68 }
69 $this->suggestedTitleID = $suggestedTitleID;
70 }
71
76 public function getText() {
77 return $this->text;
78 }
79
85 public function setText( $text, $setTitle = true ) {
86 $this->text = $text;
87 if ( $setTitle && $text !== '' && $text !== null ) {
88 $this->setSuggestedTitle( Title::makeTitle( 0, $text ) );
89 }
90 }
91
97 public function getSuggestedTitle() {
98 return $this->suggestedTitle;
99 }
100
104 public function setSuggestedTitle( Title $title = null ) {
105 $this->suggestedTitle = $title;
106 if ( $title !== null ) {
107 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
108 $this->url = $urlUtils->expand( $title->getFullURL(), PROTO_CURRENT ) ?? false;
109 }
110 }
111
117 public function getSuggestedTitleID() {
118 return $this->suggestedTitleID;
119 }
120
124 public function setSuggestedTitleID( $suggestedTitleID = null ) {
125 $this->suggestedTitleID = $suggestedTitleID;
126 }
127
132 public function getScore() {
133 return $this->score;
134 }
135
140 public function setScore( $score ) {
141 $this->score = $score;
142 }
143
149 public function getURL() {
150 return $this->url;
151 }
152
157 public function setURL( $url ) {
158 $this->url = $url;
159 }
160
167 public static function fromTitle( $score, Title $title ) {
168 return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
169 }
170
178 public static function fromText( $score, $text ) {
179 $suggestion = new self( $score, $text );
180 if ( $text ) {
181 $suggestion->setSuggestedTitle( Title::newFromText( $text ) );
182 }
183 return $suggestion;
184 }
185
186}
const PROTO_CURRENT
Definition Defines.php:209
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:78
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2586
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1859
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.
setSuggestedTitle(Title $title=null)
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.
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.