r75081 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75080‎ | r75081 | r75082 >
Date:11:25, 20 October 2010
Author:ashley
Status:ok
Tags:
Comment:
RSS: follow-up to r75046: coding style tweaks
Modified paths:
  • /trunk/extensions/RSS/RSS.php (modified) (history)
  • /trunk/extensions/RSS/RSSData.php (modified) (history)
  • /trunk/extensions/RSS/RSSFetch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RSS/RSSData.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 class RSSData {
45 public $etag;
56 public $last_modified;
@@ -8,49 +9,50 @@
910
1011 function __construct( $resp ) {
1112 $this->xml = new DOMDocument;
12 - $this->xml->loadXML($resp->getContent());
13 - $h = $resp->getResponseHeader('ETag');
 13+ $this->xml->loadXML( $resp->getContent() );
 14+ $h = $resp->getResponseHeader( 'ETag' );
1415 $this->etag = $h;
15 - $h = $resp->getResponseHeader('Last-Modified');
 16+ $h = $resp->getResponseHeader( 'Last-Modified' );
1617 $this->last_modified = $h;
1718
18 - $xpath = new DOMXPath($this->xml);
19 - $items = $xpath->evaluate("/rss/channel/item");
 19+ $xpath = new DOMXPath( $this->xml );
 20+ $items = $xpath->evaluate( '/rss/channel/item' );
2021
21 - foreach($items as $item) {
 22+ foreach( $items as $item ) {
2223 $bit = array();
23 - foreach($item->childNodes as $n) {
24 - $name = $this->rssTokenToName($n->nodeName);
25 - if($name != null)
 24+ foreach( $item->childNodes as $n ) {
 25+ $name = $this->rssTokenToName( $n->nodeName );
 26+ if( $name != null ) {
2627 $bit[$name] = $n->nodeValue;
 28+ }
2729 }
2830 $this->items[] = $bit;
2931 }
3032 }
3133
32 - function rssTokenToName($n) {
33 - switch($n) {
34 - case "dc:date":
35 - return "date";
 34+ function rssTokenToName( $n ) {
 35+ switch( $n ) {
 36+ case 'dc:date':
 37+ return 'date';
3638 # parse "2010-10-18T18:07:00Z"
37 - case "pubDate":
38 - return "date";
 39+ case 'pubDate':
 40+ return 'date';
3941 # parse RFC date
40 - case "dc:creator":
41 - return "author";
42 - case "title":
43 - return "title";
44 - case "content:encoded":
45 - return "encodedContent";
 42+ case 'dc:creator':
 43+ return 'author';
 44+ case 'title':
 45+ return 'title';
 46+ case 'content:encoded':
 47+ return 'encodedContent';
4648
47 - case "slash:comments":
48 - case "slash:department":
49 - case "slash:section":
50 - case "slash:hit_parade":
51 - case "feedburner:origLink":
52 - case "wfw:commentRss":
53 - case "comments":
54 - case "category":
 49+ case 'slash:comments':
 50+ case 'slash:department':
 51+ case 'slash:section':
 52+ case 'slash:hit_parade':
 53+ case 'feedburner:origLink':
 54+ case 'wfw:commentRss':
 55+ case 'comments':
 56+ case 'category':
5557 return null;
5658
5759 default:
Index: trunk/extensions/RSS/RSSFetch.php
@@ -48,7 +48,8 @@
4949 global $wgRSSOutputEncoding, $wgRSSInputEncoding;
5050 global $wgRSSDetectEncoding, $wgRSSUseGzip;
5151
52 - $nameValue = array('wgRSSCache' => true,
 52+ $nameValue = array(
 53+ 'wgRSSCache' => true,
5354 'wgRSSCacheAge' => 60 * 60, // one hour
5455 'wgRSSCacheFreshOnly' => false,
5556 'wgRSSCacheDirectory' => '/extensions/RSS/cache',
@@ -56,9 +57,10 @@
5758 'wgRSSInputEncoding' => null,
5859 'wgRSSDetectEncoding' => true,
5960 'wgRSSFetchTimeout' => 5, // 5 second timeout
60 - 'wgRSSUseGzip' => true);
 61+ 'wgRSSUseGzip' => true
 62+ );
6163
62 - foreach($nameValue as $n => $v) {
 64+ foreach( $nameValue as $n => $v) {
6365 if( !isset( $GLOBALS[$n] ) ) {
6466 $GLOBALS[$n] = $v;
6567 }
@@ -194,13 +196,13 @@
195197 global $wgRSSFetchTimeout, $wgRSSUseGzip;
196198
197199 $client =
198 - HttpRequest::factory($url, array('timeout' => $wgRSSFetchTimeout));
199 - $client->setUserAgent('MediawikiRSS/0.01 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension');
 200+ HttpRequest::factory( $url, array( 'timeout' => $wgRSSFetchTimeout ) );
 201+ $client->setUserAgent( 'MediaWikiRSS/0.01 (+http://www.mediawiki.org/wiki/Extension:RSS) / MediaWiki RSS extension' );
200202 /* $client->use_gzip = $wgRSSUseGzip; */
201203 if ( is_array( $headers ) && count( $headers ) > 0 ) {
202 - foreach($headers as $h) {
 204+ foreach( $headers as $h ) {
203205 if( count( $h ) > 1 ) {
204 - $client->setHeader($h[0], $h[1]);
 206+ $client->setHeader( $h[0], $h[1] );
205207 }
206208 }
207209 }
@@ -222,7 +224,7 @@
223225 */
224226 function _response_to_rss( $resp ) {
225227 global $wgRSSOutputEncoding, $wgRSSInputEncoding, $wgRSSDetectEncoding;
226 - $rss = new RSSData($resp);
 228+ $rss = new RSSData( $resp );
227229
228230 // if RSS parsed successfully
229231 if ( $rss && !$rss->ERROR ) {
Index: trunk/extensions/RSS/RSS.php
@@ -131,9 +131,9 @@
132132 }
133133
134134 if( isset( $args['template'] ) ) {
135 - $template = 'Template:'.$args['template'];
 135+ $template = 'Template:' . $args['template'];
136136 } else {
137 - $template = wfMsgNoTrans("rss-item");
 137+ $template = wfMsgNoTrans( 'rss-item' );
138138 }
139139
140140 $headcnt = 0;
@@ -160,43 +160,48 @@
161161
162162 $output = '';
163163
164 - /* This would be better served by preg_replace_callback, but
 164+ /**
 165+ * This would be better served by preg_replace_callback, but
165166 * I can't create a callback that carries $item in PHP < 5.3
166167 */
167168 if ( $template ) {
168169 $headcnt = 0;
169170 foreach( $rss->items as $item ) {
170 - if($maxheads > 0 && $headcnt >= $maxheads) continue;
 171+ if( $maxheads > 0 && $headcnt >= $maxheads ) {
 172+ continue;
 173+ }
171174
172175 $decision = true;
173 - foreach(array('title', 'author', 'description', 'category') as $check) {
 176+ foreach( array( 'title', 'author', 'description', 'category' ) as $check ) {
174177 if( isset( $item[$check] ) ) {
175 - $decision &= wfRssFilter($item[$check], $rssFilter) & wfRssFilterout($item[$check], $rssFilterout);
176 - if( !$decision ) continue 2;
 178+ $decision &= wfRssFilter( $item[$check], $rssFilter ) & wfRssFilterout( $item[$check], $rssFilterout );
 179+ if( !$decision ) {
 180+ continue 2;
 181+ }
177182
178183 $item[$check] = wfRssHighlight( $item[$check], $rssHighlight );
179184 }
180185
181186 }
182187
183 - $rssTemp = "";
 188+ $rssTemp = '';
184189
185 - foreach(explode("|", $template) as $bit) {
186 - $bits = explode("=", $bit);
187 - if( count($bits) == 2 ) {
188 - $left = trim($bits[0]);
 190+ foreach( explode( '|', $template ) as $bit ) {
 191+ $bits = explode( '=', $bit );
 192+ if( count( $bits ) == 2 ) {
 193+ $left = trim( $bits[0] );
189194
190195 if( isset( $item[$left] ) ) {
191196 $right = $item[$left];
192197 }
193198
194 - $rssTemp .= implode( " = ", array($left, $right) );
 199+ $rssTemp .= implode( ' = ', array( $left, $right ) );
195200 } else {
196201 $rssTemp .= $bit;
197202 }
198 - $rssTemp .= "|";
 203+ $rssTemp .= '|';
199204 }
200 - $rssTemp .= "}}";
 205+ $rssTemp .= '}}';
201206
202207 $output .= $parser->recursiveTagParse( $rssTemp, $frame );
203208 $headcnt++;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75046* Use [[Template:RSSPost]] (and [[Mediawiki:Rss-item]]) (or another...mah21:54, 19 October 2010

Status & tagging log