r96895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96894‎ | r96895 | r96896 >
Date:20:13, 12 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r96890; fixed some logic fails
Modified paths:
  • /trunk/extensions/Survey/resources/ext.survey.tag.js (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -86,7 +86,7 @@
8787
8888 $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) );
8989
90 - foreach ( array( 'user_type', 'ratio', 'min_pages' ) as $field ) {
 90+ foreach ( array( 'user_type', 'ratio', 'min_pages', 'expiry' ) as $field ) {
9191 $survey->setField( $field, $wgRequest->getInt( 'survey-' . $field ) );
9292 }
9393
@@ -203,6 +203,13 @@
204204 );
205205
206206 $fields[] = array(
 207+ 'type' => 'hidden',
 208+ 'default' => $survey->getField( 'expiry' ),
 209+ 'name' => 'survey-expiry',
 210+ 'id' => 'survey-expiry',
 211+ );
 212+
 213+ $fields[] = array(
207214 'class' => 'SurveyNameField',
208215 'default' => $survey->getField( 'name' ),
209216 'label-message' => 'survey-special-label-name',
Index: trunk/extensions/Survey/resources/ext.survey.tag.js
@@ -10,21 +10,10 @@
1111
1212 function getCookieName( options ) {
1313 return ( typeof options.id !== 'undefined' ) ?
14 - 'ssurvey-id-' + options.id
15 - : 'ssurvey-name-' + options.name
 14+ 'survey-id-' + options.id
 15+ : 'survey-name-' + options.name
1616 }
1717
18 - function shouldShowSurvey( options ) {
19 - if ( !options.cookie ) {
20 - return true;
21 - }
22 - else {
23 - var cookie = getCookie( options );
24 - return ( options.pages === 0 && cookie !== 'done' )
25 - || ( options.pages !== 0 && parseInt( cookie ) >= options.pages );
26 - }
27 - }
28 -
2918 function getCookie( options ) {
3019 var cookie = $.cookie( getCookieName( options ) );
3120 survey.log( 'read "' + cookie + '" from cookie ' + getCookieName( options ) );
@@ -58,7 +47,7 @@
5948 var options = {
6049 'ratio': typeof ratioAttr === 'undefined' ? 1 : parseFloat( ratioAttr ) / 100,
6150 'cookie': $tag.attr( 'survey-data-cookie' ) !== 'no',
62 - 'expiry': typeof expiryAttr === 'undefined' ? 60 * 60 * 24 * 30 : 60 * 60 * 24 * 30,//parseInt( expiryAttr ),
 51+ 'expiry': typeof expiryAttr === 'undefined' ? 60 * 60 * 24 * 30 : parseInt( expiryAttr ),
6352 'pages': typeof pagesAttr === 'undefined' ? 0 : parseInt( pagesAttr )
6453 };
6554
@@ -72,18 +61,27 @@
7362 return;
7463 }
7564
76 - if ( hasCookie( options ) || winsLottery( options ) ) {
77 - if ( shouldShowSurvey( options ) ) {
 65+ if ( hasCookie( options ) || options.ratio === 1 || winsLottery( options ) ) {
 66+ if ( !options.cookie ) {
7867 $tag.mwSurvey( options );
79 - setCookie( options, 'done' );
8068 }
81 - else if ( options.pages !== 0 ) {
82 - var nr = parseInt( getCookie( options ) );
83 - setCookie( options, ( isNaN( nr ) ? 0 : nr ) + 1 )
 69+ else {
 70+ var cookie = getCookie( options );
 71+
 72+ if ( cookie !== 'done' ) {
 73+ if ( ( options.pages === 0 || parseInt( cookie ) >= options.pages ) ) {
 74+ $tag.mwSurvey( options );
 75+ setCookie( options, 'done' );
 76+ }
 77+ else if ( options.pages !== 0 ) {
 78+ var nr = parseInt( getCookie( options ) );
 79+ setCookie( options, ( isNaN( nr ) ? 0 : nr ) + 1 )
 80+ }
 81+ }
8482 }
8583 }
8684 else {
87 - onSurveyDone( options );
 85+ setCookie( options, 'done' );
8886 }
8987 }
9088

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96890follow up to r96855; adding js for min_pages settingjeroendedauw19:46, 12 September 2011

Status & tagging log