MediaWiki master
FeedItem.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Feed;
25
30
40class FeedItem {
42 public $title;
43
46
48 public $url;
49
51 public $date;
52
54 public $author;
55
57 public $uniqueId;
58
60 public $comments;
61
63 public $rssIsPermalink = false;
64
66
75 public function __construct(
76 $title, $description, $url, $date = '', $author = '', $comments = ''
77 ) {
78 $this->title = $title;
79 $this->description = $description;
80 $this->url = $url;
81 $this->uniqueId = $url;
82 $this->date = $date;
83 $this->author = $author;
84 $this->comments = $comments;
85 $this->urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
86 }
87
95 public function xmlEncode( $string ) {
96 $string = str_replace( "\r\n", "\n", $string );
97 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
98
99 return htmlspecialchars( $string );
100 }
101
107 public function getUniqueID() {
108 $id = $this->getUniqueIdUnescaped();
109 if ( $id ) {
110 return $this->xmlEncode( $id );
111 }
112 }
113
119 public function getUniqueIdUnescaped(): ?string {
120 if ( $this->uniqueId ) {
121 return $this->urlUtils->expand( $this->uniqueId, PROTO_CURRENT );
122 }
123
124 return null;
125 }
126
133 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
134 $this->uniqueId = $uniqueId;
135 $this->rssIsPermalink = $rssIsPermalink;
136 }
137
143 public function getTitle() {
144 return $this->xmlEncode( $this->title );
145 }
146
152 public function getUrl() {
153 return $this->xmlEncode( $this->url );
154 }
155
160 public function getUrlUnescaped() {
161 return $this->url;
162 }
163
169 public function getDescription() {
170 return $this->xmlEncode( $this->description );
171 }
172
178 public function getDescriptionUnescaped() {
179 return $this->description;
180 }
181
187 public function getLanguage() {
188 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
190 return LanguageCode::bcp47( $languageCode );
191 }
192
198 public function getDate() {
199 return $this->date;
200 }
201
207 public function getAuthor() {
208 return $this->xmlEncode( $this->author );
209 }
210
216 public function getAuthorUnescaped() {
217 return $this->author;
218 }
219
225 public function getComments() {
226 return $this->xmlEncode( $this->comments );
227 }
228
234 public function getCommentsUnescaped() {
235 return $this->comments;
236 }
237
245 public static function stripComment( $text ) {
246 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
247 }
248
249}
250
252class_alias( FeedItem::class, 'FeedItem' );
const PROTO_CURRENT
Definition Defines.php:215
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:40
getDescriptionUnescaped()
Get the description of this item without any escaping.
Definition FeedItem.php:178
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition FeedItem.php:119
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:160
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition FeedItem.php:107
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition FeedItem.php:75
getDate()
Get the date of this item.
Definition FeedItem.php:198
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:143
getAuthor()
Get the author of this item; already xml-encoded.
Definition FeedItem.php:207
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition FeedItem.php:133
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:169
getUrl()
Get the URL of this item; already xml-encoded.
Definition FeedItem.php:152
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition FeedItem.php:245
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition FeedItem.php:216
getComments()
Get the comment of this item; already xml-encoded.
Definition FeedItem.php:225
getLanguage()
Get the language of this item.
Definition FeedItem.php:187
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition FeedItem.php:234
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:95
Methods for dealing with language codes.
A class containing constants representing the names of configuration variables.
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16