X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FFeed.php;h=f9dbf5ba715f6086bc6bad078396e56154f1b267;hb=6088cd4458f6b6ca36bcdd881c4c3d4d49b6d1b8;hp=21e8f084f592e0c031436aee147b8cda224803a0;hpb=46727906bb3491394854dd5ef877bbb459383a91;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Feed.php b/includes/Feed.php index 21e8f084f5..f9dbf5ba71 100644 --- a/includes/Feed.php +++ b/includes/Feed.php @@ -1,107 +1,217 @@ -# http://www.mediawiki.org/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# http://www.gnu.org/copyleft/gpl.html - /** * Basic support for outputting syndication feeds in RSS, other formats. + * * Contain a feed class as well as classes to build rss / atom ... feeds * Available feeds are defined in Defines.php + * + * Copyright © 2004 Brion Vibber + * http://www.mediawiki.org/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + */ + +/** + * @defgroup Feed Feed */ /** * A base class for basic support for outputting syndication feeds in RSS and other formats. + * + * @ingroup Feed */ class FeedItem { - /**#@+ - * @var string - * @private + /** + * @var Title */ - var $Title = 'Wiki'; - var $Description = ''; - var $Url = ''; - var $Date = ''; - var $Author = ''; - /**#@-*/ + var $title; - /**#@+ - * @todo document - * @param $Url URL uniquely designating the item. + var $description; + var $url; + var $date; + var $author; + var $uniqueId; + var $comments; + var $rssIsPermalink = false; + + /** + * Constructor + * + * @param $title String|Title Item's title + * @param $description String + * @param $url String: URL uniquely designating the item. + * @param $date String: Item's date + * @param $author String: Author's user name + * @param $comments String */ - function __construct( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) { - $this->Title = $Title; - $this->Description = $Description; - $this->Url = $Url; - $this->Date = $Date; - $this->Author = $Author; - $this->Comments = $Comments; + function __construct( $title, $description, $url, $date = '', $author = '', $comments = '' ) { + $this->title = $title; + $this->description = $description; + $this->url = $url; + $this->uniqueId = $url; + $this->date = $date; + $this->author = $author; + $this->comments = $comments; } - function xmlEncode( $string ) { + /** + * Encode $string so that it can be safely embedded in a XML document + * + * @param $string String: string to encode + * @return String + */ + public function xmlEncode( $string ) { $string = str_replace( "\r\n", "\n", $string ); $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string ); return htmlspecialchars( $string ); } - function getTitle() { return $this->xmlEncode( $this->Title ); } - function getUrl() { return $this->xmlEncode( $this->Url ); } - function getDescription() { return $this->xmlEncode( $this->Description ); } - function getLanguage() { - global $wgContLanguageCode; - return $wgContLanguageCode; + /** + * Get the unique id of this item + * + * @return String + */ + public function getUniqueId() { + if ( $this->uniqueId ) { + return $this->xmlEncode( $this->uniqueId ); + } + } + + /** + * set the unique id of an item + * + * @param $uniqueId String: unique id for the item + * @param $rssIsPermalink Boolean: set to true if the guid (unique id) is a permalink (RSS feeds only) + */ + public function setUniqueId( $uniqueId, $rssIsPermalink = false ) { + $this->uniqueId = $uniqueId; + $this->rssIsPermalink = $rssIsPermalink; + } + + /** + * Get the title of this item; already xml-encoded + * + * @return String + */ + public function getTitle() { + return $this->xmlEncode( $this->title ); + } + + /** + * Get the URL of this item; already xml-encoded + * + * @return String + */ + public function getUrl() { + return $this->xmlEncode( $this->url ); + } + + /** + * Get the description of this item; already xml-encoded + * + * @return String + */ + public function getDescription() { + return $this->xmlEncode( $this->description ); + } + + /** + * Get the language of this item + * + * @return String + */ + public function getLanguage() { + global $wgLanguageCode; + return $wgLanguageCode; + } + + /** + * Get the title of this item + * + * @return String + */ + public function getDate() { + return $this->date; + } + + /** + * Get the author of this item; already xml-encoded + * + * @return String + */ + public function getAuthor() { + return $this->xmlEncode( $this->author ); + } + + /** + * Get the comment of this item; already xml-encoded + * + * @return String + */ + public function getComments() { + return $this->xmlEncode( $this->comments ); + } + + /** + * Quickie hack... strip out wikilinks to more legible form from the comment. + * + * @param $text String: wikitext + * @return String + */ + public static function stripComment( $text ) { + return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text ); } - function getDate() { return $this->Date; } - function getAuthor() { return $this->xmlEncode( $this->Author ); } - function getComments() { return $this->xmlEncode( $this->Comments ); } /**#@-*/ } /** * @todo document (needs one-sentence top-level class description). + * @ingroup Feed */ -class ChannelFeed extends FeedItem { - /**#@+ - * Abstract function, override! - * @abstract - */ - +abstract class ChannelFeed extends FeedItem { /** * Generate Header of the feed + * @par Example: + * @code + * print ""; + * @endcode + * @param $item */ - function outHeader() { - # print ""; - } + abstract public function outHeader(); /** * Generate an item + * @par Example: + * @code + * print "..."; + * @endcode * @param $item */ - function outItem( $item ) { - # print "..."; - } + abstract public function outItem( $item ); /** * Generate Footer of the feed + * @par Example: + * @code + * print ""; + * @endcode */ - function outFooter() { - # print ""; - } - /**#@-*/ + abstract public function outFooter(); /** * Setup and send HTTP headers. Don't send any content; @@ -110,16 +220,17 @@ class ChannelFeed extends FeedItem { * * This should be called from the outHeader() method, * but can also be called separately. - * - * @public */ - function httpHeaders() { - global $wgOut; + public function httpHeaders() { + global $wgOut, $wgVaryOnXFP; # We take over from $wgOut, excepting its cache header info $wgOut->disable(); $mimetype = $this->contentType(); header( "Content-type: $mimetype; charset=UTF-8" ); + if ( $wgVaryOnXFP ) { + $wgOut->addVaryHeader( 'X-Forwarded-Proto' ); + } $wgOut->sendCacheControl(); } @@ -146,22 +257,25 @@ class ChannelFeed extends FeedItem { global $wgStylePath, $wgStyleVersion; $this->httpHeaders(); - echo '' . "\n"; + echo '' . "\n"; echo '\n"; } } /** * Generate a RSS feed + * + * @ingroup Feed */ class RSSFeed extends ChannelFeed { /** * Format a date given a timestamp - * @param integer $ts Timestamp - * @return string Date string + * + * @param $ts Integer: timestamp + * @return String: date string */ function formatTime( $ts ) { return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) ); @@ -177,7 +291,7 @@ class RSSFeed extends ChannelFeed { ?> <?php print $this->getTitle() ?> - getUrl() ?> + getUrl(), PROTO_CURRENT ) ?> getDescription() ?> getLanguage() ?> MediaWiki @@ -187,17 +301,18 @@ class RSSFeed extends ChannelFeed { /** * Output an RSS 2.0 item - * @param FeedItem item to be output + * @param $item FeedItem: item to be output */ function outItem( $item ) { ?> <?php print $item->getTitle() ?> - getUrl() ?> + getUrl(), PROTO_CURRENT ) ?> + rssIsPermalink ) print ' isPermaLink="false"' ?>>getUniqueId() ?> getDescription() ?> getDate() ) { ?>formatTime( $item->getDate() ) ?> getAuthor() ) { ?>getAuthor() ?> - getComments() ) { ?>getComments() ?> + getComments() ) { ?>getComments(), PROTO_CURRENT ) ?> getFeedId() ?> <?php print $this->getTitle() ?> - - + + formatTime( wfTimestampNow() ) ?>Z getDescription() ?> MediaWiki @@ -274,9 +392,9 @@ class AtomFeed extends ChannelFeed { global $wgMimeType; ?> - getUrl() ?> + getUniqueId() ?> <?php print $item->getTitle() ?> - + getDate() ) { ?> formatTime( $item->getDate() ) ?>Z @@ -285,9 +403,9 @@ class AtomFeed extends ChannelFeed { getAuthor() ) { ?>getAuthor() ?> -getComments() ) { ?>getComments() ?> - */ + */ } /**