r86685 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86684‎ | r86685 | r86686 >
Date:00:38, 22 April 2011
Author:nimishg
Status:deferred
Tags:
Comment:
changed behavior or account creation buckets to only give cookies to people who enter the account creation process
Modified paths:
  • /trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php (modified) (history)
  • /trunk/extensions/CustomUserSignup/CustomUserSignup.php (modified) (history)
  • /trunk/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CustomUserSignup/CustomUserSignup.php
@@ -42,6 +42,8 @@
4343 $wgHooks['AddNewAccount'][] = 'CustomUserSignupHooks::addNewAccount';
4444
4545
 46+$wgCustomUserSignupVersion = 1;
 47+$wgCustomUserSignupSetBuckets = true;
4648 // For Account Creation Project
4749 ClickTrackingHooks::addCampaign($dir. 'modules', 'CustomUserSignup/modules', 'AccountCreationUserBucket' );
4850
Index: trunk/extensions/CustomUserSignup/CustomUserSignup.hooks.php
@@ -20,7 +20,7 @@
2121
2222
2323 public static function userCreateForm( &$template ) {
24 - global $wgRequest;
 24+ global $wgRequest, $wgCustomUserSignupVersion, $wgCustomUserSignupSetBuckets;
2525 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
2626
2727 $newTemplate;
@@ -28,6 +28,7 @@
2929
3030 $campaign = CustomUserSignupHooks::getCampaign();
3131 if( $campaign != "" ) {
 32+
3233 if( $template instanceof UserloginTemplate ) {
3334 $newTemplate = new CustomUserloginTemplate();
3435 $linkmsg = 'nologin';
@@ -52,6 +53,15 @@
5354 return true;
5455 }
5556
 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+
5666 // replace "gotaccount" and "nologin" links
5767 if( $template->data['link'] != '' ) {
5868
Index: trunk/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js
@@ -13,6 +13,8 @@
1414 //Treatment version. Increment this when altering rates
1515 "version": 1,
1616
 17+ "preferences": {"setBuckets" : false },
 18+
1719 // Rates are calculated out of the total sum, so
1820 // rates of x:10000, y:3, and z:1 mean users have a
1921 // chance of being in bucket x at 10000/10004,
@@ -59,8 +61,44 @@
6062 //add click tracking to save
6163 $j("#wpSave").click(function(){ $j.trackAction('save'); });
6264 }
 65+ },
6366
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+ }
66104
67105 };
\ No newline at end of file

Status & tagging log