r81175 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81174‎ | r81175 | r81176 >
Date:22:37, 28 January 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added alternative action support, and used it to supply an "or login" option for the create account pitch.
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.css (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php
@@ -23,11 +23,13 @@
2424 'articlefeedback-field-wellwritten-tip',
2525 'articlefeedback-pitch-takesurvey-title',
2626 'articlefeedback-pitch-reject',
 27+ 'articlefeedback-pitch-or',
2728 'articlefeedback-pitch-takesurvey-message',
2829 'articlefeedback-pitch-takesurvey-accept',
2930 'articlefeedback-pitch-createaccount-title',
3031 'articlefeedback-pitch-createaccount-message',
3132 'articlefeedback-pitch-createaccount-accept',
 33+ 'articlefeedback-pitch-createaccount-login',
3234 'articlefeedback-pitch-makefirstedit-title',
3335 'articlefeedback-pitch-makefirstedit-message',
3436 'articlefeedback-pitch-makefirstedit-accept',
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -103,6 +103,30 @@
104104 }
105105 } );
106106 },
 107+ 'executePitch': function( action ) {
 108+ $(this)
 109+ .closest( '.articleFeedback-pitch' )
 110+ .find( '.articleFeedback-accept, .articleFeedback-altAccept' )
 111+ .button( { 'disabled': true } )
 112+ .end()
 113+ .find( '.articleFeedback-reject' )
 114+ .attr( 'disabled', true );
 115+ var $pitch = $(this).closest( '.articleFeedback-pitch' );
 116+ var key = $pitch.attr( 'rel' );
 117+ // If a pitch's action returns true, hide the pitch and
 118+ // re-enable the button
 119+ if ( action.call( $(this) ) ) {
 120+ $pitch.fadeOut();
 121+ $(this)
 122+ .closest( '.articleFeedback-pitch' )
 123+ .find( '.articleFeedback-accept, .articleFeedback-altAccept' )
 124+ .button( { 'disabled': false } )
 125+ .end()
 126+ .find( '.articleFeedback-reject' )
 127+ .attr( 'disabled', false );
 128+ }
 129+ return false;
 130+ },
107131 'load': function() {
108132 var context = this;
109133 $.ajax( {
@@ -217,23 +241,11 @@
218242 .find( '.articleFeedback-accept' )
219243 .text( mw.msg( context.options.pitches[key].accept ) )
220244 .click( function() {
221 - $(this)
222 - .button( { 'disabled': true } )
223 - .closest( '.articleFeedback-pitch' )
224 - .find( '.articleFeedback-reject' )
225 - .attr( 'disabled', true );
226245 var $pitch = $(this).closest( '.articleFeedback-pitch' );
227 - var key = $pitch.attr( 'rel' );
228 - // If a pitch's action returns true, hide the pitch and
229 - // re-enable the button
230 - if ( context.options.pitches[key].action() ) {
231 - $pitch.fadeOut();
232 - $(this)
233 - .button( { 'disabled': false } )
234 - .closest( '.articleFeedback-pitch' )
235 - .find( '.articleFeedback-reject' )
236 - .attr( 'disabled', false );
237 - }
 246+ return $.articleFeedback.fn.executePitch.call(
 247+ $(this),
 248+ context.options.pitches[$pitch.attr( 'rel' )].action
 249+ );
238250 } )
239251 .button()
240252 .end()
@@ -252,6 +264,29 @@
253265 } )
254266 .end()
255267 .appendTo( $(this) );
 268+ if (
 269+ typeof context.options.pitches[key].altAccept == 'string'
 270+ && typeof context.options.pitches[key].altAction == 'function'
 271+ ) {
 272+ $(this)
 273+ .find( '.articleFeedback-accept' )
 274+ .after( '<button class="articleFeedback-altAccept"></button>' )
 275+ .after(
 276+ $( '<span class="articleFeedback-pitch-or"></span>' )
 277+ .text( mw.msg( 'articlefeedback-pitch-or' ) )
 278+ )
 279+ .end()
 280+ .find( '.articleFeedback-altAccept' )
 281+ .text( mw.msg( context.options.pitches[key].altAccept ) )
 282+ .click( function() {
 283+ var $pitch = $(this).closest( '.articleFeedback-pitch' );
 284+ return $.articleFeedback.fn.executePitch.call(
 285+ $(this),
 286+ context.options.pitches[$pitch.attr( 'rel' )].altAction
 287+ );
 288+ } )
 289+ .button();
 290+ }
256291 }
257292 } )
258293 .localize( { 'prefix': 'articlefeedback-' } )
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.css
@@ -24,7 +24,10 @@
2525 border: 1px solid #cccccc;
2626 padding-bottom: 1px;
2727 }
28 -
 28+.articleFeedback-pitch-or {
 29+ margin-left: 0.75em;
 30+ margin-right: 0.25em;
 31+}
2932 .articleFeedback-reject {
3033 border: none;
3134 background-color: #f9f9f9;
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -195,28 +195,14 @@
196196 }
197197 },
198198 'pitches': {
199 - 'takesurvey': {
200 - 'condition': function() {
201 - // If already taken survey, return false
202 - return isPitchMuted( 'takesurvey' ) ? false : lottery( 0.33 );
203 - },
204 - 'action': function() {
205 - survey.load();
206 - // Hide the pitch immediately
207 - return true;
208 - },
209 - 'title': 'articlefeedback-pitch-takesurvey-title',
210 - 'message': 'articlefeedback-pitch-takesurvey-message',
211 - 'accept': 'articlefeedback-pitch-takesurvey-accept',
212 - 'reject': 'articlefeedback-pitch-reject'
213 - },
214199 'createaccount': {
215200 'condition': function() {
216201 // If user is logged in, return false
217 - return !isPitchMuted( 'createaccount' ) && mediaWiki.user.anonymous();
 202+ return ( isPitchMuted( 'createaccount' ) || !mediaWiki.user.anonymous() )
 203+ ? false : lottery( 0.5 );
218204 },
219205 'action': function() {
220 - // TODO: Do something
 206+ // Go to account creation page
221207 window.location =
222208 mediaWiki.config.get( 'wgScript' ) + '?' + $.param( {
223209 'title': 'Special:UserLogin',
@@ -230,15 +216,29 @@
231217 'title': 'articlefeedback-pitch-createaccount-title',
232218 'message': 'articlefeedback-pitch-createaccount-message',
233219 'accept': 'articlefeedback-pitch-createaccount-accept',
234 - 'reject': 'articlefeedback-pitch-reject'
 220+ 'reject': 'articlefeedback-pitch-reject',
 221+ // Special alternative action for going to login page
 222+ 'altAccept': 'articlefeedback-pitch-createaccount-login',
 223+ 'altAction': function() {
 224+ // Go to login page
 225+ window.location =
 226+ mediaWiki.config.get( 'wgScript' ) + '?' + $.param( {
 227+ 'title': 'Special:UserLogin',
 228+ 'returnto': mediaWiki.config.get( 'wgPageName' )
 229+ } );
 230+ // Mute for 1 day
 231+ mutePitch( 'createaccount', 1 );
 232+ return false;
 233+ }
235234 },
236235 'makefirstedit': {
237236 'condition': function() {
238237 // If user is not logged in, return false
239 - return !isPitchMuted( 'makefirstedit' ) && !mediaWiki.user.anonymous();
 238+ return ( isPitchMuted( 'makefirstedit' ) || mediaWiki.user.anonymous() )
 239+ ? false : lottery( 0.5 );
240240 },
241241 'action': function() {
242 - // TODO: Do something
 242+ // Go to edit page
243243 window.location =
244244 mediaWiki.config.get( 'wgScript' ) + '?' + $.param( {
245245 'title': mediaWiki.config.get( 'wgPageName' ),
@@ -252,6 +252,21 @@
253253 'message': 'articlefeedback-pitch-makefirstedit-message',
254254 'accept': 'articlefeedback-pitch-makefirstedit-accept',
255255 'reject': 'articlefeedback-pitch-reject'
 256+ },
 257+ 'takesurvey': {
 258+ 'condition': function() {
 259+ // If already taken survey, return false
 260+ return !isPitchMuted( 'takesurvey' );
 261+ },
 262+ 'action': function() {
 263+ survey.load();
 264+ // Hide the pitch immediately
 265+ return true;
 266+ },
 267+ 'title': 'articlefeedback-pitch-takesurvey-title',
 268+ 'message': 'articlefeedback-pitch-takesurvey-message',
 269+ 'accept': 'articlefeedback-pitch-takesurvey-accept',
 270+ 'reject': 'articlefeedback-pitch-reject'
256271 }
257272 }
258273 };
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php
@@ -45,12 +45,14 @@
4646 'articlefeedback-field-wellwritten-label' => 'Well-written',
4747 'articlefeedback-field-wellwritten-tip' => 'Do you feel that this page is well-organized and well-written?',
4848 'articlefeedback-pitch-reject' => 'Maybe later',
 49+ 'articlefeedback-pitch-or' => 'or',
4950 'articlefeedback-pitch-takesurvey-title' => 'Would you like to take a survey?',
5051 'articlefeedback-pitch-takesurvey-message' => '-- message --',
5152 'articlefeedback-pitch-takesurvey-accept' => 'Start survey',
5253 'articlefeedback-pitch-createaccount-title' => 'Would you like to create an account?',
5354 'articlefeedback-pitch-createaccount-message' => '-- message --',
5455 'articlefeedback-pitch-createaccount-accept' => 'Create account',
 56+ 'articlefeedback-pitch-createaccount-login' => 'Log in',
5557 'articlefeedback-pitch-makefirstedit-title' => 'Would you like to edit this page?',
5658 'articlefeedback-pitch-makefirstedit-message' => '-- message --',
5759 'articlefeedback-pitch-makefirstedit-accept' => 'Start editing',

Status & tagging log