MediaWiki master
SearchSuggestion.php
Go to the documentation of this file.
1<?php
2
23
31 private $text;
32
36 private $url;
37
41 private $suggestedTitle;
42
48 private $suggestedTitleID;
49
53 private $score;
54
61 public function __construct( $score, $text = null, Title $suggestedTitle = null,
62 $suggestedTitleID = null ) {
63 $this->score = $score;
64 $this->text = $text;
65 if ( $suggestedTitle ) {
66 $this->setSuggestedTitle( $suggestedTitle );
67 }
68 $this->suggestedTitleID = $suggestedTitleID;
69 }
70
75 public function getText() {
76 return $this->text;
77 }
78
84 public function setText( $text, $setTitle = true ) {
85 $this->text = $text;
86 if ( $setTitle && $text !== '' && $text !== null ) {
87 $this->setSuggestedTitle( Title::makeTitle( 0, $text ) );
88 }
89 }
90
96 public function getSuggestedTitle() {
97 return $this->suggestedTitle;
98 }
99
103 public function setSuggestedTitle( Title $title = null ) {
104 $this->suggestedTitle = $title;
105 if ( $title !== null ) {
106 $this->url = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
107 }
108 }
109
115 public function getSuggestedTitleID() {
116 return $this->suggestedTitleID;
117 }
118
122 public function setSuggestedTitleID( $suggestedTitleID = null ) {
123 $this->suggestedTitleID = $suggestedTitleID;
124 }
125
130 public function getScore() {
131 return $this->score;
132 }
133
138 public function setScore( $score ) {
139 $this->score = $score;
140 }
141
147 public function getURL() {
148 return $this->url;
149 }
150
155 public function setURL( $url ) {
156 $this->url = $url;
157 }
158
165 public static function fromTitle( $score, Title $title ) {
166 return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
167 }
168
176 public static function fromText( $score, $text ) {
177 $suggestion = new self( $score, $text );
178 if ( $text ) {
179 $suggestion->setSuggestedTitle( Title::newFromText( $text ) );
180 }
181 return $suggestion;
182 }
183
184}
const PROTO_CURRENT
Definition Defines.php:207
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
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:2590
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1861
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.