http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88457

Revision: 88457
Author:   ashley
Date:     2011-05-20 15:44:24 +0000 (Fri, 20 May 2011)
Log Message:
-----------
GoogleNewsSitemap: coding style tweaks

Modified Paths:
--------------
    trunk/extensions/GoogleNewsSitemap/FeedSMItem.php
    trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php
    trunk/extensions/GoogleNewsSitemap/SitemapFeed.php

Modified: trunk/extensions/GoogleNewsSitemap/FeedSMItem.php
===================================================================
--- trunk/extensions/GoogleNewsSitemap/FeedSMItem.php   2011-05-20 15:38:29 UTC 
(rev 88456)
+++ trunk/extensions/GoogleNewsSitemap/FeedSMItem.php   2011-05-20 15:44:24 UTC 
(rev 88457)
@@ -3,9 +3,9 @@
 
 /**
  * FeedSMItem Class
- **
+ *
  * Base class for basic SiteMap support, for building url containers.
- **/
+ */
 class FeedSMItem extends FeedItem {
 
        private $keywords = array();
@@ -25,17 +25,16 @@
         *   An integer for the page name of $title in the specific namespace 
denoted by that integer.
         */
        public function __construct( $title, $pubDate, $keywords = '', $comment 
= true ) {
-
                if ( !$title ) {
                        // Paranoia
-                       throw new MWException( "Invalid title object passed to 
FeedSMItem" );
+                       throw new MWException( 'Invalid title object passed to 
FeedSMItem' );
                }
 
                $commentsURL = '';
                if ( $comment === true ) {
                        // The comment ns is this article's talk namespace.
                        $commentsURL = $title->getTalkPage()->getFullUrl();
-               } else if ( is_int( $comment ) ) {
+               } elseif ( is_int( $comment ) ) {
                        // There's a specific comments namespace.
                        $commentsTitle = Title::makeTitle( $comment, 
$title->getDBkey() );
                        if ( $commentsTitle ) {
@@ -47,7 +46,7 @@
                $this->keywords = $keywords;
 
                parent::__construct( $title->getText(), '' /* Description */,
-                       $title->getFullUrl(), $pubDate, '' /* Author */, 
$commentsURL  );
+                       $title->getFullURL(), $pubDate, '' /* Author */, 
$commentsURL  );
        }
 
        /**
@@ -56,12 +55,12 @@
         * @param FeedItem Original item.
         * @return FeedSMItem Converted item.
         */
-       static public function newFromFeedItem( FeedItem $item ) {
-               // FIXME: This is borked (esp. on history), but better than a 
fatal (not by much).
+       public static function newFromFeedItem( FeedItem $item ) {
+               // @todo FIXME: This is borked (esp. on history), but better 
than a fatal (not by much).
                // maybe try and get title from url?
                $title = Title::newFromText( $item->getTitle() );
                if ( !$title ) {
-                       throw new MWException( "Error getting title object from 
string in FeedItem." );
+                       throw new MWException( 'Error getting title object from 
string in FeedItem.' );
                }
                $date = $item->getDate();
                return new FeedSMItem( $title, $date );

Modified: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php
===================================================================
--- trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php       
2011-05-20 15:38:29 UTC (rev 88456)
+++ trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php       
2011-05-20 15:44:24 UTC (rev 88457)
@@ -2,14 +2,14 @@
 if ( !defined( 'MEDIAWIKI' ) ) die();
 
 /**
- * Class googlenewssitemap creates Atom/RSS feeds for Wikinews
- **
+ * Class GoogleNewsSitemap creates Atom/RSS feeds for Wikinews
+ *
  * Simple feed using Atom/RSS coupled to DynamicPageList category searching.
  *
  * To use: 
http://wiki.url/Special:GoogleNewsSitemap?[paramter=value][&parameter2=value]&;...
  *
  * Implemented parameters are marked with an @
- **
+ *
  * Parameters
  *       * categories = string ; default = Published
  *       * notcategories = string ; default = null
@@ -22,7 +22,7 @@
  *       * stablepages = string ; default = only
  *       * qualitypages = string ; default = include
  *       * feed = string ; default = sitemap
- **/
+ */
 
 class GoogleNewsSitemap extends SpecialPage {
 
@@ -34,14 +34,14 @@
 
        /**
         * Constructor
-        **/
+        */
        public function __construct() {
                parent::__construct( 'GoogleNewsSitemap' );
        }
 
        /**
         * main()
-        **/
+        */
        public function execute( $par ) {
                global $wgContLang, $wgFeedClasses,
                        $wgLanguageCode, $wgMemc, $wgOut, $wgGNSMsmaxage;
@@ -50,7 +50,7 @@
 
                // if there's an error parsing the params, bail out and return
                if ( isset( $params['error'] ) ) {
-                       wfHttpError( 500, "Internal Server Error", 
$params['error'] );
+                       wfHttpError( 500, 'Internal Server Error', 
$params['error'] );
                        return;
                }
 
@@ -63,8 +63,8 @@
                                        $wgContLang->uc( $params['feed'] ),
                                        $wgLanguageCode
                                ),
-                               wfMsgExt( 'tagline', array( 'parsemag', 
'content') ),
-                               Title::newMainPage()->getFullUrl()
+                               wfMsgExt( 'tagline', array( 'parsemag', 
'content' ) ),
+                               Title::newMainPage()->getFullURL()
                        );
                } else {
                        // FeedUtils outputs an error if wrong feed type.
@@ -108,13 +108,13 @@
         */
        private function getCacheKey( $params, $categories, $notCategories ) {
                global $wgRenderHashAppend;
-               // Note, the implode relies on Title::__toString, which needs 
php > 5.2
+               // Note, the implode relies on Title::__toString, which needs 
PHP > 5.2
                // Which I think is above the minimum we support.
                $sum = md5( serialize( $params )
-                       . implode( "|", $categories ) . "||"
-                       . implode( "|", $notCategories )
+                       . implode( '|', $categories ) . '||'
+                       . implode( '|', $notCategories )
                );
-               return wfMemcKey( "GNSM", $sum, $wgRenderHashAppend );
+               return wfMemcKey( 'GNSM', $sum, $wgRenderHashAppend );
        }
 
        /**
@@ -163,7 +163,7 @@
                                return;
                        }
 
-                       // Fixme: Under what circumstance would cl_timestamp 
not be set?
+                       // @todo FIXME: Under what circumstance would 
cl_timestamp not be set?
                        // possibly worth an exception if that happens.
                        $pubDate = isset( $row->cl_timestamp ) ? 
$row->cl_timestamp : wfTimestampNow();
 
@@ -196,7 +196,7 @@
         *
         * @return String All the above info concatenated.
         */
-       private function getCacheInvalidationInfo ( $params, $categories, 
$notCategories ) {
+       private function getCacheInvalidationInfo( $params, $categories, 
$notCategories ) {
                wfProfileIn( __METHOD__ );
                $dbr = wfGetDB( DB_SLAVE );
                $cacheInfo = '';
@@ -212,7 +212,7 @@
                        $categoriesKey[] = $key;
                        $tsQueries[] = $dbr->selectSQLText(
                                'categorylinks',
-                               'MAX(cl_timestamp) as ts',
+                               'MAX(cl_timestamp) AS ts',
                                array( 'cl_to' => $key ),
                                __METHOD__
                        );
@@ -245,11 +245,11 @@
                // Part 2: cl_timestamp:
                // TODO: Double check that the order of the result of union 
queries
                // is one after another from the order you specified the 
queries in.
-               $res2 = $dbr->query($dbr->unionQueries( $tsQueries, true ), 
__METHOD__);
+               $res2 = $dbr->query( $dbr->unionQueries( $tsQueries, true ), 
__METHOD__ );
 
                foreach ( $res2 as $row ) {
-                       if ( is_null($row->ts) ) {
-                               $ts = "empty";
+                       if ( is_null( $row->ts ) ) {
+                               $ts = 'empty';
                        } else {
                                $ts = wfTimestamp( TS_MW, $row->ts );
                        }
@@ -280,7 +280,7 @@
                        $conditions['page_namespace'] = $params['namespace'];
                }
 
-               wfRunHooks('GoogleNewsSitemap::Query', array($params, &$joins, 
&$conditions, &$tables));
+               wfRunHooks( 'GoogleNewsSitemap::Query', array( $params, 
&$joins, &$conditions, &$tables ) );
 
                switch ( $params['redirects'] ) {
                        case self::OPT_ONLY:
@@ -354,7 +354,7 @@
         * Parse parameters, populates $params
         * @return Array containing the $params, $categories and $notCategories
         *   variables that make up the request.
-        **/
+        */
        public function getParams() {
                global $wgRequest, $wgGNSMmaxCategories,
                        $wgGNSMmaxResultCount, $wgGNSMfallbackCategory;
@@ -415,7 +415,7 @@
         * @param $default Integer Class constant to return if none match
         * @return Integer Class constant corresponding to value.
         */
-       private function getIEOVal ( $valName, $default = self::OPT_INCLUDE ) {
+       private function getIEOVal( $valName, $default = self::OPT_INCLUDE ) {
                global $wgRequest;
                $val = $wgRequest->getVal( $valName );
                switch ( $val ) {
@@ -429,12 +429,13 @@
                                return $default;
                }
        }
+
        /**
-        * Decode the namespace url parameter.
-        * @param $ns String Either numeric ns number, ns name, or special 
value :all:
-        * @return Mixed Integer or false Namespace number or false for no ns 
filtering.
+        * Decode the namespace URL parameter.
+        * @param $ns String Either numeric NS number, NS name, or special 
value :all:
+        * @return Mixed Integer or false Namespace number or false for no NS 
filtering.
         */
-       private function getNS ( $ns ) {
+       private function getNS( $ns ) {
                global $wgContLang;
 
                $nsNumb = $wgContLang->getNsIndex( $ns );
@@ -442,7 +443,7 @@
                if ( $nsNumb !== false ) {
                        // If they specified something like Talk or Image.
                        return $nsNumb;
-               } else if ( is_numeric( $ns ) ) {
+               } elseif ( is_numeric( $ns ) ) {
                        // If they specified a number.
                        $nsVal = intval( $ns );
                        if ( $nsVal >= 0 && MWNamespace::exists( $nsVal ) ) {
@@ -451,7 +452,7 @@
                                wfDebug( __METHOD__ . ' Invalid numeric ns 
number. Using main.' );
                                return 0;
                        }
-               } else if ( $ns === ':all:' ) {
+               } elseif ( $ns === ':all:' ) {
                        // Need someway to denote no namespace filtering,
                        // This seems as good as any since a namespace can't
                        // have colons in it.
@@ -478,7 +479,7 @@
                global $wgRequest;
 
                $value = $wgRequest->getText( $name, $default );
-               $arr = explode( "|", $value, $max + 2 );
+               $arr = explode( '|', $value, $max + 2 );
                $res = array();
                foreach ( $arr as $name ) {
                        $catTitle = Title::newFromText( $name, NS_CATEGORY );
@@ -500,7 +501,7 @@
         * @param Title $title
         * @return Array of String: list of keywords
         */
-       public function getKeywords ( $title ) {
+       public function getKeywords( $title ) {
                wfProfileIn( __METHOD__ );
                $cats = $title->getParentCategories();
                $res = array();

Modified: trunk/extensions/GoogleNewsSitemap/SitemapFeed.php
===================================================================
--- trunk/extensions/GoogleNewsSitemap/SitemapFeed.php  2011-05-20 15:38:29 UTC 
(rev 88456)
+++ trunk/extensions/GoogleNewsSitemap/SitemapFeed.php  2011-05-20 15:44:24 UTC 
(rev 88457)
@@ -16,7 +16,7 @@
 
        /**
         * Set the publication language code. Only used if different from
-        * $wgLanguageCode, which could happen if google disagrees with us
+        * $wgLanguageCode, which could happen if Google disagrees with us
         * on say what code zh gets.
         * @param String $lang Language code (like en)
         */
@@ -46,10 +46,10 @@
 
                $this->writer->openURI( 'php://output' );
                $this->writer->setIndent( true );
-               $this->writer->startDocument( "1.0", "UTF-8" );
-               $this->writer->startElement( "urlset" );
-               $this->writer->writeAttribute( "xmlns", 
"http://www.sitemaps.org/schemas/sitemap/0.9"; );
-               $this->writer->writeAttribute( "xmlns:news", 
"http://www.google.com/schemas/sitemap-news/0.9"; );
+               $this->writer->startDocument( '1.0', 'UTF-8' );
+               $this->writer->startElement( 'urlset' );
+               $this->writer->writeAttribute( 'xmlns', 
'http://www.sitemaps.org/schemas/sitemap/0.9' );
+               $this->writer->writeAttribute( 'xmlns:news', 
'http://www.google.com/schemas/sitemap-news/0.9' );
        }
 
        /**
@@ -57,9 +57,8 @@
         * @param FeedSMItem $item to be output
         */
        public function outItem( $item ) {
-
                if ( !( $item instanceof FeedItem ) ) {
-                       throw new MWException( "Requires a FeedItem or 
subclass." );
+                       throw new MWException( 'Requires a FeedItem or 
subclass.' );
                }
 
                wfProfileIn( __METHOD__ );
@@ -67,40 +66,40 @@
                        $item = FeedSMItem::newFromFeedItem( $item );
                }
 
-               $this->writer->startElement( "url" );
+               $this->writer->startElement( 'url' );
 
-               $this->writer->startElement( "loc" );
+               $this->writer->startElement( 'loc' );
                $this->writer->text( $item->getUrl() );
                $this->writer->endElement();
 
-               $this->writer->startElement( "news:news"; );
+               $this->writer->startElement( 'news:news' );
 
-               $this->writer->startElement( "news:publication_date"; );
+               $this->writer->startElement( 'news:publication_date' );
                $this->writer->text( wfTimestamp( TS_ISO_8601, $item->getDate() 
) );
                $this->writer->endElement();
 
-               $this->writer->startElement( "news:title"; );
+               $this->writer->startElement( 'news:title' );
                $this->writer->text( $item->getTitle() );
                $this->writer->endElement();
 
-               $this->writer->startElement( "news:publication"; );
-               $this->writer->startElement( "news:name"; );
+               $this->writer->startElement( 'news:publication' );
+               $this->writer->startElement( 'news:name' );
                $this->writer->text( $this->publicationName );
                $this->writer->endElement();
-               $this->writer->startElement( "news:language"; );
+               $this->writer->startElement( 'news:language' );
                $this->writer->text( $this->publicationLang );
                $this->writer->endElement();
                $this->writer->endElement();
 
                if ( $item->getKeywords() ) {
-                       $this->writer->startElement( "news:keywords"; );
+                       $this->writer->startElement( 'news:keywords' );
                        $this->writer->text( $item->getKeywords() );
                        $this->writer->endElement();
                }
 
                $this->writer->endElement(); // end news:news
                if ( $item->getLastMod() ) {
-                       $this->writer->startElement( "lastmod" );
+                       $this->writer->startElement( 'lastmod' );
                        $this->writer->text( wfTimestamp( TS_ISO_8601, 
$item->getLastMod() ) );
                        $this->writer->endElement();
                }


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to