MediaWiki  master
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  public function __construct(
60  $title, $description, $url, $date = '', $author = '', $comments = ''
61  ) {
62  $this->title = $title;
63  $this->description = $description;
64  $this->url = $url;
65  $this->uniqueId = $url;
66  $this->date = $date;
67  $this->author = $author;
68  $this->comments = $comments;
69  }
70 
77  public function xmlEncode( $string ) {
78  $string = str_replace( "\r\n", "\n", $string );
79  $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
80  return htmlspecialchars( $string );
81  }
82 
87  public function getUniqueID() {
88  $id = $this->getUniqueIdUnescaped();
89  if ( $id ) {
90  return $this->xmlEncode( $id );
91  }
92  }
93 
98  public function getUniqueIdUnescaped() {
99  if ( $this->uniqueId ) {
100  return wfExpandUrl( $this->uniqueId, PROTO_CURRENT );
101  }
102  }
103 
110  public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
111  $this->uniqueId = $uniqueId;
112  $this->rssIsPermalink = $rssIsPermalink;
113  }
114 
120  public function getTitle() {
121  return $this->xmlEncode( $this->title );
122  }
123 
129  public function getUrl() {
130  return $this->xmlEncode( $this->url );
131  }
132 
137  public function getUrlUnescaped() {
138  return $this->url;
139  }
140 
146  public function getDescription() {
147  return $this->xmlEncode( $this->description );
148  }
149 
155  public function getDescriptionUnescaped() {
156  return $this->description;
157  }
158 
164  public function getLanguage() {
165  global $wgLanguageCode;
167  }
168 
174  public function getDate() {
175  return $this->date;
176  }
177 
183  public function getAuthor() {
184  return $this->xmlEncode( $this->author );
185  }
186 
192  public function getAuthorUnescaped() {
193  return $this->author;
194  }
195 
201  public function getComments() {
202  return $this->xmlEncode( $this->comments );
203  }
204 
210  public function getCommentsUnescaped() {
211  return $this->comments;
212  }
213 
220  public static function stripComment( $text ) {
221  return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
222  }
224 }
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:155
FeedItem\getLanguage
getLanguage()
Get the language of this item.
Definition: FeedItem.php:164
FeedItem\stripComment
static stripComment( $text)
Quickie hack...
Definition: FeedItem.php:220
FeedItem\getTitle
getTitle()
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:120
FeedItem\getAuthor
getAuthor()
Get the author of this item; already xml-encoded.
Definition: FeedItem.php:183
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:174
FeedItem\getAuthorUnescaped
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition: FeedItem.php:192
FeedItem\getCommentsUnescaped
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition: FeedItem.php:210
FeedItem\setUniqueId
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition: FeedItem.php:110
FeedItem\getDescription
getDescription()
Get the description of this item; already xml-encoded.
Definition: FeedItem.php:146
FeedItem\getUniqueIdUnescaped
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition: FeedItem.php:98
FeedItem\getUrl
getUrl()
Get the URL of this item; already xml-encoded.
Definition: FeedItem.php:129
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2949
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:77
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:176
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:201
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:137
FeedItem\getUniqueID
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition: FeedItem.php:87
FeedItem\$uniqueId
$uniqueId
Definition: FeedItem.php:45