Index: trunk/extensions/CustomUserSignup/CustomUserSignup.php |
— | — | @@ -42,6 +42,8 @@ |
43 | 43 | $wgHooks['AddNewAccount'][] = 'CustomUserSignupHooks::addNewAccount'; |
44 | 44 | |
45 | 45 | |
| 46 | +$wgCustomUserSignupVersion = 1; |
| 47 | +$wgCustomUserSignupSetBuckets = true; |
46 | 48 | // For Account Creation Project |
47 | 49 | ClickTrackingHooks::addCampaign($dir. 'modules', 'CustomUserSignup/modules', 'AccountCreationUserBucket' ); |
48 | 50 | |
Index: trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | |
22 | 22 | |
23 | 23 | public static function userCreateForm( &$template ) { |
24 | | - global $wgRequest; |
| 24 | + global $wgRequest, $wgCustomUserSignupVersion, $wgCustomUserSignupSetBuckets; |
25 | 25 | $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); |
26 | 26 | |
27 | 27 | $newTemplate; |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | |
30 | 30 | $campaign = CustomUserSignupHooks::getCampaign(); |
31 | 31 | if( $campaign != "" ) { |
| 32 | + |
32 | 33 | if( $template instanceof UserloginTemplate ) { |
33 | 34 | $newTemplate = new CustomUserloginTemplate(); |
34 | 35 | $linkmsg = 'nologin'; |
— | — | @@ -52,6 +53,15 @@ |
53 | 54 | return true; |
54 | 55 | } |
55 | 56 | |
| 57 | + //set bucket if not set already |
| 58 | + if( $wgCustomUserSignupSetBuckets && $wgRequest->getCookie('UserName') == NULL ){ //do not put users who already have a username in a bucket |
| 59 | + $buckets = ClickTrackingHooks::unpackBucketInfo(); |
| 60 | + if( !isset($buckets["AccountCreation"]) || $buckets["AccountCreation"][1] < $wgCustomUserSignupVersion ){ |
| 61 | + $buckets["AccountCreation"] = array($campaign, $wgCustomUserSignupVersion); |
| 62 | + ClickTrackingHooks::packBucketInfo($buckets); |
| 63 | + } |
| 64 | + } |
| 65 | + |
56 | 66 | // replace "gotaccount" and "nologin" links |
57 | 67 | if( $template->data['link'] != '' ) { |
58 | 68 | |
Index: trunk/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js |
— | — | @@ -13,6 +13,8 @@ |
14 | 14 | //Treatment version. Increment this when altering rates |
15 | 15 | "version": 1, |
16 | 16 | |
| 17 | + "preferences": {"setBuckets" : false }, |
| 18 | + |
17 | 19 | // Rates are calculated out of the total sum, so |
18 | 20 | // rates of x:10000, y:3, and z:1 mean users have a |
19 | 21 | // chance of being in bucket x at 10000/10004, |
— | — | @@ -59,8 +61,44 @@ |
60 | 62 | //add click tracking to save |
61 | 63 | $j("#wpSave").click(function(){ $j.trackAction('save'); }); |
62 | 64 | } |
| 65 | + }, |
63 | 66 | |
64 | | - |
65 | | - } |
| 67 | + "all": function(){ |
| 68 | + //add up all rates |
| 69 | + var campaign = MW.activeCampaigns.AccountCreation; |
| 70 | + if( $j.cookie('userbuckets') && |
| 71 | + $j.parseJSON( $j.cookie('userbuckets') )["AccountCreation"]){ |
| 72 | + var buckets = $j.parseJSON( $j.cookie('userbuckets') ); |
| 73 | + |
| 74 | + if(typeof(campaign[buckets[campaign.name][0]]) == "function"){ |
| 75 | + campaign[buckets[campaign.name][0]](); //function to execute |
| 76 | + campaign.allActive(); |
| 77 | + return; |
| 78 | + } |
| 79 | + } else { |
| 80 | + var bucketTotal = 0; |
| 81 | + for ( var rate in campaign.rates ){ |
| 82 | + bucketTotal += campaign.rates[rate]; |
| 83 | + } |
| 84 | + |
| 85 | + //give the user a random number in those rates |
| 86 | + var currentUser = Math.floor(Math.random() * (bucketTotal+1)); |
| 87 | + |
| 88 | + // recurse through the rates until we get into the range the user falls in, |
| 89 | + // assign them to that range |
| 90 | + var prev_val = -1; |
| 91 | + var next_val = 0; |
| 92 | + for( rate in campaign.rates ){ |
| 93 | + next_val += campaign.rates[rate]; |
| 94 | + if(prev_val <= currentUser && currentUser < next_val){ |
| 95 | + if(rate != "none"){ |
| 96 | + campaign[rate](); |
| 97 | + } |
| 98 | + break; |
| 99 | + } |
| 100 | + prev_val = next_val; |
| 101 | + } |
| 102 | + }//else |
| 103 | + } |
66 | 104 | |
67 | 105 | }; |
\ No newline at end of file |