Refactoring to r89566
authorSam Reed <reedy@users.mediawiki.org>
Mon, 6 Jun 2011 15:07:23 +0000 (15:07 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 6 Jun 2011 15:07:23 +0000 (15:07 +0000)
Refactor out duplicate code to SpecialPage

includes/SpecialPage.php
includes/specials/SpecialContributions.php
includes/specials/SpecialWatchlist.php

index 2d5f541..d5e6985 100644 (file)
@@ -657,6 +657,23 @@ class SpecialPage {
        public function msg( /* $args */ ) {
                return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
        }
+
+       /**
+        * Adds RSS/atom links
+        *
+        * @param $params array
+        */
+       protected function addFeedLinks( $params ) {
+               global $wgFeedClasses, $wgOut;
+
+               $feedTemplate = wfScript( 'api' ) . '?';
+
+               foreach( $wgFeedClasses as $format => $class ) {
+                       $theseParams = $params + array( 'feedformat' => $format );
+                       $url = $feedTemplate . wfArrayToCGI( $theseParams );
+                       $wgOut->addFeedLink( $format, $url );
+               }
+       }
 }
 
 /**
index 92f4ab3..a9afbc6 100644 (file)
@@ -116,15 +116,7 @@ class SpecialContributions extends SpecialPage {
                }
 
                // Add RSS/atom links
-               global $wgFeedClasses;
-               $apiParams = array( 'action' => 'feedcontributions', 'user' => $wgUser->getName() );
-               $feedTemplate = wfScript( 'api' ) . '?';
-
-               foreach( $wgFeedClasses as $format => $class ) {
-                       $theseParams = $apiParams + array( 'feedformat' => $format );
-                       $url = $feedTemplate . wfArrayToCGI( $theseParams );
-                       $wgOut->addFeedLink( $format, $url );
-               }
+               $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $wgUser->getName() ) );
 
                if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) {
 
index 7389b0b..89e9e90 100644 (file)
@@ -46,16 +46,8 @@ class SpecialWatchlist extends SpecialPage {
                        $wgUser->saveSettings();
                }
 
-               global $wgFeedClasses;
-               $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
-                                                       'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
-               $feedTemplate = wfScript( 'api' ) . '?';
-
-               foreach( $wgFeedClasses as $format => $class ) {
-                       $theseParams = $apiParams + array( 'feedformat' => $format );
-                       $url = $feedTemplate . wfArrayToCGI( $theseParams );
-                       $wgOut->addFeedLink( $format, $url );
-               }
+               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                                       'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ) );
 
                $skin = $this->getSkin();
                $wgOut->setRobotPolicy( 'noindex,nofollow' );