r60880 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60879‎ | r60880 | r60881 >
Date:21:59, 9 January 2010
Author:ialex
Status:ok
Tags:
Comment:
* Document a bit
* Add new doxygen group "Feed"
* Fix some doxygen warnings
Modified paths:
  • /trunk/phase3/includes/ChangesFeed.php (modified) (history)
  • /trunk/phase3/includes/Feed.php (modified) (history)
  • /trunk/phase3/includes/FeedUtils.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/FeedUtils.php
@@ -1,8 +1,20 @@
22 <?php
33
4 -// TODO: document
 4+/**
 5+ * Helper functions for feeds
 6+ *
 7+ * @ingroup Feed
 8+ */
59 class FeedUtils {
610
 11+ /**
 12+ * Check whether feed's cache should be cleared; for changes feeds
 13+ * If the feed should be purged; $timekey and $key will be removed from
 14+ * $messageMemc
 15+ *
 16+ * @param $timekey String: cache key of the timestamp of the last item
 17+ * @param $key String: cache key of feed's content
 18+ */
719 public static function checkPurge( $timekey, $key ) {
820 global $wgRequest, $wgUser, $messageMemc;
921 $purge = $wgRequest->getVal( 'action' ) === 'purge';
@@ -12,6 +24,12 @@
1325 }
1426 }
1527
 28+ /**
 29+ * Check whether feeds can be used and that $type is a valid feed type
 30+ *
 31+ * @param $type String: feed type, as requested by the user
 32+ * @return Boolean
 33+ */
1634 public static function checkFeedOutput( $type ) {
1735 global $wgFeed, $wgFeedClasses;
1836
@@ -30,8 +48,11 @@
3149 }
3250
3351 /**
34 - * Format a diff for the newsfeed
35 - */
 52+ * Format a diff for the newsfeed
 53+ *
 54+ * @param $row Object: row from the recentchanges table
 55+ * @return String
 56+ */
3657 public static function formatDiff( $row ) {
3758 global $wgUser;
3859
@@ -53,6 +74,17 @@
5475 $actiontext );
5576 }
5677
 78+ /**
 79+ * Really format a diff for the newsfeed
 80+ *
 81+ * @param $title Title object
 82+ * @param $oldid Integer: old revision's id
 83+ * @param $newid Integer: new revision's id
 84+ * @param $timestamp Integer: new revision's timestamp
 85+ * @param $comment String: new revision's comment
 86+ * @param $actiontext String: text of the action; in case of log event
 87+ * @return String
 88+ */
5789 public static function formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
5890 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
5991 wfProfileIn( __FUNCTION__ );
@@ -129,14 +161,14 @@
130162 }
131163
132164 /**
133 - * Hacky application of diff styles for the feeds.
134 - * Might be 'cleaner' to use DOM or XSLT or something,
135 - * but *gack* it's a pain in the ass.
136 - *
137 - * @param $text String:
138 - * @return string
139 - * @private
140 - */
 165+ * Hacky application of diff styles for the feeds.
 166+ * Might be 'cleaner' to use DOM or XSLT or something,
 167+ * but *gack* it's a pain in the ass.
 168+ *
 169+ * @param $text String: diff's HTML output
 170+ * @return String: modified HTML
 171+ * @private
 172+ */
141173 public static function applyDiffStyle( $text ) {
142174 $styles = array(
143175 'diff' => 'background-color: white; color:black;',
Index: trunk/phase3/includes/Feed.php
@@ -19,13 +19,19 @@
2020 # http://www.gnu.org/copyleft/gpl.html
2121
2222 /**
 23+ * @defgroup Feed Feed
 24+ *
2325 * Basic support for outputting syndication feeds in RSS, other formats.
2426 * Contain a feed class as well as classes to build rss / atom ... feeds
2527 * Available feeds are defined in Defines.php
 28+ *
 29+ * @file
2630 */
2731
2832 /**
2933 * A base class for basic support for outputting syndication feeds in RSS and other formats.
 34+ *
 35+ * @ingroup Feed
3036 */
3137 class FeedItem {
3238 /**#@+
@@ -39,9 +45,15 @@
4046 var $Author = '';
4147 /**#@-*/
4248
43 - /**#@+
44 - * @todo document
45 - * @param $Url URL uniquely designating the item.
 49+ /**
 50+ * Constructor
 51+ *
 52+ * @param $Title String: Item's title
 53+ * @param $Description String
 54+ * @param $Url String: URL uniquely designating the item.
 55+ * @param $Date String: Item's date
 56+ * @param $Author String: Author's user name
 57+ * @param $Comments String
4658 */
4759 function __construct( $Title, $Description, $Url, $Date = '', $Author = '', $Comments = '' ) {
4860 $this->Title = $Title;
@@ -52,41 +64,87 @@
5365 $this->Comments = $Comments;
5466 }
5567
 68+ /**
 69+ * Encode $string so that it can be safely embedded in a XML document
 70+ *
 71+ * @param $string String: string to encode
 72+ * @return String
 73+ */
5674 public function xmlEncode( $string ) {
5775 $string = str_replace( "\r\n", "\n", $string );
5876 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string );
5977 return htmlspecialchars( $string );
6078 }
6179
 80+ /**
 81+ * Get the title of this item; already xml-encoded
 82+ *
 83+ * @return String
 84+ */
6285 public function getTitle() {
6386 return $this->xmlEncode( $this->Title );
6487 }
6588
 89+ /**
 90+ * Get the URL of this item; already xml-encoded
 91+ *
 92+ * @return String
 93+ */
6694 public function getUrl() {
6795 return $this->xmlEncode( $this->Url );
6896 }
6997
 98+ /**
 99+ * Get the description of this item; already xml-encoded
 100+ *
 101+ * @return String
 102+ */
70103 public function getDescription() {
71104 return $this->xmlEncode( $this->Description );
72105 }
73106
 107+ /**
 108+ * Get the language of this item
 109+ *
 110+ * @return String
 111+ */
74112 public function getLanguage() {
75113 global $wgContLanguageCode;
76114 return $wgContLanguageCode;
77115 }
78116
 117+ /**
 118+ * Get the title of this item
 119+ *
 120+ * @return String
 121+ */
79122 public function getDate() {
80123 return $this->Date;
81124 }
 125+
 126+ /**
 127+ * Get the author of this item; already xml-encoded
 128+ *
 129+ * @return String
 130+ */
82131 public function getAuthor() {
83132 return $this->xmlEncode( $this->Author );
84133 }
 134+
 135+ /**
 136+ * Get the comment of this item; already xml-encoded
 137+ *
 138+ * @return String
 139+ */
85140 public function getComments() {
86141 return $this->xmlEncode( $this->Comments );
87142 }
88143
89144 /**
90145 * Quickie hack... strip out wikilinks to more legible form from the comment.
 146+ *
 147+ * @param $text String: wikitext
 148+ * @return String
91149 */
92150 public static function stripComment( $text ) {
93151 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
@@ -96,6 +154,7 @@
97155
98156 /**
99157 * @todo document (needs one-sentence top-level class description).
 158+ * @ingroup Feed
100159 */
101160 class ChannelFeed extends FeedItem {
102161 /**#@+
@@ -133,10 +192,8 @@
134193 *
135194 * This should be called from the outHeader() method,
136195 * but can also be called separately.
137 - *
138 - * @public
139196 */
140 - function httpHeaders() {
 197+ public function httpHeaders() {
141198 global $wgOut;
142199
143200 # We take over from $wgOut, excepting its cache header info
@@ -178,13 +235,16 @@
179236
180237 /**
181238 * Generate a RSS feed
 239+ *
 240+ * @ingroup Feed
182241 */
183242 class RSSFeed extends ChannelFeed {
184243
185244 /**
186245 * Format a date given a timestamp
187 - * @param integer $ts Timestamp
188 - * @return string Date string
 246+ *
 247+ * @param $ts Integer: timestamp
 248+ * @return String: date string
189249 */
190250 function formatTime( $ts ) {
191251 return gmdate( 'D, d M Y H:i:s \G\M\T', wfTimestamp( TS_UNIX, $ts ) );
@@ -210,7 +270,7 @@
211271
212272 /**
213273 * Output an RSS 2.0 item
214 - * @param FeedItem item to be output
 274+ * @param $item FeedItem: item to be output
215275 */
216276 function outItem( $item ) {
217277 ?>
@@ -237,6 +297,8 @@
238298
239299 /**
240300 * Generate an Atom feed
 301+ *
 302+ * @ingroup Feed
241303 */
242304 class AtomFeed extends ChannelFeed {
243305 /**
Index: trunk/phase3/includes/ChangesFeed.php
@@ -1,14 +1,31 @@
22 <?php
33
 4+/**
 5+ * Feed to Special:RecentChanges and Special:RecentChangesLiked
 6+ *
 7+ * @ingroup Feed
 8+ */
49 class ChangesFeed {
5 -
610 public $format, $type, $titleMsg, $descMsg;
711
 12+ /**
 13+ * Constructor
 14+ *
 15+ * @param $format String: feed's format (either 'rss' or 'atom')
 16+ * @param $type String: type of feed (for cache keys)
 17+ */
818 public function __construct( $format, $type ) {
919 $this->format = $format;
1020 $this->type = $type;
1121 }
1222
 23+ /**
 24+ * Get a ChannelFeed subclass object to use
 25+ *
 26+ * @param $title String: feed's title
 27+ * @param $description String: feed's description
 28+ * @return ChannelFeed subclass or false on failure
 29+ */
1330 public function getFeedObject( $title, $description ) {
1431 global $wgSitename, $wgContLanguageCode, $wgFeedClasses, $wgTitle;
1532 $feedTitle = "$wgSitename - {$title} [$wgContLanguageCode]";
@@ -18,6 +35,18 @@
1936 $feedTitle, htmlspecialchars( $description ), $wgTitle->getFullUrl() );
2037 }
2138
 39+ /**
 40+ * Generates feed's content
 41+ *
 42+ * @param $feed ChannelFeed subclass object (generally the one returned by getFeedObject())
 43+ * @param $rows ResultWrapper object with rows in recentchanges table
 44+ * @param $limit Integer: number of rows in $rows (only used for the cache key)
 45+ * @param $hideminor Boolean: whether to hide minor edits (only used for the cache key)
 46+ * @param $lastmod Integer: timestamp of the last item in the recentchanges table (only used for the cache key)
 47+ * @param $target String: target's name; for Special:RecentChangesLinked (only used for the cache key)
 48+ * @param $namespace Integer: namespace id (only used for the cache key)
 49+ * @return null or true
 50+ */
2251 public function execute( $feed, $rows, $limit=0, $hideminor=false, $lastmod=false, $target='', $namespace='' ) {
2352 global $messageMemc, $wgFeedCacheTimeout;
2453 global $wgSitename, $wgLang;
@@ -52,6 +81,13 @@
5382 return true;
5483 }
5584
 85+ /**
 86+ * Save to feed result to $messageMemc
 87+ *
 88+ * @param $feed String: feed's content
 89+ * @param $timekey String: memcached key of the last modification
 90+ * @param $key String: memcached key of the content
 91+ */
5692 public function saveToCache( $feed, $timekey, $key ) {
5793 global $messageMemc;
5894 $expire = 3600 * 24; # One day
@@ -59,6 +95,14 @@
6096 $messageMemc->set( $timekey, wfTimestamp( TS_MW ), $expire );
6197 }
6298
 99+ /**
 100+ * Try to load the feed result from $messageMemc
 101+ *
 102+ * @param $lastmod Integer: timestamp of the last item in the recentchanges table
 103+ * @param $timekey String: memcached key of the last modification
 104+ * @param $key String: memcached key of the content
 105+ * @return feed's content on cache hit or false on cache miss
 106+ */
63107 public function loadFromCache( $lastmod, $timekey, $key ) {
64108 global $wgFeedCacheTimeout, $messageMemc;
65109 $feedLastmod = $messageMemc->get( $timekey );
@@ -86,10 +130,10 @@
87131 }
88132
89133 /**
90 - * Generate the feed items given a row from the database.
91 - * @param $rows Database resource with recentchanges rows
92 - * @param $feed Feed object
93 - */
 134+ * Generate the feed items given a row from the database.
 135+ * @param $rows DatabaseBase resource with recentchanges rows
 136+ * @param $feed Feed object
 137+ */
94138 public static function generateFeed( $rows, &$feed ) {
95139 wfProfileIn( __METHOD__ );
96140

Status & tagging log