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

Revision: 68552
Author:   juliano
Date:     2010-06-25 04:13:56 +0000 (Fri, 25 Jun 2010)

Log Message:
-----------
Wikilog feeds by namespace.

Modified Paths:
--------------
    trunk/extensions/Wikilog/SpecialWikilog.php
    trunk/extensions/Wikilog/Wikilog.i18n.php
    trunk/extensions/Wikilog/WikilogFeed.php
    trunk/extensions/Wikilog/WikilogQuery.php

Modified: trunk/extensions/Wikilog/SpecialWikilog.php
===================================================================
--- trunk/extensions/Wikilog/SpecialWikilog.php 2010-06-25 04:13:36 UTC (rev 
68551)
+++ trunk/extensions/Wikilog/SpecialWikilog.php 2010-06-25 04:13:56 UTC (rev 
68552)
@@ -119,7 +119,7 @@
                global $wgRequest, $wgFeedLimit;
 
                $opts = $this->getDefaultOptions();
-               $opts->fetchValuesFromRequest( $wgRequest, array( 'show', 
'limit' ) );
+               $opts->fetchValuesFromRequest( $wgRequest, array( 'wikilog', 
'show', 'limit' ) );
                $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
                return $opts;
        }
@@ -191,8 +191,8 @@
 
                # Add feed links.
                $wgOut->setSyndicated();
-               if ( isset( $qarr['show'] ) ) {
-                       $altquery = wfArrayToCGI( array_intersect_key( $qarr, 
WikilogItemFeed::$paramWhitelist ) );
+               $altquery = wfArrayToCGI( array_intersect_key( $qarr, 
WikilogItemFeed::$paramWhitelist ) );
+               if ( $altquery ) {
                        $wgOut->setFeedAppendQuery( $altquery );
                }
 
@@ -400,13 +400,20 @@
         * @return Wikilog query object.
         */
        public static function getQuery( $opts ) {
+               global $wgWikilogNamespaces;
+
                $query = new WikilogItemQuery();
                $query->setPubStatus( $opts['show'] );
-               if ( $opts['wikilog'] && ( $t = Title::newFromText( 
$opts['wikilog'] ) ) ) {
-                       if ( $t->getText() == '*' ) {
-                               $query->setNamespace( $t->getNamespace() );
+               if ( $opts['wikilog'] ) {
+                       $t = Title::newFromText( $opts['wikilog'] );
+                       if ( $t && in_array( $t->getNamespace(), 
$wgWikilogNamespaces ) ) {
+                               if ( $t->getText() == '*' ) {
+                                       $query->setNamespace( 
$t->getNamespace() );
+                               } else {
+                                       $query->setWikilogTitle( $t );
+                               }
                        } else {
-                               $query->setWikilogTitle( $t );
+                               $query->setEmpty();
                        }
                }
                if ( ( $t = $opts['category'] ) ) {

Modified: trunk/extensions/Wikilog/Wikilog.i18n.php
===================================================================
--- trunk/extensions/Wikilog/Wikilog.i18n.php   2010-06-25 04:13:36 UTC (rev 
68551)
+++ trunk/extensions/Wikilog/Wikilog.i18n.php   2010-06-25 04:13:56 UTC (rev 
68552)
@@ -119,6 +119,7 @@
 
        # Atom and RSS feeds
        'wikilog-feed-title' => '{{SITENAME}} - $1 [$2]', # $1 = title, $2 = 
content language
+       'wikilog-feed-ns-title' => '$1 wikilog articles', # $1 = namespace name
        'wikilog-feed-description' => 'Read the most recent posts in this 
feed.',
        'wikilog-comment-feed-title1' => 'Comment by $2 (#$1)',
        'wikilog-comment-feed-title2' => 'Comment by $2 to $3 (#$1)',

Modified: trunk/extensions/Wikilog/WikilogFeed.php
===================================================================
--- trunk/extensions/Wikilog/WikilogFeed.php    2010-06-25 04:13:36 UTC (rev 
68551)
+++ trunk/extensions/Wikilog/WikilogFeed.php    2010-06-25 04:13:56 UTC (rev 
68552)
@@ -65,7 +65,7 @@
         * to this list means that feed caching should be revisited. Parameters
         * must be listed as keys.
         */
-       public static $paramWhitelist = array( 'show' => true );
+       public static $paramWhitelist = array( 'wikilog' => true, 'show' => 
true );
 
        /**
         * WikilogFeed constructor.
@@ -362,7 +362,6 @@
                if ( !$limit ) $limit = $wgWikilogNumArticles;
                parent::__construct( $title, $format, $query, $limit );
                $this->mSiteFeed = $this->mQuery->getWikilogTitle() === null;
-               
        }
 
        public function getIndexField() {
@@ -375,10 +374,12 @@
        }
 
        public function getFeedObject() {
-               if ( $this->mSiteFeed ) {
+               if ( $this->mQuery->getWikilogTitle() ) {
+                       return $this->getWikilogFeedObject( 
$this->mQuery->getWikilogTitle() );
+               } elseif ( $this->mQuery->getNamespace() !== false ) {
+                       return $this->getNamespaceFeedObject( 
$this->mQuery->getNamespace() );
+               } else {
                        return $this->getSiteFeedObject();
-               } else {
-                       return $this->getWikilogFeedObject( 
$this->mQuery->getWikilogTitle() );
                }
        }
 
@@ -414,6 +415,47 @@
        }
 
        /**
+        * Generates and populates a WlSyndicationFeed object for a given 
namespace.
+        *
+        * @param $ns Namespace.
+        * @return Feed object.
+        */
+       protected function getNamespaceFeedObject( $ns ) {
+               global $wgWikilogFeedClasses, $wgFavicon, $wgLogo;
+               global $wgContLang, $wgContLanguageCode;
+
+               $title = wfMsgForContent( 'wikilog-feed-ns-title', 
$wgContLang->getFormattedNsText( $ns ) );
+               $subtitle = wfMsgExt( 'wikilog-feed-description', array( 
'parse', 'content' ) );
+
+               $updated = $this->mDb->selectField(
+                       array( 'wikilog_wikilogs', 'page' ),
+                       'MAX(wlw_updated)',
+                       array(
+                               'wlw_page = page_id',
+                               'page_namespace' => $ns
+                       ),
+                       __METHOD__
+               );
+               if ( !$updated ) $updated = wfTimestampNow();
+
+               $feed = new $wgWikilogFeedClasses[$this->mFormat](
+                       $this->mTitle->getFullUrl(),
+                       wfMsgForContent( 'wikilog-feed-title', $title, 
$wgContLanguageCode ),
+                       $updated,
+                       $this->mTitle->getFullUrl()
+               );
+               $feed->setSubtitle( new WlTextConstruct( 'html', $subtitle ) );
+               $feed->setLogo( wfExpandUrl( $wgLogo ) );
+               if ( $wgFavicon !== false ) {
+                       $feed->setIcon( wfExpandUrl( $wgFavicon ) );
+               }
+               if ( $this->mCopyright ) {
+                       $feed->setRights( new WlTextConstruct( 'html', 
$this->mCopyright ) );
+               }
+               return $feed;
+       }
+
+       /**
         * Generates and populates a WlSyndicationFeed object for the given
         * wikilog. Caches objects whenever possible.
         *
@@ -574,8 +616,13 @@
         * Returns the keys for the timestamp and feed output in the object 
cache.
         */
        public function getCacheKeys() {
-               $title = $this->mQuery->getWikilogTitle();
-               $id = $title ? 'id:' . $title->getArticleId() : 'site';
+               if ( ( $title = $this->mQuery->getWikilogTitle() ) ) {
+                       $id = 'id:' . $title->getArticleId();
+               } elseif ( ( $ns = $this->mQuery->getNamespace() ) ) {
+                       $id = 'ns:' . $ns;
+               } else {
+                       $id = 'site';
+               }
                $ft = 'show:' . $this->mQuery->getPubStatus() .
                        ':limit:' . $this->mLimit;
                return array(

Modified: trunk/extensions/Wikilog/WikilogQuery.php
===================================================================
--- trunk/extensions/Wikilog/WikilogQuery.php   2010-06-25 04:13:36 UTC (rev 
68551)
+++ trunk/extensions/Wikilog/WikilogQuery.php   2010-06-25 04:13:56 UTC (rev 
68552)
@@ -46,6 +46,12 @@
        protected $mDefaultOptions = array();
 
        /**
+        * Whether the query should always return nothing (when invalid options
+        * are provided, for example).
+        */
+       protected $mEmpty = false;
+
+       /**
         * Constructor.
         */
        public function __construct() {
@@ -86,6 +92,12 @@
        }
 
        /**
+        * Filter is always returns empty.
+        */
+       public function setEmpty( $empty = true ) { $this->mEmpty = $empty; }
+       public function getEmpty() { return $this->mEmpty; }
+
+       /**
         * Generate and return query information.
         * @param $db Database  Database object used to encode table names, etc.
         * @param $opts mixed  Misc query options.
@@ -312,10 +324,15 @@
                $q_options = array();
                $q_joins = $wlp_tables['join_conds'];
 
+               # Invalid filter.
+               if ( $this->mEmpty ) {
+                       $q_conds[] = '0=1';
+               }
+
                # Filter by wikilog name.
                if ( $this->mWikilogTitle !== null ) {
                        $q_conds['wlp_parent'] = 
$this->mWikilogTitle->getArticleId();
-               } elseif ( $this->mNamespace ) {
+               } elseif ( $this->mNamespace !== false ) {
                        $q_conds['p.page_namespace'] = $this->mNamespace;
                }
 
@@ -380,7 +397,7 @@
 
                if ( $this->mNeedWikilogParam && $this->mWikilogTitle ) {
                        $query['wikilog'] = 
$this->mWikilogTitle->getPrefixedDBKey();
-               } elseif ( $this->mNamespace ) {
+               } elseif ( $this->mNamespace !== false ) {
                        $query['wikilog'] = Title::makeTitle( 
$this->mNamespace, "*" )->getPrefixedDBKey();
                }
 
@@ -525,7 +542,7 @@
         * precedence over this filter.
         * @param $ns Namespace to query for.
         */
-       public function setNamespace ( $ns ) {
+       public function setNamespace( $ns ) {
                $this->mNamespace = $ns;
        }
 
@@ -637,6 +654,11 @@
                $q_options = array();
                $q_joins = $wlc_tables['join_conds'];
 
+               # Invalid filter.
+               if ( $this->mEmpty ) {
+                       $q_conds[] = '0=1';
+               }
+
                # Filter by moderation status.
                if ( $this->mModStatus == self::MS_ACCEPTED ) {
                        $q_conds['wlc_status'] = 'OK';
@@ -658,7 +680,7 @@
                } elseif ( $this->mWikilog !== null ) {
                        $join_wlp = true;
                        $q_conds['wlp_parent'] = 
$this->mWikilog->getArticleId();
-               } elseif ( $this->mNamespace ) {
+               } elseif ( $this->mNamespace !== false ) {
                        $q_conds['c.page_namespace'] = $this->mNamespace;
                }
 
@@ -706,7 +728,7 @@
                        $query['item'] = 
$this->mItem->mTitle->getPrefixedDBKey();
                } elseif ( $this->mWikilog ) {
                        $query['wikilog'] = $this->mWikilog->getPrefixedDBKey();
-               } elseif ( $this->mNamespace ) {
+               } elseif ( $this->mNamespace !== false ) {
                        $query['wikilog'] = Title::makeTitle( 
$this->mNamespace, "*" )->getPrefixedDBKey();
                }
 



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

Reply via email to