r88457 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88456‎ | r88457 | r88458 >
Date:15:44, 20 May 2011
Author:ashley
Status:ok
Tags:
Comment:
GoogleNewsSitemap: coding style tweaks
Modified paths:
  • /trunk/extensions/GoogleNewsSitemap/FeedSMItem.php (modified) (history)
  • /trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php (modified) (history)
  • /trunk/extensions/GoogleNewsSitemap/SitemapFeed.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php
@@ -2,14 +2,14 @@
33 if ( !defined( 'MEDIAWIKI' ) ) die();
44
55 /**
6 - * Class googlenewssitemap creates Atom/RSS feeds for Wikinews
7 - **
 6+ * Class GoogleNewsSitemap creates Atom/RSS feeds for Wikinews
 7+ *
88 * Simple feed using Atom/RSS coupled to DynamicPageList category searching.
99 *
1010 * To use: http://wiki.url/Special:GoogleNewsSitemap?[paramter=value][&parameter2=value]&...
1111 *
1212 * Implemented parameters are marked with an @
13 - **
 13+ *
1414 * Parameters
1515 * * categories = string ; default = Published
1616 * * notcategories = string ; default = null
@@ -22,7 +22,7 @@
2323 * * stablepages = string ; default = only
2424 * * qualitypages = string ; default = include
2525 * * feed = string ; default = sitemap
26 - **/
 26+ */
2727
2828 class GoogleNewsSitemap extends SpecialPage {
2929
@@ -34,14 +34,14 @@
3535
3636 /**
3737 * Constructor
38 - **/
 38+ */
3939 public function __construct() {
4040 parent::__construct( 'GoogleNewsSitemap' );
4141 }
4242
4343 /**
4444 * main()
45 - **/
 45+ */
4646 public function execute( $par ) {
4747 global $wgContLang, $wgFeedClasses,
4848 $wgLanguageCode, $wgMemc, $wgOut, $wgGNSMsmaxage;
@@ -50,7 +50,7 @@
5151
5252 // if there's an error parsing the params, bail out and return
5353 if ( isset( $params['error'] ) ) {
54 - wfHttpError( 500, "Internal Server Error", $params['error'] );
 54+ wfHttpError( 500, 'Internal Server Error', $params['error'] );
5555 return;
5656 }
5757
@@ -63,8 +63,8 @@
6464 $wgContLang->uc( $params['feed'] ),
6565 $wgLanguageCode
6666 ),
67 - wfMsgExt( 'tagline', array( 'parsemag', 'content') ),
68 - Title::newMainPage()->getFullUrl()
 67+ wfMsgExt( 'tagline', array( 'parsemag', 'content' ) ),
 68+ Title::newMainPage()->getFullURL()
6969 );
7070 } else {
7171 // FeedUtils outputs an error if wrong feed type.
@@ -108,13 +108,13 @@
109109 */
110110 private function getCacheKey( $params, $categories, $notCategories ) {
111111 global $wgRenderHashAppend;
112 - // Note, the implode relies on Title::__toString, which needs php > 5.2
 112+ // Note, the implode relies on Title::__toString, which needs PHP > 5.2
113113 // Which I think is above the minimum we support.
114114 $sum = md5( serialize( $params )
115 - . implode( "|", $categories ) . "||"
116 - . implode( "|", $notCategories )
 115+ . implode( '|', $categories ) . '||'
 116+ . implode( '|', $notCategories )
117117 );
118 - return wfMemcKey( "GNSM", $sum, $wgRenderHashAppend );
 118+ return wfMemcKey( 'GNSM', $sum, $wgRenderHashAppend );
119119 }
120120
121121 /**
@@ -163,7 +163,7 @@
164164 return;
165165 }
166166
167 - // Fixme: Under what circumstance would cl_timestamp not be set?
 167+ // @todo FIXME: Under what circumstance would cl_timestamp not be set?
168168 // possibly worth an exception if that happens.
169169 $pubDate = isset( $row->cl_timestamp ) ? $row->cl_timestamp : wfTimestampNow();
170170
@@ -196,7 +196,7 @@
197197 *
198198 * @return String All the above info concatenated.
199199 */
200 - private function getCacheInvalidationInfo ( $params, $categories, $notCategories ) {
 200+ private function getCacheInvalidationInfo( $params, $categories, $notCategories ) {
201201 wfProfileIn( __METHOD__ );
202202 $dbr = wfGetDB( DB_SLAVE );
203203 $cacheInfo = '';
@@ -212,7 +212,7 @@
213213 $categoriesKey[] = $key;
214214 $tsQueries[] = $dbr->selectSQLText(
215215 'categorylinks',
216 - 'MAX(cl_timestamp) as ts',
 216+ 'MAX(cl_timestamp) AS ts',
217217 array( 'cl_to' => $key ),
218218 __METHOD__
219219 );
@@ -245,11 +245,11 @@
246246 // Part 2: cl_timestamp:
247247 // TODO: Double check that the order of the result of union queries
248248 // is one after another from the order you specified the queries in.
249 - $res2 = $dbr->query($dbr->unionQueries( $tsQueries, true ), __METHOD__);
 249+ $res2 = $dbr->query( $dbr->unionQueries( $tsQueries, true ), __METHOD__ );
250250
251251 foreach ( $res2 as $row ) {
252 - if ( is_null($row->ts) ) {
253 - $ts = "empty";
 252+ if ( is_null( $row->ts ) ) {
 253+ $ts = 'empty';
254254 } else {
255255 $ts = wfTimestamp( TS_MW, $row->ts );
256256 }
@@ -280,7 +280,7 @@
281281 $conditions['page_namespace'] = $params['namespace'];
282282 }
283283
284 - wfRunHooks('GoogleNewsSitemap::Query', array($params, &$joins, &$conditions, &$tables));
 284+ wfRunHooks( 'GoogleNewsSitemap::Query', array( $params, &$joins, &$conditions, &$tables ) );
285285
286286 switch ( $params['redirects'] ) {
287287 case self::OPT_ONLY:
@@ -354,7 +354,7 @@
355355 * Parse parameters, populates $params
356356 * @return Array containing the $params, $categories and $notCategories
357357 * variables that make up the request.
358 - **/
 358+ */
359359 public function getParams() {
360360 global $wgRequest, $wgGNSMmaxCategories,
361361 $wgGNSMmaxResultCount, $wgGNSMfallbackCategory;
@@ -415,7 +415,7 @@
416416 * @param $default Integer Class constant to return if none match
417417 * @return Integer Class constant corresponding to value.
418418 */
419 - private function getIEOVal ( $valName, $default = self::OPT_INCLUDE ) {
 419+ private function getIEOVal( $valName, $default = self::OPT_INCLUDE ) {
420420 global $wgRequest;
421421 $val = $wgRequest->getVal( $valName );
422422 switch ( $val ) {
@@ -429,12 +429,13 @@
430430 return $default;
431431 }
432432 }
 433+
433434 /**
434 - * Decode the namespace url parameter.
435 - * @param $ns String Either numeric ns number, ns name, or special value :all:
436 - * @return Mixed Integer or false Namespace number or false for no ns filtering.
 435+ * Decode the namespace URL parameter.
 436+ * @param $ns String Either numeric NS number, NS name, or special value :all:
 437+ * @return Mixed Integer or false Namespace number or false for no NS filtering.
437438 */
438 - private function getNS ( $ns ) {
 439+ private function getNS( $ns ) {
439440 global $wgContLang;
440441
441442 $nsNumb = $wgContLang->getNsIndex( $ns );
@@ -442,7 +443,7 @@
443444 if ( $nsNumb !== false ) {
444445 // If they specified something like Talk or Image.
445446 return $nsNumb;
446 - } else if ( is_numeric( $ns ) ) {
 447+ } elseif ( is_numeric( $ns ) ) {
447448 // If they specified a number.
448449 $nsVal = intval( $ns );
449450 if ( $nsVal >= 0 && MWNamespace::exists( $nsVal ) ) {
@@ -451,7 +452,7 @@
452453 wfDebug( __METHOD__ . ' Invalid numeric ns number. Using main.' );
453454 return 0;
454455 }
455 - } else if ( $ns === ':all:' ) {
 456+ } elseif ( $ns === ':all:' ) {
456457 // Need someway to denote no namespace filtering,
457458 // This seems as good as any since a namespace can't
458459 // have colons in it.
@@ -478,7 +479,7 @@
479480 global $wgRequest;
480481
481482 $value = $wgRequest->getText( $name, $default );
482 - $arr = explode( "|", $value, $max + 2 );
 483+ $arr = explode( '|', $value, $max + 2 );
483484 $res = array();
484485 foreach ( $arr as $name ) {
485486 $catTitle = Title::newFromText( $name, NS_CATEGORY );
@@ -500,7 +501,7 @@
501502 * @param Title $title
502503 * @return Array of String: list of keywords
503504 */
504 - public function getKeywords ( $title ) {
 505+ public function getKeywords( $title ) {
505506 wfProfileIn( __METHOD__ );
506507 $cats = $title->getParentCategories();
507508 $res = array();
Index: trunk/extensions/GoogleNewsSitemap/FeedSMItem.php
@@ -3,9 +3,9 @@
44
55 /**
66 * FeedSMItem Class
7 - **
 7+ *
88 * Base class for basic SiteMap support, for building url containers.
9 - **/
 9+ */
1010 class FeedSMItem extends FeedItem {
1111
1212 private $keywords = array();
@@ -25,17 +25,16 @@
2626 * An integer for the page name of $title in the specific namespace denoted by that integer.
2727 */
2828 public function __construct( $title, $pubDate, $keywords = '', $comment = true ) {
29 -
3029 if ( !$title ) {
3130 // Paranoia
32 - throw new MWException( "Invalid title object passed to FeedSMItem" );
 31+ throw new MWException( 'Invalid title object passed to FeedSMItem' );
3332 }
3433
3534 $commentsURL = '';
3635 if ( $comment === true ) {
3736 // The comment ns is this article's talk namespace.
3837 $commentsURL = $title->getTalkPage()->getFullUrl();
39 - } else if ( is_int( $comment ) ) {
 38+ } elseif ( is_int( $comment ) ) {
4039 // There's a specific comments namespace.
4140 $commentsTitle = Title::makeTitle( $comment, $title->getDBkey() );
4241 if ( $commentsTitle ) {
@@ -47,7 +46,7 @@
4847 $this->keywords = $keywords;
4948
5049 parent::__construct( $title->getText(), '' /* Description */,
51 - $title->getFullUrl(), $pubDate, '' /* Author */, $commentsURL );
 50+ $title->getFullURL(), $pubDate, '' /* Author */, $commentsURL );
5251 }
5352
5453 /**
@@ -56,12 +55,12 @@
5756 * @param FeedItem Original item.
5857 * @return FeedSMItem Converted item.
5958 */
60 - static public function newFromFeedItem( FeedItem $item ) {
61 - // FIXME: This is borked (esp. on history), but better than a fatal (not by much).
 59+ public static function newFromFeedItem( FeedItem $item ) {
 60+ // @todo FIXME: This is borked (esp. on history), but better than a fatal (not by much).
6261 // maybe try and get title from url?
6362 $title = Title::newFromText( $item->getTitle() );
6463 if ( !$title ) {
65 - throw new MWException( "Error getting title object from string in FeedItem." );
 64+ throw new MWException( 'Error getting title object from string in FeedItem.' );
6665 }
6766 $date = $item->getDate();
6867 return new FeedSMItem( $title, $date );
Index: trunk/extensions/GoogleNewsSitemap/SitemapFeed.php
@@ -16,7 +16,7 @@
1717
1818 /**
1919 * Set the publication language code. Only used if different from
20 - * $wgLanguageCode, which could happen if google disagrees with us
 20+ * $wgLanguageCode, which could happen if Google disagrees with us
2121 * on say what code zh gets.
2222 * @param String $lang Language code (like en)
2323 */
@@ -46,10 +46,10 @@
4747
4848 $this->writer->openURI( 'php://output' );
4949 $this->writer->setIndent( true );
50 - $this->writer->startDocument( "1.0", "UTF-8" );
51 - $this->writer->startElement( "urlset" );
52 - $this->writer->writeAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
53 - $this->writer->writeAttribute( "xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9" );
 50+ $this->writer->startDocument( '1.0', 'UTF-8' );
 51+ $this->writer->startElement( 'urlset' );
 52+ $this->writer->writeAttribute( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' );
 53+ $this->writer->writeAttribute( 'xmlns:news', 'http://www.google.com/schemas/sitemap-news/0.9' );
5454 }
5555
5656 /**
@@ -57,9 +57,8 @@
5858 * @param FeedSMItem $item to be output
5959 */
6060 public function outItem( $item ) {
61 -
6261 if ( !( $item instanceof FeedItem ) ) {
63 - throw new MWException( "Requires a FeedItem or subclass." );
 62+ throw new MWException( 'Requires a FeedItem or subclass.' );
6463 }
6564
6665 wfProfileIn( __METHOD__ );
@@ -67,40 +66,40 @@
6867 $item = FeedSMItem::newFromFeedItem( $item );
6968 }
7069
71 - $this->writer->startElement( "url" );
 70+ $this->writer->startElement( 'url' );
7271
73 - $this->writer->startElement( "loc" );
 72+ $this->writer->startElement( 'loc' );
7473 $this->writer->text( $item->getUrl() );
7574 $this->writer->endElement();
7675
77 - $this->writer->startElement( "news:news" );
 76+ $this->writer->startElement( 'news:news' );
7877
79 - $this->writer->startElement( "news:publication_date" );
 78+ $this->writer->startElement( 'news:publication_date' );
8079 $this->writer->text( wfTimestamp( TS_ISO_8601, $item->getDate() ) );
8180 $this->writer->endElement();
8281
83 - $this->writer->startElement( "news:title" );
 82+ $this->writer->startElement( 'news:title' );
8483 $this->writer->text( $item->getTitle() );
8584 $this->writer->endElement();
8685
87 - $this->writer->startElement( "news:publication" );
88 - $this->writer->startElement( "news:name" );
 86+ $this->writer->startElement( 'news:publication' );
 87+ $this->writer->startElement( 'news:name' );
8988 $this->writer->text( $this->publicationName );
9089 $this->writer->endElement();
91 - $this->writer->startElement( "news:language" );
 90+ $this->writer->startElement( 'news:language' );
9291 $this->writer->text( $this->publicationLang );
9392 $this->writer->endElement();
9493 $this->writer->endElement();
9594
9695 if ( $item->getKeywords() ) {
97 - $this->writer->startElement( "news:keywords" );
 96+ $this->writer->startElement( 'news:keywords' );
9897 $this->writer->text( $item->getKeywords() );
9998 $this->writer->endElement();
10099 }
101100
102101 $this->writer->endElement(); // end news:news
103102 if ( $item->getLastMod() ) {
104 - $this->writer->startElement( "lastmod" );
 103+ $this->writer->startElement( 'lastmod' );
105104 $this->writer->text( wfTimestamp( TS_ISO_8601, $item->getLastMod() ) );
106105 $this->writer->endElement();
107106 }

Status & tagging log