Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -if (!defined('MEDIAWIKI')) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Class GNSM creates Atom/RSS feeds for Wikinews |
— | — | @@ -51,21 +51,21 @@ |
52 | 52 | var $wgDPLallowUnlimitedResults = true; // Allow unlimited results |
53 | 53 | var $wgDPLallowUnlimitedCategories = false; // Allow unlimited categories |
54 | 54 | |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * @var array Parameters array |
58 | 58 | **/ |
59 | 59 | var $params = array(); |
60 | 60 | var $categories = array(); |
61 | 61 | var $notCategories = array(); |
62 | | - |
| 62 | + |
63 | 63 | /** |
64 | 64 | * Constructor |
65 | 65 | **/ |
66 | 66 | public function __construct() { |
67 | 67 | parent::__construct( 'GoogleNewsSitemap' ); |
68 | 68 | } |
69 | | - |
| 69 | + |
70 | 70 | /** |
71 | 71 | * main() |
72 | 72 | **/ |
— | — | @@ -78,39 +78,39 @@ |
79 | 79 | // global $wfTimeStamp; |
80 | 80 | wfLoadExtensionMessages( 'GoogleNewsSitemap' ); |
81 | 81 | global $wgFeedClasses, $wgLocaltimezone; |
82 | | - |
| 82 | + |
83 | 83 | // Not sure how clean $wgLocaltimezone is |
84 | 84 | // In fact, it's default setting is null... |
85 | 85 | if ( null == $wgLocaltimezone ) |
86 | 86 | $wgLocaltimezone = date_default_timezone_get(); |
87 | 87 | date_default_timezone_set( $wgLocaltimezone ); |
88 | | - //$url = __FILE__; |
| 88 | + // $url = __FILE__; |
89 | 89 | |
90 | | - $this->unload_params(); //populates this->params as a side effect |
| 90 | + $this->unload_params(); // populates this->params as a side effect |
91 | 91 | |
92 | | - |
| 92 | + |
93 | 93 | $wgFeedClasses[] = array( 'sitemap' => 'SitemapFeed' ); |
94 | | - |
95 | | - if ( 'sitemap' == $this->params['feed'] ){ |
| 94 | + |
| 95 | + if ( 'sitemap' == $this->params['feed'] ) { |
96 | 96 | $feed = new SitemapFeed( |
97 | | - $wgServer.$wgScriptPath, |
| 97 | + $wgServer . $wgScriptPath, |
98 | 98 | date( DATE_ATOM ) |
99 | 99 | ); |
100 | | - }else{ |
| 100 | + } else { |
101 | 101 | // FIXME: These should be configurable at some point |
102 | 102 | $feed = new $wgFeedClasses[ $this->params['feed'] ]( |
103 | 103 | $wgSitename, |
104 | 104 | $wgSitename . ' ' . $this->params['feed'] . ' feed', |
105 | | - $wgServer.$wgScriptPath, |
| 105 | + $wgServer . $wgScriptPath, |
106 | 106 | date( DATE_ATOM ), |
107 | 107 | $wgSitename |
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | 111 | $feed->outHeader(); |
112 | | - |
| 112 | + |
113 | 113 | // main routine to output items |
114 | | - if ( isset( $this->param['error'] ) ){ |
| 114 | + if ( isset( $this->param['error'] ) ) { |
115 | 115 | $wgOut->disable(); |
116 | 116 | echo $this->param['error']; |
117 | 117 | $feed->outFooter(); |
— | — | @@ -119,31 +119,31 @@ |
120 | 120 | |
121 | 121 | $dbr =& wfGetDB( DB_SLAVE ); |
122 | 122 | $sql = $this->dpl_buildSQL(); |
123 | | - //Debug line |
124 | | - //echo "\n<p>$sql</p>\n"; |
| 123 | + // Debug line |
| 124 | + // echo "\n<p>$sql</p>\n"; |
125 | 125 | $res = $dbr->query ( $sql ); |
126 | | - |
| 126 | + |
127 | 127 | // FIXME: figure out how to fail with no results gracefully |
128 | | - if ( $dbr->numRows( $res ) == 0 ){ |
| 128 | + if ( $dbr->numRows( $res ) == 0 ) { |
129 | 129 | $feed->outFooter(); |
130 | | - if ( false == $this->params['suppressErrors'] ) |
| 130 | + if ( false == $this->params['suppressErrors'] ) |
131 | 131 | return htmlspecialchars( wfMsg( 'gnsm_noresults' ) ); |
132 | 132 | else |
133 | 133 | return ''; |
134 | 134 | } |
135 | | - |
136 | | - while ($row = $dbr->fetchObject( $res ) ) { |
137 | | - $title = Title::makeTitle( $row->page_namespace, $row->page_title); |
138 | | - |
139 | | - if ( ! $title ){ |
| 135 | + |
| 136 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 137 | + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 138 | + |
| 139 | + if ( ! $title ) { |
140 | 140 | $feed->outFooter(); |
141 | 141 | return; |
142 | 142 | } |
143 | | - |
| 143 | + |
144 | 144 | $titleText = ( true == $this->params['nameSpace'] ) ? $title->getPrefixedText() : $title->getText(); |
145 | | - |
146 | | - if ( 'sitemap' == $this->params['feed'] ){ |
147 | | - |
| 145 | + |
| 146 | + if ( 'sitemap' == $this->params['feed'] ) { |
| 147 | + |
148 | 148 | $this->pubDate = isset( $row->cl_timestamp ) ? $row->cl_timestamp : date( DATE_ATOM ); |
149 | 149 | $feedArticle = new Article( $title ); |
150 | 150 | |
— | — | @@ -154,53 +154,53 @@ |
155 | 155 | wfTimeStamp( TS_ISO_8601, $feedArticle->getTouched() ), |
156 | 156 | $feed->getPriority( $this->priority ) |
157 | 157 | ); |
158 | | - |
159 | | - }elseif ( ('atom' == $this->params['feed'] ) || ( 'rss' == $this->params['feed'] ) ){ |
160 | | - |
| 158 | + |
| 159 | + } elseif ( ( 'atom' == $this->params['feed'] ) || ( 'rss' == $this->params['feed'] ) ) { |
| 160 | + |
161 | 161 | $this->Date = isset( $row->cl_timestamp ) ? $row->cl_timestamp : date( DATE_ATOM ); |
162 | | - if ( isset( $row->comment ) ){ |
| 162 | + if ( isset( $row->comment ) ) { |
163 | 163 | $comments = htmlspecialchars( $row->comment ); |
164 | | - }else{ |
| 164 | + } else { |
165 | 165 | $talkpage = $title->getTalkPage(); |
166 | 166 | $comments = $talkpage->getFullURL(); |
167 | 167 | } |
168 | | - $titleText = (true === $this->params['nameSpace'] ) ? $title->getPrefixedText() : $title->getText(); |
| 168 | + $titleText = ( true === $this->params['nameSpace'] ) ? $title->getPrefixedText() : $title->getText(); |
169 | 169 | $feedItem = new FeedItem( |
170 | 170 | $titleText, |
171 | 171 | $this->feedItemDesc( $row ), |
172 | 172 | $title->getFullURL(), |
173 | 173 | $this->Date, |
174 | 174 | $this->feedItemAuthor( $row ), |
175 | | - $comments); |
| 175 | + $comments ); |
176 | 176 | } |
177 | 177 | $feed->outItem( $feedItem ); |
178 | | - }//end while fetchobject |
| 178 | + }// end while fetchobject |
179 | 179 | $feed->outFooter(); |
180 | | - } //end public function execute |
181 | | - |
| 180 | + } // end public function execute |
| 181 | + |
182 | 182 | /** |
183 | 183 | * Build sql |
184 | 184 | **/ |
185 | | - public function dpl_buildSQL(){ |
186 | | - |
| 185 | + public function dpl_buildSQL() { |
| 186 | + |
187 | 187 | $sqlSelectFrom = 'SELECT page_namespace, page_title, page_id, c1.cl_timestamp FROM ' . $this->params['dbr']->tableName( 'page' ); |
188 | | - |
189 | | - if ( $this->params['nameSpace'] ){ |
| 188 | + |
| 189 | + if ( $this->params['nameSpace'] ) { |
190 | 190 | $sqlWhere = ' WHERE page_namespace=' . $this->params['nameSpace'] . ' '; |
191 | | - }else{ |
| 191 | + } else { |
192 | 192 | $sqlWhere = ' WHERE 1=1 '; |
193 | 193 | } |
194 | | - |
| 194 | + |
195 | 195 | // If flagged revisions is in use, check which options selected. |
196 | 196 | // FIXME: double check the default options in function::dpl_parm; what should it default to? |
197 | | - if( function_exists('efLoadFlaggedRevs') ) { |
| 197 | + if ( function_exists( 'efLoadFlaggedRevs' ) ) { |
198 | 198 | $flaggedPages = $this->params['dbr']->tableName( 'flaggedpages' ); |
199 | 199 | $filterSet = array( 'only', 'exclude' ); |
200 | 200 | # Either involves the same JOIN here... |
201 | | - if( in_array( $this->params['stable'], $filterSet ) || in_array( $this->params['quality'], $filterSet ) ) { |
| 201 | + if ( in_array( $this->params['stable'], $filterSet ) || in_array( $this->params['quality'], $filterSet ) ) { |
202 | 202 | $sqlSelectFrom .= " LEFT JOIN $flaggedPages ON page_id = fp_page_id"; |
203 | 203 | } |
204 | | - switch( $this->params['stable'] ){ |
| 204 | + switch( $this->params['stable'] ) { |
205 | 205 | case 'only': |
206 | 206 | $sqlWhere .= ' AND fp_stable IS NOT NULL '; |
207 | 207 | break; |
— | — | @@ -208,7 +208,7 @@ |
209 | 209 | $sqlWhere .= ' AND fp_stable IS NULL '; |
210 | 210 | break; |
211 | 211 | } |
212 | | - switch( $this->params['quality'] ){ |
| 212 | + switch( $this->params['quality'] ) { |
213 | 213 | case 'only': |
214 | 214 | $sqlWhere .= ' AND fp_quality >= 1'; |
215 | 215 | break; |
— | — | @@ -217,8 +217,8 @@ |
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
221 | | - |
222 | | - switch ( $this->params['redirects'] ){ |
| 221 | + |
| 222 | + switch ( $this->params['redirects'] ) { |
223 | 223 | case 'only': |
224 | 224 | $sqlWhere .= ' AND page_is_redirect = 1 '; |
225 | 225 | break; |
— | — | @@ -226,61 +226,61 @@ |
227 | 227 | $sqlWhere .= ' AND page_is_redirect = 0 '; |
228 | 228 | break; |
229 | 229 | } |
230 | | - |
| 230 | + |
231 | 231 | $currentTableNumber = 0; |
232 | | - |
233 | | - for ( $i = 0; $i < $this->params['catCount']; $i++ ){ |
| 232 | + |
| 233 | + for ( $i = 0; $i < $this->params['catCount']; $i++ ) { |
234 | 234 | $sqlSelectFrom .= ' INNER JOIN ' . $this->params['dbr']->tableName( 'categorylinks' ); |
235 | 235 | $sqlSelectFrom .= ' AS c' . ( $currentTableNumber + 1 ) . ' ON page_id = c'; |
236 | 236 | $sqlSelectFrom .= ( $currentTableNumber + 1 ) . '.cl_from AND c' . ( $currentTableNumber + 1 ); |
237 | 237 | |
238 | 238 | $sqlSelectFrom .= '.cl_to=' . $this->params['dbr']->addQuotes( $this->categories[$i]->getDBkey() ); |
239 | | - |
| 239 | + |
240 | 240 | $currentTableNumber++; |
241 | 241 | } |
242 | 242 | |
243 | | - for ( $i = 0; $i < $this->params['notCatCount']; $i++ ){ |
244 | | - //echo "notCategory parameter $i<br />\n"; |
| 243 | + for ( $i = 0; $i < $this->params['notCatCount']; $i++ ) { |
| 244 | + // echo "notCategory parameter $i<br />\n"; |
245 | 245 | $sqlSelectFrom .= ' LEFT OUTER JOIN ' . $this->params['dbr']->tableName( 'categorylinks' ); |
246 | 246 | $sqlSelectFrom .= ' AS c' . ( $currentTableNumber + 1 ) . ' ON page_id = c' . ( $currentTableNumber + 1 ); |
247 | 247 | $sqlSelectFrom .= '.cl_from AND c' . ( $currentTableNumber + 1 ); |
248 | 248 | $sqlSelectFrom .= '.cl_to=' . $this->params['dbr']->addQuotes( $this->notCategories[$i]->getDBkey() ); |
249 | | - |
| 249 | + |
250 | 250 | $sqlWhere .= ' AND c' . ( $currentTableNumber + 1 ) . '.cl_to IS NULL'; |
251 | 251 | |
252 | 252 | $currentTableNumber++; |
253 | 253 | } |
254 | | - |
255 | | - if ('lastedit' == $this->params['orderMethod'] ){ |
| 254 | + |
| 255 | + if ( 'lastedit' == $this->params['orderMethod'] ) { |
256 | 256 | $sqlWhere .= ' ORDER BY page_touched '; |
257 | | - }else{ |
| 257 | + } else { |
258 | 258 | $sqlWhere .= ' ORDER BY c1.cl_timestamp '; |
259 | 259 | } |
260 | | - |
261 | | - if ( 'descending' == $this->params['order'] ){ |
| 260 | + |
| 261 | + if ( 'descending' == $this->params['order'] ) { |
262 | 262 | $sqlWhere .= 'DESC'; |
263 | | - }else{ |
| 263 | + } else { |
264 | 264 | $sqlWhere .= 'ASC'; |
265 | 265 | } |
266 | 266 | |
267 | 267 | // FIXME: Note: this is not a boolean type check - will also trap count = 0 which may |
268 | 268 | // accidentally give unlimited returns |
269 | | - if ( 0 < $this->params['count'] ){ |
| 269 | + if ( 0 < $this->params['count'] ) { |
270 | 270 | $sqlWhere .= ' LIMIT ' . $this->params['count']; |
271 | 271 | } |
272 | | - |
273 | | - //debug line |
274 | | - //echo "<p>$sqlSelectFrom$sqlWhere;</p>\n"; |
275 | | - |
| 272 | + |
| 273 | + // debug line |
| 274 | + // echo "<p>$sqlSelectFrom$sqlWhere;</p>\n"; |
| 275 | + |
276 | 276 | return $sqlSelectFrom . $sqlWhere; |
277 | | - } //end buildSQL |
278 | | - |
| 277 | + } // end buildSQL |
| 278 | + |
279 | 279 | /** |
280 | 280 | * Parse parameters |
281 | 281 | ** |
282 | 282 | * FIXME this includes a lot of DynamicPageList cruft in need of thinning. |
283 | 283 | **/ |
284 | | - public function unload_params(){ |
| 284 | + public function unload_params() { |
285 | 285 | global $wgContLang; |
286 | 286 | global $wgRequest; |
287 | 287 | global $wgOut; |
— | — | @@ -288,61 +288,61 @@ |
289 | 289 | |
290 | 290 | $this->params = array(); |
291 | 291 | $parser = new Parser; |
292 | | - $poptions = new ParserOptions; |
293 | | - $category = $wgRequest->getArray('category', 'Published'); |
294 | | - //$title = Title::newFromText( $parser->transformMsg( $category, $poptions ) ); |
295 | | - //if ( is_object( $title ) ){ |
| 292 | + $poptions = new ParserOptions; |
| 293 | + $category = $wgRequest->getArray( 'category', 'Published' ); |
| 294 | + // $title = Title::newFromText( $parser->transformMsg( $category, $poptions ) ); |
| 295 | + // if ( is_object( $title ) ){ |
296 | 296 | // $this->categories[] = $title; |
297 | 297 | // } |
298 | | - //FIXME:notcats |
299 | | - //$this->notCategories[] = $wgRequest->getArray('notcategory'); |
300 | | - $this->params['nameSpace'] = $wgContLang->getNsIndex($wgRequest->getVal('namespace',0)); |
301 | | - $this->params['count'] = $wgRequest->getInt('count', $this->wgDPLmaxResultCount); |
302 | | - if (($this->params['count'] > $this->wgDPLmaxResultCount)||($this->params['count'] < $this->wgDPLminResultCount)) |
| 298 | + // FIXME:notcats |
| 299 | + // $this->notCategories[] = $wgRequest->getArray('notcategory'); |
| 300 | + $this->params['nameSpace'] = $wgContLang->getNsIndex( $wgRequest->getVal( 'namespace', 0 ) ); |
| 301 | + $this->params['count'] = $wgRequest->getInt( 'count', $this->wgDPLmaxResultCount ); |
| 302 | + if ( ( $this->params['count'] > $this->wgDPLmaxResultCount ) || ( $this->params['count'] < $this->wgDPLminResultCount ) ) |
303 | 303 | $this->params['count'] = $this->wgDPLmaxResultCount; |
304 | 304 | |
305 | | - $this->params['order'] = $wgRequest->getVal('order', 'descending'); |
306 | | - $this->params['orderMethod'] = $wgRequest->getVal('ordermethod', 'categoryadd'); |
307 | | - $this->params['redirects'] = $wgRequest->getVal('redirects', 'exclude'); |
308 | | - $this->params['stable'] = $wgRequest->getVal('stable','only'); |
309 | | - $this->params['quality'] = $wgRequest->getVal('qualitypages', 'only'); |
310 | | - $this->params['suppressErrors']=$wgRequest->getBool('supresserrors', false); |
311 | | - $this->params['useNameSpace'] = $wgRequest->getBool('usenamespace', false); |
312 | | - $this->params['useCurId'] = $wgRequest->getBool('usecurid', false); |
313 | | - $this->params['feed'] = $wgRequest->getVal('feed', 'sitemap'); |
| 305 | + $this->params['order'] = $wgRequest->getVal( 'order', 'descending' ); |
| 306 | + $this->params['orderMethod'] = $wgRequest->getVal( 'ordermethod', 'categoryadd' ); |
| 307 | + $this->params['redirects'] = $wgRequest->getVal( 'redirects', 'exclude' ); |
| 308 | + $this->params['stable'] = $wgRequest->getVal( 'stable', 'only' ); |
| 309 | + $this->params['quality'] = $wgRequest->getVal( 'qualitypages', 'only' ); |
| 310 | + $this->params['suppressErrors'] = $wgRequest->getBool( 'supresserrors', false ); |
| 311 | + $this->params['useNameSpace'] = $wgRequest->getBool( 'usenamespace', false ); |
| 312 | + $this->params['useCurId'] = $wgRequest->getBool( 'usecurid', false ); |
| 313 | + $this->params['feed'] = $wgRequest->getVal( 'feed', 'sitemap' ); |
314 | 314 | |
315 | | - |
| 315 | + |
316 | 316 | $this->params['catCount'] = count( $this->categories ); |
317 | 317 | $this->params['notCatCount'] = count( $this->notCategories ); |
318 | 318 | $totalCatCount = $this->params['catCount'] + $this->params['notCatCount']; |
319 | | - if (( $this->params['catCount'] < 1 && false == $this->params['nameSpace'] ) || ( $totalCatCount < $this->wgDPlminCategories )){ |
320 | | - //echo "Boom on catCount\n"; |
| 319 | + if ( ( $this->params['catCount'] < 1 && false == $this->params['nameSpace'] ) || ( $totalCatCount < $this->wgDPlminCategories ) ) { |
| 320 | + // echo "Boom on catCount\n"; |
321 | 321 | $parser = new Parser; |
322 | 322 | $poptions = new ParserOptions; |
323 | 323 | $feed = Title::newFromText( $parser->transformMsg( 'Published', $poptions ) ); |
324 | | - if ( is_object( $feed ) ){ |
| 324 | + if ( is_object( $feed ) ) { |
325 | 325 | $this->categories[] = $feed; |
326 | | - $this->params['catCount'] = count( $this->categories ); |
327 | | - }else{ |
| 326 | + $this->params['catCount'] = count( $this->categories ); |
| 327 | + } else { |
328 | 328 | echo "\$feed is not an object.\n"; |
329 | | - //continue; |
| 329 | + // continue; |
330 | 330 | } |
331 | 331 | } |
332 | | - |
333 | | - if ( ( $totalCatCount > $this->wgDPlmaxCategories ) && ( !$this->wgDPLallowUnlimitedCategories ) ){ |
| 332 | + |
| 333 | + if ( ( $totalCatCount > $this->wgDPlmaxCategories ) && ( !$this->wgDPLallowUnlimitedCategories ) ) { |
334 | 334 | $this->params['error'] = htmlspecialchars( wfMsg( 'intersection_toomanycats' ) ); // "!!too many categories!!"; |
335 | 335 | } |
336 | | - |
337 | | - //disallow showing date if the query doesn't have an inclusion category parameter |
| 336 | + |
| 337 | + // disallow showing date if the query doesn't have an inclusion category parameter |
338 | 338 | if ( $this->params['count'] < 1 ) |
339 | 339 | $this->params['addFirstCategoryDate'] = false; |
340 | | - |
| 340 | + |
341 | 341 | $this->params['dbr'] =& wfGetDB( DB_SLAVE ); |
342 | | - //print_r($this->notCategories); |
343 | | - //print_r($this->categories); |
| 342 | + // print_r($this->notCategories); |
| 343 | + // print_r($this->categories); |
344 | 344 | return; |
345 | 345 | } |
346 | | - |
| 346 | + |
347 | 347 | function feedItemAuthor( $row ) { |
348 | 348 | return isset( $row->user_text ) ? $row->user_text : 'Wikinews'; |
349 | 349 | } |
— | — | @@ -350,38 +350,38 @@ |
351 | 351 | function feedItemDesc( $row ) { |
352 | 352 | return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : ''; |
353 | 353 | } |
354 | | - |
355 | | - function getKeywords ( $title ){ |
| 354 | + |
| 355 | + function getKeywords ( $title ) { |
356 | 356 | $cats = $title->getParentCategories(); |
357 | 357 | $str = ''; |
358 | | - #the following code is based (stolen) from r56954 of flagged revs. |
| 358 | + # the following code is based (stolen) from r56954 of flagged revs. |
359 | 359 | $catMap = Array(); |
360 | 360 | $catMask = Array(); |
361 | 361 | $msg = wfMsg( 'gnsm_categorymap' ); |
362 | 362 | if ( !wfEmptyMsg( 'gnsm_categorymap', $msg ) ) { |
363 | | - $list = explode( "\n*", "\n$msg"); |
364 | | - foreach($list as $item) { |
365 | | - $mapping = explode('|', $item, 2); |
| 363 | + $list = explode( "\n*", "\n$msg" ); |
| 364 | + foreach ( $list as $item ) { |
| 365 | + $mapping = explode( '|', $item, 2 ); |
366 | 366 | if ( count( $mapping ) == 2 ) { |
367 | | - if ( trim( $mapping[1] ) == '__MASK__') { |
368 | | - $catMask[trim($mapping[0])] = true; |
| 367 | + if ( trim( $mapping[1] ) == '__MASK__' ) { |
| 368 | + $catMask[trim( $mapping[0] )] = true; |
369 | 369 | } else { |
370 | | - $catMap[trim($mapping[0])] = trim($mapping[1]); |
| 370 | + $catMap[trim( $mapping[0] )] = trim( $mapping[1] ); |
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
375 | | - foreach ( $cats as $key => $val ){ |
| 375 | + foreach ( $cats as $key => $val ) { |
376 | 376 | $cat = str_replace( '_', ' ', trim( substr( $key, strpos( $key, ':' ) + 1 ) ) ); |
377 | | - if (!isset($catMask[$cat])) { |
378 | | - if (isset($catMap[$cat])) { |
| 377 | + if ( !isset( $catMask[$cat] ) ) { |
| 378 | + if ( isset( $catMap[$cat] ) ) { |
379 | 379 | $str .= ', ' . str_replace( '_', ' ', trim ( $catMap[$cat] ) ); |
380 | 380 | } else { |
381 | 381 | $str .= ', ' . $cat; |
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
385 | | - $str = substr( $str, 2 ); #to remove leading ', ' |
| 385 | + $str = substr( $str, 2 ); # to remove leading ', ' |
386 | 386 | return $str; |
387 | 387 | } |
388 | 388 | |
— | — | @@ -392,7 +392,7 @@ |
393 | 393 | ** |
394 | 394 | * Base class for basic SiteMap support, for building url containers. |
395 | 395 | **/ |
396 | | -class feedSMItem{ |
| 396 | +class feedSMItem { |
397 | 397 | /** |
398 | 398 | * Var string |
399 | 399 | **/ |
— | — | @@ -401,77 +401,77 @@ |
402 | 402 | var $keywords = ''; |
403 | 403 | var $lastMod = ''; |
404 | 404 | var $priority = ''; |
405 | | - |
406 | | - function __construct( $url, $pubDate, $keywords = '', $lastMod = '', $priority = ''){ |
| 405 | + |
| 406 | + function __construct( $url, $pubDate, $keywords = '', $lastMod = '', $priority = '' ) { |
407 | 407 | $this->url = $url; |
408 | 408 | $this->pubDate = $pubDate; |
409 | 409 | $this->keywords = $keywords; |
410 | 410 | $this->lastMod = $lastMod; |
411 | 411 | $this->priority = $priority; |
412 | 412 | } |
413 | | - |
414 | | - public function xmlEncode( $string ){ |
| 413 | + |
| 414 | + public function xmlEncode( $string ) { |
415 | 415 | $string = str_replace( "\r\n", "\n", $string ); |
416 | 416 | $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string ); |
417 | 417 | return htmlspecialchars( $string ); |
418 | 418 | } |
419 | | - |
420 | | - public function getUrl(){ |
| 419 | + |
| 420 | + public function getUrl() { |
421 | 421 | return $this->url; |
422 | 422 | } |
423 | | - |
424 | | - public function getPriority(){ |
| 423 | + |
| 424 | + public function getPriority() { |
425 | 425 | return $this->priority; |
426 | 426 | } |
427 | | - |
428 | | - public function getLastMod(){ |
| 427 | + |
| 428 | + public function getLastMod() { |
429 | 429 | return $this->lastMod; |
430 | 430 | } |
431 | 431 | |
432 | | - public function getKeywords (){ |
| 432 | + public function getKeywords () { |
433 | 433 | return $this->xmlEncode( $this->keywords ); |
434 | 434 | } |
435 | | - |
436 | | - public function getPubDate(){ |
| 435 | + |
| 436 | + public function getPubDate() { |
437 | 437 | return $this->pubDate; |
438 | 438 | } |
439 | | - |
| 439 | + |
440 | 440 | function formatTime( $ts ) { |
441 | 441 | // need to use RFC 822 time format at least for rss2.0 |
442 | 442 | return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) ); |
443 | 443 | } |
444 | | - |
| 444 | + |
445 | 445 | } |
446 | 446 | |
447 | | -class SitemapFeed extends feedSMItem{ |
| 447 | +class SitemapFeed extends feedSMItem { |
448 | 448 | private $writer; |
449 | 449 | |
450 | 450 | |
451 | | - function __construct(){ |
| 451 | + function __construct() { |
452 | 452 | global $wgOut; |
453 | | - $this->writer=new XMLWriter(); |
| 453 | + $this->writer = new XMLWriter(); |
454 | 454 | $wgOut->disable(); |
455 | 455 | } |
456 | 456 | /** |
457 | 457 | * Output feed headers |
458 | 458 | **/ |
459 | | - function outHeader(){ |
| 459 | + function outHeader() { |
460 | 460 | global $wgOut; |
461 | | - global $wgRequest; |
| 461 | + global $wgRequest; |
462 | 462 | |
463 | | - //FIXME: Why can't we just pick one mime type and always send that? |
| 463 | + // FIXME: Why can't we just pick one mime type and always send that? |
464 | 464 | $ctype = $wgRequest->getVal( 'ctype', 'application/xml' ); |
465 | 465 | $allowedctypes = array( 'application/xml', 'text/xml', 'application/rss+xml', 'application/atom+xml' ); |
466 | 466 | $mimetype = in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml'; |
467 | 467 | header( "Content-type: $mimetype; charset=UTF-8" ); |
468 | 468 | $wgOut->sendCacheControl(); |
469 | 469 | |
470 | | - $this->writer->openURI('php://output'); |
471 | | - $this->writer->setIndent(true); |
472 | | - $this->writer->startDocument("1.0", "UTF-8"); |
473 | | - $this->writer->startElement("urlset"); |
474 | | - $this->writer->writeAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); |
475 | | - $this->writer->writeAttribute("xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9"); |
| 470 | + $this->writer->openURI( 'php://output' ); |
| 471 | + $this->writer->setIndent( true ); |
| 472 | + $this->writer->startDocument( "1.0", "UTF-8" ); |
| 473 | + $this->writer->startElement( "urlset" ); |
| 474 | + $this->writer->writeAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" ); |
| 475 | + $this->writer->writeAttribute( "xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9" ); |
476 | 476 | $this->writer->flush(); |
477 | 477 | } |
478 | 478 | /** |
— | — | @@ -480,37 +480,37 @@ |
481 | 481 | **/ |
482 | 482 | function outItem( $item ) { |
483 | 483 | |
484 | | - $this->writer->startElement("url"); |
485 | | - $this->writer->startElement("loc"); |
486 | | - $this->writer->text($item->getUrl()); |
| 484 | + $this->writer->startElement( "url" ); |
| 485 | + $this->writer->startElement( "loc" ); |
| 486 | + $this->writer->text( $item->getUrl() ); |
487 | 487 | $this->writer->endElement(); |
488 | | - $this->writer->startElement("news:news"); |
489 | | - $this->writer->startElement("news:publication_date"); |
490 | | - $this->writer->text($item->getPubDate()); |
| 488 | + $this->writer->startElement( "news:news" ); |
| 489 | + $this->writer->startElement( "news:publication_date" ); |
| 490 | + $this->writer->text( $item->getPubDate() ); |
491 | 491 | $this->writer->endElement(); |
492 | | - if( $item->getKeywords() ){ |
493 | | - $this->writer->startElement("news:keywords"); |
494 | | - $this->writer->text($item->getKeywords()); |
| 492 | + if ( $item->getKeywords() ) { |
| 493 | + $this->writer->startElement( "news:keywords" ); |
| 494 | + $this->writer->text( $item->getKeywords() ); |
495 | 495 | $this->writer->endElement(); |
496 | 496 | } |
497 | | - $this->writer->endElement(); //end news:news |
498 | | - if( $item->getLastMod() ){ |
499 | | - $this->writer->startElement("lastmod"); |
500 | | - $this->writer->text($item->getLastMod()); |
| 497 | + $this->writer->endElement(); // end news:news |
| 498 | + if ( $item->getLastMod() ) { |
| 499 | + $this->writer->startElement( "lastmod" ); |
| 500 | + $this->writer->text( $item->getLastMod() ); |
501 | 501 | $this->writer->endElement(); |
502 | 502 | } |
503 | | - if( $item->getPriority() ){ |
504 | | - $this->writer->startElement("priority"); |
505 | | - $this->writer->text($item->getPriority()); |
| 503 | + if ( $item->getPriority() ) { |
| 504 | + $this->writer->startElement( "priority" ); |
| 505 | + $this->writer->text( $item->getPriority() ); |
506 | 506 | $this->writer->endElement(); |
507 | 507 | } |
508 | | - $this->writer->endElement(); //end url |
| 508 | + $this->writer->endElement(); // end url |
509 | 509 | } |
510 | | - |
| 510 | + |
511 | 511 | /** |
512 | 512 | * Output SiteMap 0.9 footer |
513 | 513 | **/ |
514 | | - function outFooter(){ |
| 514 | + function outFooter() { |
515 | 515 | $this->writer->endDocument(); |
516 | 516 | $this->writer->flush(); |
517 | 517 | } |
Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -if (!defined('MEDIAWIKI')) { |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
4 | 4 | echo <<<EOT |
5 | 5 | To install GoogleNewsSitemap extension, an extension special page, put the following line in LocalSettings.php: |
6 | 6 | require_once( dirname(__FILE__) . '/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php' ); |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | 'url' => 'http://www.mediawiki.org/wiki/Extension:GoogleNewsSitemap', |
64 | 64 | ); |
65 | 65 | |
66 | | -$dir = dirname(__FILE__) . '/'; |
| 66 | +$dir = dirname( __FILE__ ) . '/'; |
67 | 67 | $wgExtensionMessagesFiles['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap.i18n.php'; |
68 | 68 | $wgExtensionAliasesFiles['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap.alias.php'; |
69 | 69 | $wgAutoloadClasses['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap_body.php'; |