Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / search / SearchSuggestion.php
blob80a437b6c9c4ea52bd6d2d75522e4e65dc1990f4
1 <?php
3 /**
4 * Search suggestion
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
23 /**
24 * A search suggestion
27 class SearchSuggestion {
28 /**
29 * @var string the suggestion
31 private $text;
33 /**
34 * @var string the suggestion URL
36 private $url;
38 /**
39 * @var Title|null the suggested title
41 private $suggestedTitle;
43 /**
44 * NOTE: even if suggestedTitle is a redirect suggestedTitleID
45 * is the ID of the target page.
46 * @var int|null the suggested title ID
48 private $suggestedTitleID;
50 /**
51 * @var float|null The suggestion score
53 private $score;
55 /**
56 * Construct a new suggestion
57 * @param float $score the suggestion score
58 * @param string $text|null the suggestion text
59 * @param Title|null $suggestedTitle the suggested title
60 * @param int|null $suggestedTitleID the suggested title ID
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 );
69 $this->suggestedTitleID = $suggestedTitleID;
72 /**
73 * The suggestion text
74 * @return string
76 public function getText() {
77 return $this->text;
80 /**
81 * Set the suggestion text.
82 * @param string $text
83 * @param bool $setTitle Should we also update the title?
85 public function setText( $text, $setTitle = true ) {
86 $this->text = $text;
87 if ( $setTitle && $text !== '' && $text !== null ) {
88 $this->setSuggestedTitle( Title::makeTitle( 0, $text ) );
92 /**
93 * Title object in the case this suggestion is based on a title.
94 * May return null if the suggestion is not a Title.
95 * @return Title|null
97 public function getSuggestedTitle() {
98 return $this->suggestedTitle;
102 * Set the suggested title
103 * @param Title|null $title
105 public function setSuggestedTitle( Title $title = null ) {
106 $this->suggestedTitle = $title;
107 if ( $title !== null ) {
108 $this->url = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
113 * Title ID in the case this suggestion is based on a title.
114 * May return null if the suggestion is not a Title.
115 * @return int|null
117 public function getSuggestedTitleID() {
118 return $this->suggestedTitleID;
122 * Set the suggested title ID
123 * @param int|null $suggestedTitleID
125 public function setSuggestedTitleID( $suggestedTitleID = null ) {
126 $this->suggestedTitleID = $suggestedTitleID;
130 * Suggestion score
131 * @return float Suggestion score
133 public function getScore() {
134 return $this->score;
138 * Set the suggestion score
139 * @param float $score
141 public function setScore( $score ) {
142 $this->score = $score;
146 * Suggestion URL, can be the link to the Title or maybe in the
147 * future a link to the search results for this search suggestion.
148 * @return string Suggestion URL
150 public function getURL() {
151 return $this->url;
155 * Set the suggestion URL
156 * @param string $url
158 public function setURL( $url ) {
159 $this->url = $url;
163 * Create suggestion from Title
164 * @param float $score Suggestions score
165 * @param Title $title
166 * @return SearchSuggestion
168 public static function fromTitle( $score, Title $title ) {
169 return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() );
173 * Create suggestion from text
174 * Will also create a title if text if not empty.
175 * @param float $score Suggestions score
176 * @param string $text
177 * @return SearchSuggestion
179 public static function fromText( $score, $text ) {
180 $suggestion = new self( $score, $text );
181 if ( $text ) {
182 $suggestion->setSuggestedTitle( Title::makeTitle( 0, $text ) );
184 return $suggestion;