Randomly generate a watchlist token on-demand if a watchlist is loaded and the user...
authorAndrew Garrett <werdna@users.mediawiki.org>
Wed, 30 Sep 2009 17:58:00 +0000 (17:58 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Wed, 30 Sep 2009 17:58:00 +0000 (17:58 +0000)
includes/specials/SpecialWatchlist.php

index 1d04272..d43973d 100644 (file)
@@ -16,17 +16,21 @@ function wfSpecialWatchlist( $par ) {
        
        // 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 );
-               }
+       if (!$wlToken) {
+               $wlToken = sha1( mt_rand() . microtime( true ) );
+               $wgUser->setOption( 'watchlisttoken', $wlToken );
+               $wgUser->saveSettings();
+       }
+       
+       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();