MediaWiki master
FeedItem.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Feed;
25
31
41class FeedItem {
43 public $title;
44
47
49 public $url;
50
52 public $date;
53
55 public $author;
56
58 public $uniqueId;
59
61 public $comments;
62
64 public $rssIsPermalink = false;
65
67
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
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
108 public function getUniqueID() {
109 $id = $this->getUniqueIdUnescaped();
110 if ( $id ) {
111 return $this->xmlEncode( $id );
112 }
113 }
114
120 public function getUniqueIdUnescaped(): ?string {
121 if ( $this->uniqueId ) {
122 return $this->urlUtils->expand( $this->uniqueId, PROTO_CURRENT );
123 }
124
125 return null;
126 }
127
134 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
135 $this->uniqueId = $uniqueId;
136 $this->rssIsPermalink = $rssIsPermalink;
137 }
138
144 public function getTitle() {
145 return $this->xmlEncode( $this->title );
146 }
147
153 public function getUrl() {
154 return $this->xmlEncode( $this->url );
155 }
156
161 public function getUrlUnescaped() {
162 return $this->url;
163 }
164
170 public function getDescription() {
171 return $this->xmlEncode( $this->description );
172 }
173
179 public function getDescriptionUnescaped() {
180 return $this->description;
181 }
182
188 public function getLanguage() {
189 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
191 return LanguageCode::bcp47( $languageCode );
192 }
193
199 public function getDate() {
200 return $this->date;
201 }
202
208 public function getAuthor() {
209 return $this->xmlEncode( $this->author );
210 }
211
217 public function getAuthorUnescaped() {
218 return $this->author;
219 }
220
226 public function getComments() {
227 return $this->xmlEncode( $this->comments );
228 }
229
235 public function getCommentsUnescaped() {
236 return $this->comments;
237 }
238
246 public static function stripComment( $text ) {
247 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
248 }
249
250}
251
253class_alias( FeedItem::class, 'FeedItem' );
const PROTO_CURRENT
Definition Defines.php:209
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:41
getDescriptionUnescaped()
Get the description of this item without any escaping.
Definition FeedItem.php:179
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition FeedItem.php:120
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:161
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition FeedItem.php:108
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition FeedItem.php:76
getDate()
Get the date of this item.
Definition FeedItem.php:199
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:144
getAuthor()
Get the author of this item; already xml-encoded.
Definition FeedItem.php:208
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition FeedItem.php:134
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:170
getUrl()
Get the URL of this item; already xml-encoded.
Definition FeedItem.php:153
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition FeedItem.php:246
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition FeedItem.php:217
getComments()
Get the comment of this item; already xml-encoded.
Definition FeedItem.php:226
getLanguage()
Get the language of this item.
Definition FeedItem.php:188
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition FeedItem.php:235
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:96
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.
Represents a title within MediaWiki.
Definition Title.php:78
A service to expand, parse, and otherwise manipulate URLs.
Definition UrlUtils.php:16