r87474 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87473‎ | r87474 | r87475 >
Date:00:08, 5 May 2011
Author:tparscal
Status:ok
Tags:
Comment:
Added cookie write when an anonomous user rates a page, which is later be used to determine if we need to get their ratings from the server or not. All anonymous users who have not rated will be requesting rating information using a generic URL - these are cheap. Once they rate, or if they are logged in, they will have unique URLs, which always break caching - these are expensive. Also added some path properties to other places where cookies are being set for consistency.
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -173,6 +173,10 @@
174174 },
175175 'submit': function() {
176176 var context = this;
 177+ // For anon users, keep a cookie around so we know they've rated before
 178+ if ( mw.user.anonymous() ) {
 179+ $.cookie( prefix( 'rated' ), 'true', { 'expires': 365, 'path': '/' } );
 180+ }
177181 $.articleFeedback.fn.enableSubmission.call( context, false );
178182 context.$ui.find( '.articleFeedback-lock' ).show();
179183 // Build data from form values for 'action=articlefeedback'
@@ -306,19 +310,20 @@
307311 },
308312 'load': function() {
309313 var context = this;
 314+ var userrating = !mw.user.anonymous() || $.cookie( prefix( 'rated' ) ) === 'true';
310315 $.ajax( {
311316 'url': mw.config.get( 'wgScriptPath' ) + '/api.php',
312317 'type': 'GET',
313318 'dataType': 'json',
314319 'context': context,
315 - 'cache': false,
 320+ 'cache': userrating,
316321 'data': {
317322 'action': 'query',
318323 'format': 'json',
319324 'list': 'articlefeedback',
320325 'afpageid': mw.config.get( 'wgArticleId' ),
321 - 'afanontoken': mw.user.id(),
322 - 'afuserrating': 1
 326+ 'afanontoken': userrating ? mw.user.id() : '',
 327+ 'afuserrating': Number( userrating )
323328 },
324329 'success': function( data ) {
325330 var context = this;
@@ -508,7 +513,9 @@
509514 // Remember that the users rejected this, set a cookie to not
510515 // show this for 3 days
511516 $.cookie(
512 - prefix( 'pitch-' + key ), 'hide', { 'expires': 3 }
 517+ prefix( 'pitch-' + key ),
 518+ 'hide',
 519+ { 'expires': 3, 'path': '/' }
513520 );
514521 // Track that a pitch was dismissed
515522 if ( tracked && typeof $.trackAction == 'function' ) {
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -36,7 +36,7 @@
3737 * @param durration Integer: Number of days to mute the pitch for
3838 */
3939 function mutePitch( pitch, duration ) {
40 - $.cookie( prefix( 'pitches-' + pitch ), 'hide', { 'expires': duration } );
 40+ $.cookie( prefix( 'pitches-' + pitch ), 'hide', { 'expires': duration, 'path': '/' } );
4141 }
4242
4343 function trackClick( id ) {
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php
@@ -142,9 +142,8 @@
143143
144144 protected function getAnonToken( $params ) {
145145 global $wgUser;
146 -
147146 $token = '';
148 - if ( $wgUser->isAnon() ) {
 147+ if ( $wgUser->isAnon() && $params['userrating'] ) {
149148 if ( !isset( $params['anontoken'] ) ) {
150149 $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
151150 } elseif ( strlen( $params['anontoken'] ) != 32 ) {
@@ -249,7 +248,7 @@
250249 ApiBase::PARAM_ISMULTI => false,
251250 ApiBase::PARAM_TYPE => 'integer',
252251 ),
253 - 'userrating' => false,
 252+ 'userrating' => 0,
254253 'anontoken' => null,
255254 );
256255 }
@@ -280,7 +279,7 @@
281280 return array(
282281 'api.php?action=query&list=articlefeedback',
283282 'api.php?action=query&list=articlefeedback&afpageid=1',
284 - 'api.php?action=query&list=articlefeedback&afpageid=1&afuserrating',
 283+ 'api.php?action=query&list=articlefeedback&afpageid=1&afuserrating=1',
285284 );
286285 }
287286

Status & tagging log