r57124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57123‎ | r57124 | r57125 >
Date:17:58, 30 September 2009
Author:werdna
Status:ok (Comments)
Tags:
Comment:
Randomly generate a watchlist token on-demand if a watchlist is loaded and the user has no watchlist token.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -16,18 +16,22 @@
1717
1818 // Add feed links
1919 $wlToken = $wgUser->getOption( 'watchlisttoken' );
20 - if ($wlToken) {
21 - global $wgServer, $wgScriptPath, $wgFeedClasses;
22 - $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
23 - 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
24 - $feedTemplate = $wgServer . $wgScriptPath . '/api.php?';
25 -
26 - foreach( $wgFeedClasses as $format => $class ) {
27 - $theseParams = $apiParams + array( 'feedformat' => $format );
28 - $url = $feedTemplate . wfArrayToCGI( $theseParams );
29 - $wgOut->addFeedLink( $format, $url );
30 - }
 20+ if (!$wlToken) {
 21+ $wlToken = sha1( mt_rand() . microtime( true ) );
 22+ $wgUser->setOption( 'watchlisttoken', $wlToken );
 23+ $wgUser->saveSettings();
3124 }
 25+
 26+ global $wgServer, $wgScriptPath, $wgFeedClasses;
 27+ $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
 28+ 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
 29+ $feedTemplate = $wgServer . $wgScriptPath . '/api.php?';
 30+
 31+ foreach( $wgFeedClasses as $format => $class ) {
 32+ $theseParams = $apiParams + array( 'feedformat' => $format );
 33+ $url = $feedTemplate . wfArrayToCGI( $theseParams );
 34+ $wgOut->addFeedLink( $format, $url );
 35+ }
3236
3337 $skin = $wgUser->getSkin();
3438 $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );

Comments

#Comment by Simetrical (talk | contribs)   19:01, 30 September 2009

FWIW, the reason I didn't do this to begin with is because this would allow anyone who gets access to the token to read your watchlist forever (unless it's changed, which is unlikely). So I made it opt-in. But the benefits of an opt-out scheme are certainly clear, and I have no objections to this.

Now I think the only half-bakedness remaining is letting users edit the token themselves in their preferences using an ordinary text field, instead of (let's say) buttons to generate a new token or or disable it. That might be more of a pain to fix than it's worth, though.

#Comment by Werdna (talk | contribs)   19:03, 30 September 2009

That's what we've been talking about on IRC.

Status & tagging log