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  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;
164  return LanguageCode::bcp47( $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 }
static stripComment( $text)
Quickie hack...
Definition: FeedItem.php:218
getDescriptionUnescaped()
Get the description of this item without any escaping.
Definition: FeedItem.php:153
getUrlUnescaped()
Get the URL of this item without any escaping.
Definition: FeedItem.php:135
getAuthorUnescaped()
Get the author of this item without any escaping.
Definition: FeedItem.php:190
$description
Definition: FeedItem.php:37
getDate()
Get the date of this item.
Definition: FeedItem.php:172
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
getUniqueID()
Get the unique id of this item; already xml-encoded.
Definition: FeedItem.php:85
getUniqueIdUnescaped()
Get the unique id of this item, without any escaping.
Definition: FeedItem.php:96
getComments()
Get the comment of this item; already xml-encoded.
Definition: FeedItem.php:199
const PROTO_CURRENT
Definition: Defines.php:222
setUniqueId( $uniqueId, $rssIsPermalink=false)
Set the unique id of an item.
Definition: FeedItem.php:108
title
$wgLanguageCode
Site language code.
$rssIsPermalink
Definition: FeedItem.php:49
getAuthor()
Get the author of this item; already xml-encoded.
Definition: FeedItem.php:181
__construct( $title, $description, $url, $date='', $author='', $comments='')
Definition: FeedItem.php:59
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:33
getLanguage()
Get the language of this item.
Definition: FeedItem.php:162
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getTitle()
Get the title of this item; already xml-encoded.
Definition: FeedItem.php:118
Title $title
Definition: FeedItem.php:35
getCommentsUnescaped()
Get the comment of this item without any escaping.
Definition: FeedItem.php:208
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
getUrl()
Get the URL of this item; already xml-encoded.
Definition: FeedItem.php:127
getDescription()
Get the description of this item; already xml-encoded.
Definition: FeedItem.php:144
xmlEncode( $string)
Encode $string so that it can be safely embedded in a XML document.
Definition: FeedItem.php:75