Index: trunk/extensions/RSS/RSSData.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | class RSSData { |
4 | 5 | public $etag; |
5 | 6 | public $last_modified; |
— | — | @@ -8,49 +9,50 @@ |
9 | 10 | |
10 | 11 | function __construct( $resp ) { |
11 | 12 | $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' ); |
14 | 15 | $this->etag = $h; |
15 | | - $h = $resp->getResponseHeader('Last-Modified'); |
| 16 | + $h = $resp->getResponseHeader( 'Last-Modified' ); |
16 | 17 | $this->last_modified = $h; |
17 | 18 | |
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' ); |
20 | 21 | |
21 | | - foreach($items as $item) { |
| 22 | + foreach( $items as $item ) { |
22 | 23 | $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 ) { |
26 | 27 | $bit[$name] = $n->nodeValue; |
| 28 | + } |
27 | 29 | } |
28 | 30 | $this->items[] = $bit; |
29 | 31 | } |
30 | 32 | } |
31 | 33 | |
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'; |
36 | 38 | # parse "2010-10-18T18:07:00Z" |
37 | | - case "pubDate": |
38 | | - return "date"; |
| 39 | + case 'pubDate': |
| 40 | + return 'date'; |
39 | 41 | # 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'; |
46 | 48 | |
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': |
55 | 57 | return null; |
56 | 58 | |
57 | 59 | default: |
Index: trunk/extensions/RSS/RSSFetch.php |
— | — | @@ -48,7 +48,8 @@ |
49 | 49 | global $wgRSSOutputEncoding, $wgRSSInputEncoding; |
50 | 50 | global $wgRSSDetectEncoding, $wgRSSUseGzip; |
51 | 51 | |
52 | | - $nameValue = array('wgRSSCache' => true, |
| 52 | + $nameValue = array( |
| 53 | + 'wgRSSCache' => true, |
53 | 54 | 'wgRSSCacheAge' => 60 * 60, // one hour |
54 | 55 | 'wgRSSCacheFreshOnly' => false, |
55 | 56 | 'wgRSSCacheDirectory' => '/extensions/RSS/cache', |
— | — | @@ -56,9 +57,10 @@ |
57 | 58 | 'wgRSSInputEncoding' => null, |
58 | 59 | 'wgRSSDetectEncoding' => true, |
59 | 60 | 'wgRSSFetchTimeout' => 5, // 5 second timeout |
60 | | - 'wgRSSUseGzip' => true); |
| 61 | + 'wgRSSUseGzip' => true |
| 62 | + ); |
61 | 63 | |
62 | | - foreach($nameValue as $n => $v) { |
| 64 | + foreach( $nameValue as $n => $v) { |
63 | 65 | if( !isset( $GLOBALS[$n] ) ) { |
64 | 66 | $GLOBALS[$n] = $v; |
65 | 67 | } |
— | — | @@ -194,13 +196,13 @@ |
195 | 197 | global $wgRSSFetchTimeout, $wgRSSUseGzip; |
196 | 198 | |
197 | 199 | $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' ); |
200 | 202 | /* $client->use_gzip = $wgRSSUseGzip; */ |
201 | 203 | if ( is_array( $headers ) && count( $headers ) > 0 ) { |
202 | | - foreach($headers as $h) { |
| 204 | + foreach( $headers as $h ) { |
203 | 205 | if( count( $h ) > 1 ) { |
204 | | - $client->setHeader($h[0], $h[1]); |
| 206 | + $client->setHeader( $h[0], $h[1] ); |
205 | 207 | } |
206 | 208 | } |
207 | 209 | } |
— | — | @@ -222,7 +224,7 @@ |
223 | 225 | */ |
224 | 226 | function _response_to_rss( $resp ) { |
225 | 227 | global $wgRSSOutputEncoding, $wgRSSInputEncoding, $wgRSSDetectEncoding; |
226 | | - $rss = new RSSData($resp); |
| 228 | + $rss = new RSSData( $resp ); |
227 | 229 | |
228 | 230 | // if RSS parsed successfully |
229 | 231 | if ( $rss && !$rss->ERROR ) { |
Index: trunk/extensions/RSS/RSS.php |
— | — | @@ -131,9 +131,9 @@ |
132 | 132 | } |
133 | 133 | |
134 | 134 | if( isset( $args['template'] ) ) { |
135 | | - $template = 'Template:'.$args['template']; |
| 135 | + $template = 'Template:' . $args['template']; |
136 | 136 | } else { |
137 | | - $template = wfMsgNoTrans("rss-item"); |
| 137 | + $template = wfMsgNoTrans( 'rss-item' ); |
138 | 138 | } |
139 | 139 | |
140 | 140 | $headcnt = 0; |
— | — | @@ -160,43 +160,48 @@ |
161 | 161 | |
162 | 162 | $output = ''; |
163 | 163 | |
164 | | - /* This would be better served by preg_replace_callback, but |
| 164 | + /** |
| 165 | + * This would be better served by preg_replace_callback, but |
165 | 166 | * I can't create a callback that carries $item in PHP < 5.3 |
166 | 167 | */ |
167 | 168 | if ( $template ) { |
168 | 169 | $headcnt = 0; |
169 | 170 | foreach( $rss->items as $item ) { |
170 | | - if($maxheads > 0 && $headcnt >= $maxheads) continue; |
| 171 | + if( $maxheads > 0 && $headcnt >= $maxheads ) { |
| 172 | + continue; |
| 173 | + } |
171 | 174 | |
172 | 175 | $decision = true; |
173 | | - foreach(array('title', 'author', 'description', 'category') as $check) { |
| 176 | + foreach( array( 'title', 'author', 'description', 'category' ) as $check ) { |
174 | 177 | 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 | + } |
177 | 182 | |
178 | 183 | $item[$check] = wfRssHighlight( $item[$check], $rssHighlight ); |
179 | 184 | } |
180 | 185 | |
181 | 186 | } |
182 | 187 | |
183 | | - $rssTemp = ""; |
| 188 | + $rssTemp = ''; |
184 | 189 | |
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] ); |
189 | 194 | |
190 | 195 | if( isset( $item[$left] ) ) { |
191 | 196 | $right = $item[$left]; |
192 | 197 | } |
193 | 198 | |
194 | | - $rssTemp .= implode( " = ", array($left, $right) ); |
| 199 | + $rssTemp .= implode( ' = ', array( $left, $right ) ); |
195 | 200 | } else { |
196 | 201 | $rssTemp .= $bit; |
197 | 202 | } |
198 | | - $rssTemp .= "|"; |
| 203 | + $rssTemp .= '|'; |
199 | 204 | } |
200 | | - $rssTemp .= "}}"; |
| 205 | + $rssTemp .= '}}'; |
201 | 206 | |
202 | 207 | $output .= $parser->recursiveTagParse( $rssTemp, $frame ); |
203 | 208 | $headcnt++; |