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 
101  public function setSuggestedTitle( Title $title = null ) {
102  $this->suggestedTitle = $title;
103  if ( $title !== null ) {
104  $this->url = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
105  }
106  }
107 
113  public function getSuggestedTitleID() {
115  }
116 
120  public function setSuggestedTitleID( $suggestedTitleID = null ) {
121  $this->suggestedTitleID = $suggestedTitleID;
122  }
123 
128  public function getScore() {
129  return $this->score;
130  }
131 
136  public function setScore( $score ) {
137  $this->score = $score;
138  }
139 
145  public function getURL() {
146  return $this->url;
147  }
148 
153  public function setURL( $url ) {
154  $this->url = $url;
155  }
156 
163  public static function fromTitle( $score, Title $title ) {
164  return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
165  }
166 
174  public static function fromText( $score, $text ) {
175  $suggestion = new self( $score, $text );
176  if ( $text ) {
177  $suggestion->setSuggestedTitle( Title::newFromText( $text ) );
178  }
179  return $suggestion;
180  }
181 
182 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:363
SearchSuggestion\setSuggestedTitleID
setSuggestedTitleID( $suggestedTitleID=null)
Definition: SearchSuggestion.php:120
SearchSuggestion\setScore
setScore( $score)
Set the suggestion score.
Definition: SearchSuggestion.php:136
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:145
SearchSuggestion\$url
string $url
the suggestion URL
Definition: SearchSuggestion.php:34
SearchSuggestion\__construct
__construct( $score, $text=null, Title $suggestedTitle=null, $suggestedTitleID=null)
Definition: SearchSuggestion.php:59
SearchSuggestion\fromTitle
static fromTitle( $score, Title $title)
Create suggestion from Title.
Definition: SearchSuggestion.php:163
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:113
SearchSuggestion\setURL
setURL( $url)
Set the suggestion URL.
Definition: SearchSuggestion.php:153
SearchSuggestion
Search suggestion.
Definition: SearchSuggestion.php:25
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:626
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:206
SearchSuggestion\setText
setText( $text, $setTitle=true)
Set the suggestion text.
Definition: SearchSuggestion.php:82
SearchSuggestion\$text
string $text
the suggestion
Definition: SearchSuggestion.php:29
SearchSuggestion\setSuggestedTitle
setSuggestedTitle(Title $title=null)
Definition: SearchSuggestion.php:101
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:94
SearchSuggestion\getText
getText()
The suggestion text.
Definition: SearchSuggestion.php:73
Title
Represents a title within MediaWiki.
Definition: Title.php:46
SearchSuggestion\fromText
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
Definition: SearchSuggestion.php:174
SearchSuggestion\getScore
getScore()
Suggestion score.
Definition: SearchSuggestion.php:128
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:495