MediaWiki  1.34.0
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 
60  public function __construct( $score, $text = null, Title $suggestedTitle = null,
61  $suggestedTitleID = null ) {
62  $this->score = $score;
63  $this->text = $text;
64  if ( $suggestedTitle ) {
66  }
67  $this->suggestedTitleID = $suggestedTitleID;
68  }
69 
74  public function getText() {
75  return $this->text;
76  }
77 
83  public function setText( $text, $setTitle = true ) {
84  $this->text = $text;
85  if ( $setTitle && $text !== '' && $text !== null ) {
87  }
88  }
89 
95  public function getSuggestedTitle() {
96  return $this->suggestedTitle;
97  }
98 
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() {
117  }
118 
123  public function setSuggestedTitleID( $suggestedTitleID = null ) {
124  $this->suggestedTitleID = $suggestedTitleID;
125  }
126 
131  public function getScore() {
132  return $this->score;
133  }
134 
139  public function setScore( $score ) {
140  $this->score = $score;
141  }
142 
148  public function getURL() {
149  return $this->url;
150  }
151 
156  public function setURL( $url ) {
157  $this->url = $url;
158  }
159 
166  public static function fromTitle( $score, Title $title ) {
167  return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
168  }
169 
177  public static function fromText( $score, $text ) {
178  $suggestion = new self( $score, $text );
179  if ( $text ) {
180  $suggestion->setSuggestedTitle( Title::makeTitle( 0, $text ) );
181  }
182  return $suggestion;
183  }
184 
185 }
SearchSuggestion\setSuggestedTitleID
setSuggestedTitleID( $suggestedTitleID=null)
Set the suggested title ID.
Definition: SearchSuggestion.php:123
SearchSuggestion\setScore
setScore( $score)
Set the suggestion score.
Definition: SearchSuggestion.php:139
SearchSuggestion\$score
float null $score
The suggestion score.
Definition: SearchSuggestion.php:51
SearchSuggestion\getURL
getURL()
Suggestion URL, can be the link to the Title or maybe in the future a link to the search results for ...
Definition: SearchSuggestion.php:148
SearchSuggestion\$url
string $url
the suggestion URL
Definition: SearchSuggestion.php:34
SearchSuggestion\__construct
__construct( $score, $text=null, Title $suggestedTitle=null, $suggestedTitleID=null)
Construct a new suggestion.
Definition: SearchSuggestion.php:60
SearchSuggestion\fromTitle
static fromTitle( $score, Title $title)
Create suggestion from Title.
Definition: SearchSuggestion.php:166
SearchSuggestion\$suggestedTitleID
int null $suggestedTitleID
NOTE: even if suggestedTitle is a redirect suggestedTitleID is the ID of the target page.
Definition: SearchSuggestion.php:46
SearchSuggestion\getSuggestedTitleID
getSuggestedTitleID()
Title ID in the case this suggestion is based on a title.
Definition: SearchSuggestion.php:115
SearchSuggestion\setURL
setURL( $url)
Set the suggestion URL.
Definition: SearchSuggestion.php:156
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
SearchSuggestion
Search suggestion.
Definition: SearchSuggestion.php:25
$title
$title
Definition: testCompression.php:34
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
SearchSuggestion\setText
setText( $text, $setTitle=true)
Set the suggestion text.
Definition: SearchSuggestion.php:83
SearchSuggestion\$text
string $text
the suggestion
Definition: SearchSuggestion.php:29
SearchSuggestion\setSuggestedTitle
setSuggestedTitle(Title $title=null)
Set the suggested title.
Definition: SearchSuggestion.php:103
SearchSuggestion\$suggestedTitle
Title null $suggestedTitle
the suggested title
Definition: SearchSuggestion.php:39
SearchSuggestion\getSuggestedTitle
getSuggestedTitle()
Title object in the case this suggestion is based on a title.
Definition: SearchSuggestion.php:95
SearchSuggestion\getText
getText()
The suggestion text.
Definition: SearchSuggestion.php:74
Title
Represents a title within MediaWiki.
Definition: Title.php:42
SearchSuggestion\fromText
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
Definition: SearchSuggestion.php:177
SearchSuggestion\getScore
getScore()
Suggestion score.
Definition: SearchSuggestion.php:131
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491