MediaWiki  1.34.0
FeedItem.php
Go to the documentation of this file.
1 <?php
33 class FeedItem {
35  public $title;
36 
37  public $description;
38 
39  public $url;
40 
41  public $date;
42 
43  public $author;
44 
45  public $uniqueId;
46 
47  public $comments;
48 
49  public $rssIsPermalink = false;
50 
59  function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
60  $this->title = $title;
61  $this->description = $description;
62  $this->url = $url;
63  $this->uniqueId = $url;
64  $this->date = $date;
65  $this->author = $author;
66  $this->comments = $comments;
67  }
68 
75  public function xmlEncode( $string ) {
76  $string = str_replace( "\r\n", "\n", $string );
77  $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
78  return htmlspecialchars( $string );
79  }
80 
85  public function getUniqueID() {
86  $id = $this->getUniqueIdUnescaped();
87  if ( $id ) {
88  return $this->xmlEncode( $id );
89  }
90  }
91 
96  public function getUniqueIdUnescaped() {
97  if ( $this->uniqueId ) {
98  return wfExpandUrl( $this->uniqueId, PROTO_CURRENT );
99  }
100  }
101 
108  public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
109  $this->uniqueId = $uniqueId;
110  $this->rssIsPermalink = $rssIsPermalink;
111  }
112 
118  public function getTitle() {
119  return $this->xmlEncode( $this->title );
120  }
121 
127  public function getUrl() {
128  return $this->xmlEncode( $this->url );
129  }
130 
135  public function getUrlUnescaped() {
136  return $this->url;
137  }
138 
144  public function getDescription() {
145  return $this->xmlEncode( $this->description );
146  }
147 
153  public function getDescriptionUnescaped() {
154  return $this->description;
155  }
156 
162  public function getLanguage() {
163  global $wgLanguageCode;
165  }
166 
172  public function getDate() {
173  return $this->date;
174  }
175 
181  public function getAuthor() {
182  return $this->xmlEncode( $this->author );
183  }
184 
190  public function getAuthorUnescaped() {
191  return $this->author;
192  }
193 
199  public function getComments() {
200  return $this->xmlEncode( $this->comments );
201  }
202 
208  public function getCommentsUnescaped() {
209  return $this->comments;
210  }
211 
218  public static function stripComment( $text ) {
219  return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
220  }
222 }
FeedItem
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:33
FeedItem\$url
$url
Definition: FeedItem.php:39
FeedItem\$description
$description
Definition: FeedItem.php:37
FeedItem\$rssIsPermalink
$rssIsPermalink
Definition: FeedItem.php:49
FeedItem\getDescriptionUnescaped
getDescriptionUnescaped()
Get the description of this item without any escaping.
Definition: FeedItem.php:153
FeedItem\getLanguage
getLanguage()
Get the language of this item.
Definition: FeedItem.php:162
FeedItem\stripComment
static stripComment( $text)
Quickie hack...
Definition: FeedItem.php:218
FeedItem\getTitle
getTitle()
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:118
FeedItem\getAuthor
getAuthor()
Get the author of this item; already xml-encoded.
Definition: FeedItem.php:181
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:202
FeedItem\$date
$date
Definition: FeedItem.php:41
FeedItem\getDate
getDate()
Get the date of this item.
Definition: FeedItem.php:172
FeedItem\getAuthorUnescaped
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition: FeedItem.php:190
FeedItem\getCommentsUnescaped
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition: FeedItem.php:208
FeedItem\setUniqueId
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition: FeedItem.php:108
FeedItem\getDescription
getDescription()
Get the description of this item; already xml-encoded.
Definition: FeedItem.php:144
FeedItem\getUniqueIdUnescaped
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition: FeedItem.php:96
FeedItem\getUrl
getUrl()
Get the URL of this item; already xml-encoded.
Definition: FeedItem.php:127
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2948
FeedItem\$comments
$comments
Definition: FeedItem.php:47
FeedItem\__construct
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition: FeedItem.php:59
Title
Represents a title within MediaWiki.
Definition: Title.php:42
FeedItem\xmlEncode
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition: FeedItem.php:75
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:178
FeedItem\$author
$author
Definition: FeedItem.php:43
FeedItem\$title
Title $title
Definition: FeedItem.php:35
FeedItem\getComments
getComments()
Get the comment of this item; already xml-encoded.
Definition: FeedItem.php:199
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491
FeedItem\getUrlUnescaped
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition: FeedItem.php:135
FeedItem\getUniqueID
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition: FeedItem.php:85
FeedItem\$uniqueId
$uniqueId
Definition: FeedItem.php:45