| 1 |
<?php |
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Feed; |
| 25 |
|
| 26 |
use MediaWiki\Language\LanguageCode; |
| 27 |
use MediaWiki\MainConfigNames; |
| 28 |
use MediaWiki\MediaWikiServices; |
| 29 |
use MediaWiki\Title\Title; |
| 30 |
use MediaWiki\Utils\UrlUtils; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class FeedItem { |
| 42 |
|
| 43 |
public $title; |
| 44 |
|
| 45 |
|
| 46 |
public $description; |
| 47 |
|
| 48 |
|
| 49 |
public $url; |
| 50 |
|
| 51 |
|
| 52 |
public $date; |
| 53 |
|
| 54 |
|
| 55 |
public $author; |
| 56 |
|
| 57 |
|
| 58 |
public $uniqueId; |
| 59 |
|
| 60 |
|
| 61 |
public $comments; |
| 62 |
|
| 63 |
|
| 64 |
public $rssIsPermalink = false; |
| 65 |
|
| 66 |
protected UrlUtils $urlUtils; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function __construct( |
| 77 |
$title, $description, $url, $date = '', $author = '', $comments = '' |
| 78 |
) { |
| 79 |
$this->title = $title; |
| 80 |
$this->description = $description; |
| 81 |
$this->url = $url; |
| 82 |
$this->uniqueId = $url; |
| 83 |
$this->date = $date; |
| 84 |
$this->author = $author; |
| 85 |
$this->comments = $comments; |
| 86 |
$this->urlUtils = MediaWikiServices::getInstance()->getUrlUtils(); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public function xmlEncode( $string ) { |
| 97 |
$string = str_replace( "\r\n", "\n", $string ); |
| 98 |
$string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string ); |
| 99 |
|
| 100 |
return htmlspecialchars( $string ); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public function xmlEncodeNullable( ?string $string ): ?string { |
| 109 |
return $string !== null ? $this->xmlEncode( $string ) : null; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function getUniqueID() { |
| 118 |
$id = $this->getUniqueIdUnescaped(); |
| 119 |
if ( $id ) { |
| 120 |
return $this->xmlEncode( $id ); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public function getUniqueIdUnescaped(): ?string { |
| 130 |
if ( $this->uniqueId ) { |
| 131 |
return $this->urlUtils->expand( $this->uniqueId, PROTO_CURRENT ); |
| 132 |
} |
| 133 |
|
| 134 |
return null; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public function setUniqueId( $uniqueId, $rssIsPermalink = false ) { |
| 144 |
$this->uniqueId = $uniqueId; |
| 145 |
$this->rssIsPermalink = $rssIsPermalink; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public function getTitle() { |
| 154 |
return $this->xmlEncode( $this->title ); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public function getUrl() { |
| 163 |
return $this->xmlEncode( $this->url ); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public function getUrlUnescaped() { |
| 171 |
return $this->url; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public function getDescription() { |
| 180 |
return $this->xmlEncode( $this->description ); |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public function getDescriptionUnescaped() { |
| 189 |
return $this->description; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
public function getLanguage() { |
| 198 |
$languageCode = MediaWikiServices::getInstance()->getMainConfig() |
| 199 |
->get( MainConfigNames::LanguageCode ); |
| 200 |
return LanguageCode::bcp47( $languageCode ); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public function getDate() { |
| 209 |
return $this->date; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public function getAuthor() { |
| 218 |
return $this->xmlEncode( $this->author ); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public function getAuthorUnescaped() { |
| 227 |
return $this->author; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public function getComments() { |
| 236 |
return $this->xmlEncode( $this->comments ); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public function getCommentsUnescaped() { |
| 245 |
return $this->comments; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
public static function stripComment( $text ) { |
| 256 |
return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text ); |
| 257 |
} |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
class_alias( FeedItem::class, 'FeedItem' ); |