MediaWiki REL1_40
FeedItem.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Feed;
25
26use LanguageCode;
30
40class FeedItem {
42 public $title;
43
45
46 public $url;
47
48 public $date;
49
50 public $author;
51
52 public $uniqueId;
53
54 public $comments;
55
56 public $rssIsPermalink = false;
57
66 public function __construct(
67 $title, $description, $url, $date = '', $author = '', $comments = ''
68 ) {
69 $this->title = $title;
70 $this->description = $description;
71 $this->url = $url;
72 $this->uniqueId = $url;
73 $this->date = $date;
74 $this->author = $author;
75 $this->comments = $comments;
76 }
77
84 public function xmlEncode( $string ) {
85 $string = str_replace( "\r\n", "\n", $string );
86 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
87 return htmlspecialchars( $string );
88 }
89
94 public function getUniqueID() {
95 $id = $this->getUniqueIdUnescaped();
96 if ( $id ) {
97 return $this->xmlEncode( $id );
98 }
99 }
100
105 public function getUniqueIdUnescaped() {
106 if ( $this->uniqueId ) {
107 return wfExpandUrl( $this->uniqueId, PROTO_CURRENT );
108 }
109 }
110
117 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
118 $this->uniqueId = $uniqueId;
119 $this->rssIsPermalink = $rssIsPermalink;
120 }
121
127 public function getTitle() {
128 return $this->xmlEncode( $this->title );
129 }
130
136 public function getUrl() {
137 return $this->xmlEncode( $this->url );
138 }
139
144 public function getUrlUnescaped() {
145 return $this->url;
146 }
147
153 public function getDescription() {
154 return $this->xmlEncode( $this->description );
155 }
156
162 public function getDescriptionUnescaped() {
163 return $this->description;
164 }
165
171 public function getLanguage() {
172 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
174 return LanguageCode::bcp47( $languageCode );
175 }
176
182 public function getDate() {
183 return $this->date;
184 }
185
191 public function getAuthor() {
192 return $this->xmlEncode( $this->author );
193 }
194
200 public function getAuthorUnescaped() {
201 return $this->author;
202 }
203
209 public function getComments() {
210 return $this->xmlEncode( $this->comments );
211 }
212
218 public function getCommentsUnescaped() {
219 return $this->comments;
220 }
221
228 public static function stripComment( $text ) {
229 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
230 }
231
233}
234
235class_alias( FeedItem::class, 'FeedItem' );
const PROTO_CURRENT
Definition Defines.php:198
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Methods for dealing with language codes.
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:162
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition FeedItem.php:105
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:144
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition FeedItem.php:94
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition FeedItem.php:66
getDate()
Get the date of this item.
Definition FeedItem.php:182
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:127
getAuthor()
Get the author of this item; already xml-encoded.
Definition FeedItem.php:191
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition FeedItem.php:117
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:153
getUrl()
Get the URL of this item; already xml-encoded.
Definition FeedItem.php:136
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition FeedItem.php:228
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition FeedItem.php:200
getComments()
Get the comment of this item; already xml-encoded.
Definition FeedItem.php:209
getLanguage()
Get the language of this item.
Definition FeedItem.php:171
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition FeedItem.php:218
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:84
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:82