| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\MediaWikiServices; |
| 23 |
use MediaWiki\Title\Title; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class SearchSuggestion { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
private $text; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
private $url; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
private $suggestedTitle; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private $suggestedTitleID; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
private $score; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 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 ); |
| 68 |
} |
| 69 |
$this->suggestedTitleID = $suggestedTitleID; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function getText() { |
| 77 |
return $this->text; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public function setText( $text, $setTitle = true ) { |
| 86 |
$this->text = $text; |
| 87 |
if ( $setTitle && $text !== '' && $text !== null ) { |
| 88 |
$this->setSuggestedTitle( Title::makeTitle( 0, $text ) ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function getSuggestedTitle() { |
| 98 |
return $this->suggestedTitle; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public function setSuggestedTitle( ?Title $title = null ) { |
| 105 |
$this->suggestedTitle = $title; |
| 106 |
if ( $title !== null ) { |
| 107 |
$urlUtils = MediaWikiServices::getInstance()->getUrlUtils(); |
| 108 |
$this->url = $urlUtils->expand( $title->getFullURL(), PROTO_CURRENT ) ?? false; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function getSuggestedTitleID() { |
| 118 |
return $this->suggestedTitleID; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public function setSuggestedTitleID( $suggestedTitleID = null ) { |
| 125 |
$this->suggestedTitleID = $suggestedTitleID; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public function getScore() { |
| 133 |
return $this->score; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public function setScore( $score ) { |
| 141 |
$this->score = $score; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public function getURL() { |
| 150 |
return $this->url; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public function setURL( $url ) { |
| 158 |
$this->url = $url; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public static function fromTitle( $score, Title $title ) { |
| 168 |
return new self( $score, $title->getPrefixedText(), $title, $title->getArticleID() ); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public static function fromText( $score, $text ) { |
| 179 |
$suggestion = new self( $score, $text ); |
| 180 |
if ( $text ) { |
| 181 |
$suggestion->setSuggestedTitle( Title::newFromText( $text ) ); |
| 182 |
} |
| 183 |
return $suggestion; |
| 184 |
} |
| 185 |
|
| 186 |
} |