Re-work feed exposure system.
authorAndrew Garrett <werdna@users.mediawiki.org>
Wed, 30 Sep 2009 17:35:41 +0000 (17:35 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Wed, 30 Sep 2009 17:35:41 +0000 (17:35 +0000)
* Includes a new, more flexible system which allows you to provide an array of format => URL, but also supports the older system of providing a URL suffix.
* Implemented it for the watchlist if a user has set their own token.

includes/OutputPage.php
includes/specials/SpecialWatchlist.php

index 6811a3c..844496c 100644 (file)
@@ -28,8 +28,9 @@ class OutputPage {
        var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
        var $mIsArticleRelated = true;
        protected $mParserOptions = null; // lazy initialised, use parserOptions()
-       var $mShowFeedLinks = false;
-       var $mFeedLinksAppendQuery = false;
+       
+       var $mFeedLinks = array();
+       
        var $mEnableClientCache = true;
        var $mArticleBodyOnly = false;
 
@@ -575,14 +576,30 @@ class OutputPage {
        public function isArticle() { return $this->mIsarticle; }
        public function setPrintable() { $this->mPrintable = true; }
        public function isPrintable() { return $this->mPrintable; }
-       public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
-       public function isSyndicated() { return $this->mShowFeedLinks; }
-       public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery = $val; }
        public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
        public function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
        public function getOnloadHandler() { return $this->mOnloadHandler; }
        public function disable() { $this->mDoNothing = true; }
        public function isDisabled() { return $this->mDoNothing; }
+       
+       public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
+       
+       public function setFeedAppendQuery( $val ) {
+               global $wgFeedClasses;
+               
+               $this->mFeedLinks = array();
+               
+               foreach( $wgFeedClasses as $type => $class ) {
+                       $query = "feed=$type&".$val;
+                       $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
+               }
+       }
+       
+       public function addFeedLink( $format, $href ) {
+               $this->mFeedLinks[$format] = $href;
+       }
+       
+       public function isSyndicated() { return count($this->mFeedLinks); }
 
        public function setArticleRelated( $v ) {
                $this->mIsArticleRelated = $v;
@@ -1916,22 +1933,8 @@ class OutputPage {
         * Return URLs for each supported syndication format for this page.
         * @return array associating format keys with URLs
         */
-       public function getSyndicationLinks() {
-               global $wgFeedClasses;
-               $links = array();
-
-               if( $this->isSyndicated() ) {
-                       if( is_string( $this->getFeedAppendQuery() ) ) {
-                               $appendQuery = "&" . $this->getFeedAppendQuery();
-                       } else {
-                               $appendQuery = "";
-                       }
-
-                       foreach( $wgFeedClasses as $format => $class ) {
-                               $links[$format] = $this->getTitle()->getLocalUrl( "feed=$format{$appendQuery}" );
-                       }
-               }
-               return $links;
+       public function getSyndicationLinks() {         
+               return $this->mFeedLinks;
        }
 
        /**
index 97fd8d1..8d3363a 100644 (file)
@@ -13,6 +13,21 @@ function wfSpecialWatchlist( $par ) {
        global $wgUser, $wgOut, $wgLang, $wgRequest;
        global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
        global $wgEnotifWatchlist;
+       
+       // Add feed links
+       $wlToken = $wgUser->getOption( 'watchlisttoken' );
+       if ($wlToken) {
+               global $wgServer, $wgScriptPath, $wgFeedClasses;
+               $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                                       'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
+               $feedTemplate = $wgServer . '/' . $wgScriptPath . '/api.php?';
+               
+               foreach( $wgFeedClasses as $format => $class ) {
+                       $theseParams = $apiParams + array( 'feedformat' => $format );
+                       $url = $feedTemplate . wfArrayToCGI( $theseParams );
+                       $wgOut->addFeedLink( $format, $url );
+               }
+       }
 
        $skin = $wgUser->getSkin();
        $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );