r53314 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53313‎ | r53314 | r53315 >
Date:15:08, 15 July 2009
Author:catrope
Status:deferred
Tags:
Comment:
OptIn: Add feedback survey
Modified paths:
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/OptIn.sql (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.php
@@ -28,7 +28,7 @@
2929 $wgOptInAlwaysShowPersonalLink = false;
3030 $wgOptInNeverShowPersonalLink = false;
3131
32 -$wgOptInStyleVersion = 5;
 32+$wgOptInStyleVersion = 6;
3333
3434 // Preferences to set when users opt in
3535 // array( prefname => value )
@@ -90,6 +90,24 @@
9191 'type' => 'resolution' ),
9292 );
9393
 94+$wgOptInFeedBackSurvey = $wgOptInSurvey;
 95+unset( $wgOptInFeedBackSurvey[1] );
 96+unset( $wgOptInFeedBackSurvey[2] );
 97+$wgOptInFeedBackSurvey[4]['ifno'] = 'optin-survey-question-usedtoolbar-ifno';
 98+$wgOptInFeedBackSurvey[5] = array(
 99+ 'question' => 'optin-survey-question-changes',
 100+ 'type' => 'checkboxes',
 101+ 'answers' => array(
 102+ 'optin-survey-answer-changes-nav',
 103+ 'optin-survey-answer-changes-edittools',
 104+ 'optin-survey-answer-changes-upload',
 105+ 'optin-survey-answer-changes-richtext',
 106+ 'optin-survey-answer-changes-lookfeel',
 107+ 'optin-survey-answer-changes-predictability',
 108+ 'optin-survey-answer-changes-compat' ),
 109+ 'other' => 'optin-survey-answer-changes-other'
 110+);
 111+
94112 /* Setup */
95113
96114 // Credits
Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
@@ -58,7 +58,8 @@
5959 }
6060
6161 public function execute( $par ) {
62 - global $wgRequest, $wgOut, $wgUser;
 62+ global $wgRequest, $wgOut, $wgUser, $wgOptInSurvey;
 63+ global $wgOptInFeedBackSurvey;
6364
6465 $par = $wgRequest->getVal( 'from', $par );
6566 $this->mOriginTitle = Title::newFromText( $par );
@@ -77,6 +78,9 @@
7879 if ( $wgRequest->getVal( 'opt' ) == 'out' )
7980 // Just opted out
8081 $wgOut->setPageTitle( wfMsg( 'optin-title-justoptedout' ) );
 82+ else if ( $wgRequest->getVal( 'opt' ) == 'feedback' )
 83+ // Giving feedback
 84+ $wgOut->setPageTitle( wfMsg( 'optin-title-feedback' ) );
8185 else
8286 // About to opt out
8387 $wgOut->setPageTitle( wfMsg( 'optin-title-optedin' ) );
@@ -95,9 +99,16 @@
96100 if ( $wgRequest->getVal( 'opt' ) === 'in' ) {
97101 self::optIn( $wgUser );
98102 $wgOut->addWikiMsg( 'optin-success-in' );
 103+ } else if ( $wgRequest->getVal( 'opt' ) == 'feedback' ) {
 104+ if ( $wgRequest->wasPosted() ) {
 105+ $this->saveSurvey( $wgOptInFeedBackSurvey,
 106+ 'feedback' );
 107+ $wgOut->addWikiMsg( 'optin-success-feedback' );
 108+ } else
 109+ $this->showForm( 'feedback' );
99110 } else {
100111 self::optOut( $wgUser );
101 - $this->saveSurvey();
 112+ $this->saveSurvey( $wgOptInSurvey, 'out' );
102113 $wgOut->addWikiMsg( 'optin-success-out' );
103114 }
104115 if ( $this->mOriginTitle )
@@ -105,24 +116,30 @@
106117 $this->mOriginLink ) );
107118 }
108119 else
109 - $this->showForm();
 120+ $this->showForm( self::isOptedIn( $wgUser ) ?
 121+ 'out' : 'in' );
110122 }
111123
112124 /* Private Functions */
113125
114 - private function showForm() {
115 - global $wgUser, $wgOut;
 126+ private function showForm( $opt ) {
 127+ global $wgUser, $wgOut, $wgOptInSurvey, $wgOptInFeedBackSurvey;
116128
117 - $opt = ( self::isOptedIn( $wgUser ) ? 'out' : 'in' );
118129 if ( $opt == 'out' ) {
119130 $wgOut->addWikiMsg( 'optin-survey-intro' );
120131 if ( $this->mOriginTitle )
121132 $wgOut->addHTML( wfMsg( 'optin-leave-cancel',
122133 $this->mOriginLink ) );
123 - $this->showSurvey();
124 - }
125 - else
126 - {
 134+ $this->showSurvey( $wgOptInSurvey,
 135+ 'optin-submit-out', 'out' );
 136+ } else if ( $opt == 'feedback' ) {
 137+ $wgOut->addWikiMsg( 'optin-feedback-intro' );
 138+ if ( $this->mOriginTitle )
 139+ $wgOut->addHTML( wfMsg( 'optin-feedback-back',
 140+ $this->mOriginLink ) );
 141+ $this->showSurvey( $wgOptInFeedBackSurvey,
 142+ 'optin-submit-feedback', 'feedback', true );
 143+ } else {
127144 $wgOut->wrapWikiMsg(
128145 "<div class='optin-intro'>\n$1\n</div>",
129146 array( 'optin-intro' )
@@ -208,8 +225,8 @@
209226 );
210227 }
211228
212 - private function showSurvey() {
213 - global $wgOptInSurvey, $wgOut, $wgOptInStyleVersion;
 229+ private function showSurvey( $survey, $submitMsg, $opt, $loadFromDB = false ) {
 230+ global $wgUser, $wgOut, $wgOptInStyleVersion;
214231
215232 UsabilityInitiativeHooks::initialize();
216233 UsabilityInitiativeHooks::addScript( 'OptIn/OptIn.js',
@@ -217,6 +234,21 @@
218235 UsabilityInitiativeHooks::addStyle( 'OptIn/OptIn.css',
219236 $wgOptInStyleVersion );
220237
 238+ $loaded = array();
 239+ if ( $loadFromDB ) {
 240+ $dbr = wfGetDb( DB_SLAVE );
 241+ $res = $dbr->select( 'optin_survey', array(
 242+ 'ois_question',
 243+ 'ois_answer',
 244+ 'ois_answer_data' ), array(
 245+ 'ois_user' => $wgUser->getID(),
 246+ 'ois_type' => $opt ), __METHOD__ );
 247+ foreach( $res as $row )
 248+ $loaded[$row->ois_question] = array(
 249+ $row->ois_answer, $row->ois_answer_data
 250+ );
 251+ }
 252+
221253 $query = array( 'from' => $this->mOrigin,
222254 'fromquery' => $this->mOriginQuery
223255 );
@@ -227,9 +259,12 @@
228260 'id' => 'optin-survey',
229261 )
230262 );
231 - $retval .= Xml::hidden( 'opt', 'out' );
 263+ $retval .= Xml::hidden( 'opt', $opt );
232264 $retval .= Xml::openElement( 'dl' );
233 - foreach ( $wgOptInSurvey as $id => $question ) {
 265+ foreach ( $survey as $id => $question ) {
 266+ $answer = isset( $loaded[$id] ) ? $loaded[$id][0] : null;
 267+ $answerdata = isset( $loaded[$id] )
 268+ ? $loaded[$id][1] : null;
234269 switch ( $question['type'] ) {
235270 case 'dropdown':
236271 $retval .= Xml::tags(
@@ -245,11 +280,14 @@
246281 $retval .= Xml::openElement( 'select', $attrs );
247282 $retval .= Xml::option( '', '' );
248283 foreach ( $question['answers'] as $aid => $answer ) {
249 - $retval .= Xml::option( wfMsg( $answer ), $aid );
 284+ $retval .= Xml::option(
 285+ wfMsg( $answer ), $aid,
 286+ $answer === $aid );
250287 }
251288 if ( isset( $question['other'] ) ) {
252289 $retval .= Xml::option(
253 - wfMsg( $question['other'] ), 'other'
 290+ wfMsg( $question['other'] ),
 291+ 'other', $answer === 'other'
254292 );
255293 }
256294 $retval .= Xml::closeElement( 'select' );
@@ -258,7 +296,8 @@
259297 Xml::input(
260298 "survey-$id-other",
261299 false,
262 - false,
 300+ $answer === 'other' ?
 301+ $answerdata : false,
263302 array(
264303 'class' => 'optin-other-select',
265304 'id' => "survey-$id-other"
@@ -276,7 +315,9 @@
277316 $radios = array();
278317 foreach ( $question['answers'] as $aid => $answer ) {
279318 $radios[] = Xml::radioLabel(
280 - wfMsg( $answer ), "survey-$id", $aid, "survey-$id-$aid"
 319+ wfMsg( $answer ), "survey-$id",
 320+ $aid, "survey-$id-$aid",
 321+ $answer === $aid
281322 );
282323 }
283324 if ( isset( $question['other'] ) ) {
@@ -284,13 +325,15 @@
285326 wfMsg( $question['other'] ),
286327 "survey-$id",
287328 'other',
288 - "survey-$id-other-radio"
 329+ "survey-$id-other-radio",
 330+ $answer === 'other'
289331 ) .
290332 '&nbsp;' .
291333 Xml::input(
292334 "survey-$id-other",
293335 false,
294 - false,
 336+ $answer === 'other' ?
 337+ $answerdata : false,
295338 array( 'class' => 'optin-other-radios' )
296339 );
297340 }
@@ -298,6 +341,7 @@
299342 $retval .= Xml::closeElement( 'dd' );
300343 break;
301344 case 'checkboxes':
 345+ $answers = explode( ',', $answer );
302346 $retval .= Xml::tags(
303347 'dt', null, wfMsgWikiHtml( $question['question'] )
304348 );
@@ -308,7 +352,7 @@
309353 wfMsg( $answer ),
310354 "survey-{$id}[]",
311355 "survey-$id-$aid",
312 - false,
 356+ in_array( $aid, $answers, true ),
313357 array( 'value' => $aid )
314358 );
315359 }
@@ -317,14 +361,15 @@
318362 wfMsg( $question['other'] ),
319363 "survey-{$id}[]",
320364 "survey-$id-other-check",
321 - false,
 365+ in_array( 'other', $answers, true ),
322366 array( 'value' => 'other' )
323367 ) .
324368 '&nbsp;' .
325369 Xml::input(
326370 "survey-$id-other",
327371 false,
328 - false,
 372+ in_array( 'other', $answers, true ) ?
 373+ $answerdata : false,
329374 array( 'class' => 'optin-other-checks' )
330375 );
331376 }
@@ -341,7 +386,7 @@
342387 "survey-$id",
343388 'yes',
344389 "survey-$id-yes",
345 - false,
 390+ $answer === 'yes',
346391 array( 'class' => 'survey-yes' )
347392 );
348393 $retval .= Xml::element( 'br' );
@@ -350,7 +395,7 @@
351396 "survey-$id",
352397 'no',
353398 "survey-$id-no",
354 - false,
 399+ $answer === 'no',
355400 array( 'class' => 'survey-no' )
356401 );
357402 $retval .= Xml::closeElement( 'dd' );
@@ -365,7 +410,10 @@
366411 'dt', null, wfMsgWikiHtml( $question['ifyes'] )
367412 );
368413 $retval .= Xml::tags(
369 - 'dd', null, Xml::textarea( "survey-$id-ifyes", '' )
 414+ 'dd', null, Xml::textarea(
 415+ "survey-$id-ifyes",
 416+ $answerdata ?
 417+ $answerdata : '' )
370418 );
371419 $retval .= Xml::closeElement( 'blockquote' );
372420 }
@@ -373,19 +421,26 @@
374422 $retval .= Xml::openElement(
375423 'blockquote', array(
376424 'id' => "survey-$id-ifno-row",
377 - 'class' => 'survey-ifyes',
 425+ 'class' => 'survey-ifno',
378426 )
379427 );
380428 $retval .= Xml::tags(
381429 'dt', null, wfMsgWikiHtml( $question['ifno'] )
382430 );
383431 $retval .= Xml::tags(
384 - 'dd', null, Xml::textarea( "survey-$id-ifno", '' )
 432+ 'dd', null, Xml::textarea(
 433+ "survey-$id-ifno",
 434+ $answerdata ?
 435+ $answerdata : '' )
385436 );
386437 $retval .= Xml::closeElement( 'blockquote' );
387438 }
388439 break;
389440 case 'resolution':
 441+ if ( $answerdata )
 442+ list( $x, $y ) = explode( 'x', $answerdata );
 443+ else
 444+ $x = $y = false;
390445 $retval .= Xml::tags(
391446 'dt', null, wfMsgWikiHtml( $question['question'] )
392447 );
@@ -393,7 +448,7 @@
394449 $retval .= Xml::input(
395450 "survey-$id-x",
396451 5,
397 - false,
 452+ $x,
398453 array(
399454 'class' => 'optin-resolution-x',
400455 'id' => "survey-$id-x",
@@ -403,7 +458,7 @@
404459 $retval .= Xml::input(
405460 "survey-$id-y",
406461 5,
407 - false,
 462+ $y,
408463 array(
409464 'class' => 'optin-resolution-y',
410465 'id' => "survey-$id-y",
@@ -416,7 +471,8 @@
417472 'dt', null, wfMsgWikiHtml( $question['question'] )
418473 );
419474 $retval .= Xml::tags(
420 - 'dd', null, Xml::textarea( "survey-$id", '' )
 475+ 'dd', null, Xml::textarea( "survey-$id",
 476+ $answerdata ? $answerdata : '' )
421477 );
422478 break;
423479 }
@@ -425,22 +481,23 @@
426482 'dt',
427483 array( 'class' => 'optin-survey-submit' ),
428484 Xml::element( 'a', array( 'id' => 'leave' ), '', false ) .
429 - Xml::submitButton( wfMsg( 'optin-submit-out' ) )
 485+ Xml::submitButton( wfMsg( $submitMsg ) )
430486 );
431487 $retval .= Xml::closeElement( 'dl' );
432488 $retval .= Xml::closeElement( 'form' );
433489 $wgOut->addHTML( $retval );
434490 }
435491
436 - private function saveSurvey() {
437 - global $wgRequest, $wgUser, $wgOptInSurvey;
 492+ private function saveSurvey( $survey, $type ) {
 493+ global $wgRequest, $wgUser;
438494
439495 $dbw = wfGetDb( DB_MASTER );
440496 $now = $dbw->timestamp( wfTimestamp() );
441 - foreach ( $wgOptInSurvey as $id => $question ) {
 497+ foreach ( $survey as $id => $question ) {
442498 $insert = array(
443499 'ois_user' => $wgUser->getId(),
444500 'ois_timestamp' => $now,
 501+ 'ois_type' => $type,
445502 'ois_question' => $id );
446503 switch ( $question['type'] ) {
447504 case 'dropdown':
@@ -459,9 +516,7 @@
460517 }
461518 break;
462519 case 'checkboxes':
463 - $checked = array_map(
464 - 'intval', $wgRequest->getArray( "survey-$id", array() )
465 - );
 520+ $checked = $wgRequest->getArray( "survey-$id", array() );
466521 $insert['ois_answer'] =
467522 ( count( $checked ) ? implode( ',', $checked ) : null );
468523 $insert['ois_answer_data'] = ( in_array( 'other', $checked ) ?
@@ -473,9 +528,9 @@
474529 $wgRequest->getVal( "survey-$id", null );
475530 $data = '';
476531 if ( $insert['ois_answer'] == 'yes' )
477 - $data += $wgRequest->getVal( "survey-$id-ifyes", '' );
 532+ $data .= $wgRequest->getVal( "survey-$id-ifyes", '' );
478533 if ( $insert['ois_answer'] == 'no' )
479 - $data += $wgRequest->getVal( "survey-$id-ifno", '' );
 534+ $data .= $wgRequest->getVal( "survey-$id-ifno", '' );
480535 $insert['ois_answer_data'] = ( $data ? $data : null );
481536 break;
482537 case 'resolution':
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.hooks.php
@@ -32,7 +32,7 @@
3333 // Loads opt-in messages
3434 wfLoadExtensionMessages( 'OptIn' );
3535
36 - $fromquery = $wgRequest->data;
 36+ $fromquery = $wgRequest->getValues();
3737 unset( $fromquery['title'] );
3838 $query = array( 'from' => $title->getPrefixedDBKey(),
3939 'fromquery' => wfArrayToCGI( $fromquery )
@@ -46,18 +46,29 @@
4747 $link = SpecialPage::getTitleFor( 'OptIn' )->getFullURL( $query );
4848
4949 // Inserts a link into personal tools
50 - $personal_urls = array_merge(
51 - array(
52 - 'acaibeta' => array(
53 - 'text' => SpecialOptIn::isOptedIn( $wgUser ) ?
54 - wfMsg( 'optin-leave' ) :
55 - wfMsg( 'optin-try' ),
56 - 'href' => $link,
57 - 'class' => 'no-text-transform'
58 - )
59 - ),
60 - $personal_urls
 50+ $addLinks = array(
 51+ 'acaibeta' => array(
 52+ 'text' => SpecialOptIn::isOptedIn( $wgUser ) ?
 53+ wfMsg( 'optin-leave' ) :
 54+ wfMsg( 'optin-try' ),
 55+ 'href' => $link,
 56+ 'class' => 'no-text-transform'
 57+ )
6158 );
 59+
 60+ // For opted-in users, add a feedback link
 61+ if ( SpecialOptIn::isOptedIn( $wgUser ) ) {
 62+ $query['opt'] = 'feedback';
 63+ $link = SpecialPage::getTitleFor( 'OptIn' )->getFullURL( $query );
 64+ $addLinks['betafeedback'] = array(
 65+ 'text' => wfMsg( 'optin-feedback' ),
 66+ 'href' => $link,
 67+ 'class' => 'no-text-transform'
 68+ );
 69+ }
 70+
 71+ // Add the links
 72+ $personal_urls = array_merge( $addLinks, $personal_urls );
6273 return true;
6374 }
6475 }
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.js
@@ -25,6 +25,8 @@
2626 norow.slideDown( 'fast' );
2727 }
2828 });
 29+ // Load initial state
 30+ $( '.survey-yes, .survey-no' ).change();
2931
3032 // Detect screen resolution
3133 if ( screen.width && screen.height ) {
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.sql
@@ -8,6 +8,9 @@
99
1010 -- Timestamp
1111 ois_timestamp binary(14) NOT NULL,
 12+
 13+ -- Survey type (out or feedback)
 14+ ois_type varchar(16) NOT NULL,
1215
1316 -- Question ID (key in $wgOptInSurvey)
1417 ois_question int unsigned NOT NULL,
Index: trunk/extensions/UsabilityInitiative/OptIn/OptIn.i18n.php
@@ -18,22 +18,29 @@
1919 'optin-title-optedin' => 'Leave Beta',
2020 'optin-title-justoptedin' => 'Welcome to Beta',
2121 'optin-title-justoptedout' => 'Thank you for trying Beta',
 22+ 'optin-title-feedback' => 'Give feedback',
2223 'optin-needlogin' => 'You need to [$1 log in] to try Beta.',
2324 'optin-intro' => 'The Wikipedia Usability Initiative has been working hard to improve the usability of Wikipedia.
2425 Would you like to try Beta?',
 26+ 'optin-feedback-intro' => "Thank you for trying Beta.
 27+We would like to know what you think of our new interface, so we would appreciate it if you filled out the optional survey below.",
 28+ 'optin-feedback-back' => 'If you do not want to fill out the survey, you can return to $1.',
2529 'optin-success-in' => 'You are now trying out Beta.
2630 You can opt back out at any time by clicking the "{{int:optin-leave}}" link on the top of the screen.',
2731 'optin-leave-cancel' => 'If you would like to continue using Beta, you can return to $1.',
2832 'optin-success-out' => 'You have successfully left Beta.
2933 You can try it out again at anytime by clicking the "{{int:optin-try}}" link on the top right of the screen.',
 34+ 'optin-success-feedback' => 'Thank you for your feedback!',
3035 'optin-accept-short' => 'Let\'s do it!',
3136 'optin-accept-long' => 'Try out Beta',
3237 'optin-accept-long-anon' => 'Log in and try out Beta',
3338 'optin-deny-short' => 'No thank you',
3439 'optin-deny-long' => 'Return to previous page',
3540 'optin-submit-out' => 'Leave Beta',
 41+ 'optin-submit-feedback' => 'Give feedback',
3642 'optin-try' => 'Try Beta',
3743 'optin-leave' => 'Leave Beta',
 44+ 'optin-feedback' => 'Give feedback',
3845 'optin-survey-yes' => 'Yes',
3946 'optin-survey-no' => 'No',
4047 'optin-survey-intro' => "Thank you for trying Beta.
@@ -52,6 +59,7 @@
5360 'optin-survey-question-techfail-ifyes' => 'If yes, please elaborate or explain:',
5461 'optin-survey-question-usedtoolbar' => 'Did you use the new expandable toolbar to edit a page?',
5562 'optin-survey-question-usedtoolbar-ifyes' => 'If yes, what did you like about it? What did you dislike about it?',
 63+ 'optin-survey-question-usedtoolbar-ifno' => 'If no, why not? Will you in the future? Please explain.',
5664 'optin-survey-question-different' => 'What could we have done differently to keep you using our Beta?',
5765 'optin-survey-question-feedback' => 'Please let us know about any other comments, concerns or thoughts you have for us - all feedback is useful!:',
5866 'optin-survey-question-browser' => 'Which browser do you use?',
@@ -77,6 +85,15 @@
7886 'optin-survey-answer-os-linux' => 'Linux',
7987 'optin-survey-answer-os-other' => 'Other operating system:',
8088 'optin-survey-question-res' => 'What is the resolution of your screen?',
 89+ 'optin-survey-question-changes' => 'What changes would you like to see in the Beta in the future (select up to three)?',
 90+ 'optin-survey-answer-changes-nav' => 'Make the overall navigation of the site easier to use.',
 91+ 'optin-survey-answer-changes-edittools' => 'Increase and enhance the editing tools.',
 92+ 'optin-survey-answer-changes-upload' => 'Improve content and media uploads.',
 93+ 'optin-survey-answer-changes-richtext' => 'Develop editing tools similar to rich-text editors.',
 94+ 'optin-survey-answer-changes-lookfeel' => 'Update the "look and feel" of the site.',
 95+ 'optin-survey-answer-changes-predictability' => 'Improve predictability of performance.',
 96+ 'optin-survey-answer-changes-compat' => 'Improve compatibility with local wiki.',
 97+ 'optin-survey-answer-changes-other' => 'Other:',
8198 'optin-improvements' => "== What has been improved? ==
8299 [[File:UsabilityNavigation.png|right]]
83100 ;Enhanced navigation

Status & tagging log