MediaWiki  master
SearchSuggestion.php
Go to the documentation of this file.
1 <?php
2 
29  private $text;
30 
34  private $url;
35 
39  private $suggestedTitle;
40 
47 
51  private $score;
52 
59  public function __construct( $score, $text = null, Title $suggestedTitle = null,
60  $suggestedTitleID = null ) {
61  $this->score = $score;
62  $this->text = $text;
63  if ( $suggestedTitle ) {
65  }
66  $this->suggestedTitleID = $suggestedTitleID;
67  }
68 
73  public function getText() {
74  return $this->text;
75  }
76 
82  public function setText( $text, $setTitle = true ) {
83  $this->text = $text;
84  if ( $setTitle && $text !== '' && $text !== null ) {
86  }
87  }
88 
94  public function getSuggestedTitle() {
95  return $this->suggestedTitle;
96  }
97 
102  public function setSuggestedTitle( Title $title = null ) {
103  $this->suggestedTitle = $title;
104  if ( $title !== null ) {
105  $this->url = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
106  }
107  }
108 
114  public function getSuggestedTitleID() {
116  }
117 
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::makeTitle( 0, $text ) );
180  }
181  return $suggestion;
182  }
183 
184 }
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3166
Search suggestion.
setText( $text, $setTitle=true)
Set the suggestion text.
setSuggestedTitle(Title $title=null)
Set the suggested title.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Title null $suggestedTitle
the suggested title
const PROTO_CURRENT
Definition: Defines.php:202
string $text
the suggestion
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1858
getSuggestedTitle()
Title object in the case this suggestion is based on a title.
getScore()
Suggestion score.
getText()
The suggestion text.
setSuggestedTitleID( $suggestedTitleID=null)
Set the suggested title ID.
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
float null $score
The suggestion score.
__construct( $score, $text=null, Title $suggestedTitle=null, $suggestedTitleID=null)
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
string $url
the suggestion URL
setScore( $score)
Set the suggestion score.
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 ...
getSuggestedTitleID()
Title ID in the case this suggestion is based on a title.
int null $suggestedTitleID
NOTE: even if suggestedTitle is a redirect suggestedTitleID is the ID of the target page...
setURL( $url)
Set the suggestion URL.