3 * Copyright © 2004 Brion Vibber <brion@pobox.com>
4 * https://www.mediawiki.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
29 * A base class for outputting syndication feeds (e.g. RSS and other formats).
49 public $rssIsPermalink = false;
52 * @param string|Title $title Item's title
53 * @param string $description
54 * @param string $url URL uniquely designating the item.
55 * @param string $date Item's date
56 * @param string $author Author's user name
57 * @param string $comments
59 function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) {
60 $this->title
= $title;
61 $this->description
= $description;
63 $this->uniqueId
= $url;
65 $this->author
= $author;
66 $this->comments
= $comments;
70 * Encode $string so that it can be safely embedded in a XML document
72 * @param string $string String to encode
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 );
82 * Get the unique id of this item; already xml-encoded
85 public function getUniqueID() {
86 $id = $this->getUniqueIdUnescaped();
88 return $this->xmlEncode( $id );
93 * Get the unique id of this item, without any escaping
96 public function getUniqueIdUnescaped() {
97 if ( $this->uniqueId
) {
98 return wfExpandUrl( $this->uniqueId
, PROTO_CURRENT
);
103 * Set the unique id of an item
105 * @param string $uniqueId Unique id for the item
106 * @param bool $rssIsPermalink Set to true if the guid (unique id) is a permalink (RSS feeds only)
108 public function setUniqueId( $uniqueId, $rssIsPermalink = false ) {
109 $this->uniqueId
= $uniqueId;
110 $this->rssIsPermalink
= $rssIsPermalink;
114 * Get the title of this item; already xml-encoded
118 public function getTitle() {
119 return $this->xmlEncode( $this->title
);
123 * Get the URL of this item; already xml-encoded
127 public function getUrl() {
128 return $this->xmlEncode( $this->url
);
131 /** Get the URL of this item without any escaping
135 public function getUrlUnescaped() {
140 * Get the description of this item; already xml-encoded
144 public function getDescription() {
145 return $this->xmlEncode( $this->description
);
149 * Get the description of this item without any escaping
153 public function getDescriptionUnescaped() {
154 return $this->description
;
158 * Get the language of this item
162 public function getLanguage() {
163 global $wgLanguageCode;
164 return LanguageCode
::bcp47( $wgLanguageCode );
168 * Get the date of this item
172 public function getDate() {
177 * Get the author of this item; already xml-encoded
181 public function getAuthor() {
182 return $this->xmlEncode( $this->author
);
186 * Get the author of this item without any escaping
190 public function getAuthorUnescaped() {
191 return $this->author
;
195 * Get the comment of this item; already xml-encoded
199 public function getComments() {
200 return $this->xmlEncode( $this->comments
);
204 * Get the comment of this item without any escaping
208 public function getCommentsUnescaped() {
209 return $this->comments
;
213 * Quickie hack... strip out wikilinks to more legible form from the comment.
215 * @param string $text Wikitext
218 public static function stripComment( $text ) {
219 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );