MediaWiki REL1_39
FeedItem.php
Go to the documentation of this file.
1<?php
26
36class FeedItem {
38 public $title;
39
41
42 public $url;
43
44 public $date;
45
46 public $author;
47
48 public $uniqueId;
49
50 public $comments;
51
52 public $rssIsPermalink = false;
53
62 public function __construct(
63 $title, $description, $url, $date = '', $author = '', $comments = ''
64 ) {
65 $this->title = $title;
66 $this->description = $description;
67 $this->url = $url;
68 $this->uniqueId = $url;
69 $this->date = $date;
70 $this->author = $author;
71 $this->comments = $comments;
72 }
73
80 public function xmlEncode( $string ) {
81 $string = str_replace( "\r\n", "\n", $string );
82 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
83 return htmlspecialchars( $string );
84 }
85
90 public function getUniqueID() {
91 $id = $this->getUniqueIdUnescaped();
92 if ( $id ) {
93 return $this->xmlEncode( $id );
94 }
95 }
96
101 public function getUniqueIdUnescaped() {
102 if ( $this->uniqueId ) {
103 return wfExpandUrl( $this->uniqueId, PROTO_CURRENT );
104 }
105 }
106
113 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
114 $this->uniqueId = $uniqueId;
115 $this->rssIsPermalink = $rssIsPermalink;
116 }
117
123 public function getTitle() {
124 return $this->xmlEncode( $this->title );
125 }
126
132 public function getUrl() {
133 return $this->xmlEncode( $this->url );
134 }
135
140 public function getUrlUnescaped() {
141 return $this->url;
142 }
143
149 public function getDescription() {
150 return $this->xmlEncode( $this->description );
151 }
152
158 public function getDescriptionUnescaped() {
159 return $this->description;
160 }
161
167 public function getLanguage() {
168 $languageCode = MediaWikiServices::getInstance()->getMainConfig()
169 ->get( MainConfigNames::LanguageCode );
170 return LanguageCode::bcp47( $languageCode );
171 }
172
178 public function getDate() {
179 return $this->date;
180 }
181
187 public function getAuthor() {
188 return $this->xmlEncode( $this->author );
189 }
190
196 public function getAuthorUnescaped() {
197 return $this->author;
198 }
199
205 public function getComments() {
206 return $this->xmlEncode( $this->comments );
207 }
208
214 public function getCommentsUnescaped() {
215 return $this->comments;
216 }
217
224 public static function stripComment( $text ) {
225 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
226 }
227
229}
const PROTO_CURRENT
Definition Defines.php:198
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:36
getLanguage()
Get the language of this item.
Definition FeedItem.php:167
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition FeedItem.php:113
getDescription()
Get the description of this item; already xml-encoded.
Definition FeedItem.php:149
$rssIsPermalink
Definition FeedItem.php:52
getDescriptionUnescaped()
Get the description of this item without any escaping.
Definition FeedItem.php:158
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition FeedItem.php:214
getTitle()
Get the title of this item; already xml-encoded.
Definition FeedItem.php:123
getDate()
Get the date of this item.
Definition FeedItem.php:178
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition FeedItem.php:101
Title $title
Definition FeedItem.php:38
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition FeedItem.php:224
getAuthor()
Get the author of this item; already xml-encoded.
Definition FeedItem.php:187
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition FeedItem.php:80
getComments()
Get the comment of this item; already xml-encoded.
Definition FeedItem.php:205
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition FeedItem.php:196
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition FeedItem.php:140
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition FeedItem.php:62
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition FeedItem.php:90
getUrl()
Get the URL of this item; already xml-encoded.
Definition FeedItem.php:132
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:49