r86967 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86966‎ | r86967 | r86968 >
Date:18:49, 26 April 2011
Author:nimishg
Status:reverted (Comments)
Tags:
Comment:
moved CustomUserSignup extension from trunk
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.hooks.php (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.i18n.php (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.php (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserTemplate.php (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/README (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/modules (added) (history)
  • /branches/wmf/1.17wmf1/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js (added) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.i18n.php
@@ -0,0 +1,17 @@
 2+<?php
 3+/**
 4+ * Internationalization file for the CustomUserSignup extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Nimish Gautam
 14+ */
 15+$messages['en'] = array(
 16+ 'customusersignup' => 'Custom User Signup',
 17+ 'customusersignup-desc' => 'Allows for customizable messages during the account creation process',
 18+);
\ No newline at end of file
Property changes on: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.i18n.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.php
@@ -0,0 +1,49 @@
 2+<?php
 3+/**
 4+ * CustomUserSignup extension -- allows for customizable messages during the
 5+ * account creation process
 6+ *
 7+ * @file
 8+ * @ingroup Extensions
 9+ * @version 0.1.0
 10+ * @author Nimish Gautam
 11+ * @link http://www.mediawiki.org/wiki/Extension:CustomUserSignup Documentation
 12+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+ */
 14+
 15+if ( !defined( 'MEDIAWIKI' ) ) {
 16+ die( 'This is not a valid entry point to MediaWiki.' );
 17+}
 18+
 19+// Extension credits that will show up on Special:Version
 20+$wgExtensionCredits['other'][] = array(
 21+ 'path' => __FILE__,
 22+ 'name' => 'CustomUserSignup',
 23+ 'author' => 'Nimish Gautam',
 24+ 'version' => '0.1.0',
 25+ 'descriptionmsg' => 'customusersignup-desc',
 26+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CustomUserSignup'
 27+);
 28+
 29+// Autoloading
 30+$dir = dirname( __FILE__ ) . '/';
 31+$wgAutoloadClasses['CustomUserSignupHooks'] = $dir . 'CustomUserSignup.hooks.php';
 32+$wgAutoloadClasses['CustomUserloginTemplate'] = $dir . 'CustomUserTemplate.php';
 33+$wgAutoloadClasses['CustomUsercreateTemplate'] = $dir . 'CustomUserTemplate.php';
 34+$wgExtensionMessagesFiles['CustomUserSignup'] = $dir . 'CustomUserSignup.i18n.php';
 35+
 36+// Hooks
 37+$wgHooks['UserCreateForm'][] = 'CustomUserSignupHooks::userCreateForm';
 38+$wgHooks['UserLoginForm'][] = 'CustomUserSignupHooks::userCreateForm';
 39+$wgHooks['BeforeWelcomeCreation'][] = 'CustomUserSignupHooks::welcomeScreen';
 40+
 41+// NOTE: This hook includes JS for the account creation project
 42+$wgHooks['BeforePageDisplay'][] = 'CustomUserSignupHooks::beforePageDisplay';
 43+$wgHooks['AddNewAccount'][] = 'CustomUserSignupHooks::addNewAccount';
 44+
 45+
 46+$wgCustomUserSignupVersion = 1;
 47+$wgCustomUserSignupSetBuckets = true;
 48+// For Account Creation Project
 49+ClickTrackingHooks::addCampaign($dir. 'modules', 'CustomUserSignup/modules', 'AccountCreationUserBucket' );
 50+
Property changes on: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.php
___________________________________________________________________
Added: svn:eol-style
151 + native
Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.hooks.php
@@ -0,0 +1,145 @@
 2+<?php
 3+/**
 4+ * Hooks for CustomUserSignup
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class CustomUserSignupHooks {
 11+
 12+ public static function getCampaign(){
 13+ global $wgRequest;
 14+ $campaign = "";
 15+ if( $wgRequest->getVal( 'campaign' ) ) {
 16+ preg_match( '/[A-Za-z0-9]+/', $wgRequest->getVal( 'campaign' ), $matches );
 17+ $campaign = $matches[0];
 18+ }
 19+ return $campaign;
 20+ }
 21+
 22+
 23+ public static function userCreateForm( &$template ) {
 24+ global $wgRequest, $wgCustomUserSignupVersion, $wgCustomUserSignupSetBuckets;
 25+ $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
 26+
 27+ $newTemplate;
 28+ $linkmsg;
 29+
 30+ $campaign = CustomUserSignupHooks::getCampaign();
 31+ if( $campaign != "" ) {
 32+
 33+ if( $template instanceof UserloginTemplate ) {
 34+ $newTemplate = new CustomUserloginTemplate();
 35+ $linkmsg = 'nologin';
 36+ $template->data['action'] = "{$template->data['action']}&campaign=$campaign";
 37+ $template->data['link'] =
 38+ preg_replace(
 39+ '/type\=signup/',
 40+ "campaign=$campaign&amp;type=signup",
 41+ $template->data['link']
 42+ );
 43+ } elseif( $template instanceof UsercreateTemplate ) {
 44+ $newTemplate = new CustomUsercreateTemplate();
 45+ $linkmsg = 'gotaccount';
 46+ $template->data['action'] = "{$template->data['action']}&campaign=$campaign";
 47+ $template->data['link'] =
 48+ preg_replace(
 49+ '/type\=login\&amp;/',
 50+ "type=login&amp;campaign=$campaign&amp;",
 51+ $template->data['link']
 52+ );
 53+ } else {
 54+ return true;
 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+
 66+ // replace "gotaccount" and "nologin" links
 67+ if( $template->data['link'] != '' ) {
 68+
 69+ // get the link part of the message
 70+ $originalLinkFull = $template->data['link'];
 71+ $originalLinkMessage = wfMsg( $linkmsg );
 72+
 73+ $leftOfLink = substr($originalLinkMessage, 0, strpos($originalLinkMessage, '$1'));
 74+
 75+ $linkq = substr($originalLinkFull, strlen($leftOfLink)+9 );
 76+ $linkq = substr($linkq, 0, strpos($linkq, '">'));
 77+
 78+ $link = '<a href="' . $linkq . '">';
 79+
 80+ if( wfMessage( "customusertemplate-$campaign-$linkmsg".'link' )->exists() ){
 81+ $link .= wfMsgHtml( "customusertemplate-$campaign-$linkmsg" . 'link' );
 82+ } else {
 83+ $link .= wfMsgHtml( $linkmsg . 'link' );
 84+ }
 85+ $link .= '</a>';
 86+
 87+ if( wfMessage( "customusertemplate-$campaign-$linkmsg" )->exists() ){
 88+ $template->set( 'link', wfMsgExt( "customusertemplate-$campaign-$linkmsg", array( 'parseinline', 'replaceafter' ), $link ) );
 89+ } else {
 90+ $template->set( 'link', wfMsgExt( $linkmsg, array( 'parseinline', 'replaceafter' ), $link ) );
 91+ }
 92+
 93+ }
 94+
 95+ $newTemplate->data = $template->data;
 96+ $newTemplate->translator = $template->translator;
 97+ $template = $newTemplate;
 98+ }
 99+
 100+ return true;
 101+ }
 102+
 103+ public static function welcomeScreen( &$welcomeCreationMsg, &$injected_html ) {
 104+ global $wgRequest;
 105+ $campaign = CustomUserSignupHooks::getCampaign();
 106+ if( $campaign != "" ) {
 107+ if( wfMessage( "customusertemplate-$campaign-welcomecreation" )->exists() ) {
 108+ $welcomeCreationMsg = "customusertemplate-$campaign-welcomecreation";
 109+ }
 110+ }
 111+ return true;
 112+ }
 113+
 114+ public static function beforePageDisplay( $out, $skin ) {
 115+ $out->addModules( 'ext.UserBuckets' );
 116+ return true;
 117+ }
 118+
 119+ public static function addNewAccount( $user, $byEmail ){
 120+ global $wgRequest, $wgTitle;
 121+ $buckets = ClickTrackingHooks::unpackBucketInfo();
 122+ if(isset($buckets['AccountCreation']) && $buckets['AccountCreation'][0] != "none"){
 123+
 124+ // *NOT HTTPONLY* In fact, that's the point of this cookie
 125+
 126+ setcookie( 'acctcreation' , $buckets['AccountCreation'][0] ,
 127+ time() + 60 * 60 * 24 * 365 );
 128+
 129+ $session = $wgRequest->getCookie( 'clicktrackingsession', "" );
 130+ if ( $session !== null ) {
 131+ $params = new FauxRequest( array(
 132+ 'action' => 'clicktracking',
 133+ 'eventid' => 'account-created',
 134+ 'token' => $session,
 135+ 'info' => 'account-activity',
 136+ 'namespacenumber' => $wgTitle->getNamespace(),
 137+ ) );
 138+ $api = new ApiMain( $params, true );
 139+ $api->execute();
 140+ }
 141+
 142+ }
 143+ return true;
 144+ }
 145+
 146+}
\ No newline at end of file
Property changes on: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserSignup.hooks.php
___________________________________________________________________
Added: svn:eol-style
1147 + native
Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js
@@ -0,0 +1,118 @@
 2+//checks
 3+if(typeof(MW) == "undefined"){ MW={};}
 4+if(!MW.activeCampaigns){ MW.activeCampaigns ={}; }
 5+
 6+//define new active campaign
 7+MW.activeCampaigns.AccountCreation =
 8+
 9+{
 10+ //Treatment name
 11+ "name": "AccountCreation",
 12+
 13+ //Treatment version. Increment this when altering rates
 14+ "version": 1,
 15+
 16+ "preferences": {"setBuckets" : false },
 17+
 18+ // Rates are calculated out of the total sum, so
 19+ // rates of x:10000, y:3, and z:1 mean users have a
 20+ // chance of being in bucket x at 10000/10004,
 21+ // y at 3/10004 and z at 1/10004
 22+ // The algorithm is faster if these are ordered in descending order,
 23+ // particularly if there are orders of magnitude differences in the
 24+ // bucket sizes
 25+ // "none" is reserved for control
 26+ "rates": {"ACP1": 25, "ACP2": 25, "ACP3": 25, "none": 25},
 27+
 28+ // individual changes, function names corresponding
 29+ // to what is in "rates" object
 30+ // (note: "none" function not needed or used)
 31+
 32+ "ACP1": function(){
 33+ //change to NiceMsg1 campaign
 34+ $j("#pt-anonlogin a").each(function(){
 35+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP1" );
 36+ });
 37+ $j("#pt-login a").each(function(){
 38+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP1" );
 39+ });
 40+
 41+ },
 42+ "ACP2": function(){
 43+ //change to NiceMsg2 campaign
 44+ $j("#pt-anonlogin a").each(function(){
 45+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP2" );
 46+ });
 47+ $j("#pt-login a").each(function(){
 48+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP2" );
 49+ });
 50+ },
 51+
 52+ "ACP3": function(){
 53+ //change to NiceMsg2 campaign
 54+ $j("#pt-anonlogin a").each(function(){
 55+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP3" );
 56+ });
 57+ $j("#pt-login a").each(function(){
 58+ $j(this).attr("href", $j(this).attr("href") + "&campaign=ACP3" );
 59+ });
 60+ },
 61+
 62+ // "allActive" is reserved.
 63+ // If this function exists, it will be apply to every user not in the "none" bucket
 64+ "allActive": function(){
 65+
 66+ //track account creation attempts
 67+ $j("#wpCreateaccount").click(function(){ $j.trackAction('submit-signup-data'); });
 68+
 69+ //this is the "don't have an account? CREATE ONE" link
 70+ $j("#userloginlink").click(function(){ $j.trackAction('visit-signup'); });
 71+
 72+ if($j.cookie('acctcreation') ){
 73+ //add click tracking to preview
 74+ $j("#wpPreview").click(function(){ $j.trackAction('preview'); });
 75+
 76+ //add click tracking to save
 77+ $j("#wpSave").click(function(){ $j.trackAction('save'); });
 78+ }
 79+ },
 80+
 81+ "all": function(){
 82+ //add up all rates
 83+ var campaign = MW.activeCampaigns.AccountCreation;
 84+ if( $j.cookie('userbuckets') &&
 85+ $j.parseJSON( $j.cookie('userbuckets') )["AccountCreation"]){
 86+ var buckets = $j.parseJSON( $j.cookie('userbuckets') );
 87+
 88+ if(typeof(campaign[buckets[campaign.name][0]]) == "function"){
 89+ campaign[buckets[campaign.name][0]](); //function to execute
 90+ campaign.allActive();
 91+ return;
 92+ }
 93+ } else {
 94+ var bucketTotal = 0;
 95+ for ( var rate in campaign.rates ){
 96+ bucketTotal += campaign.rates[rate];
 97+ }
 98+
 99+ //give the user a random number in those rates
 100+ var currentUser = Math.floor(Math.random() * (bucketTotal+1));
 101+
 102+ // recurse through the rates until we get into the range the user falls in,
 103+ // assign them to that range
 104+ var prev_val = -1;
 105+ var next_val = 0;
 106+ for( rate in campaign.rates ){
 107+ next_val += campaign.rates[rate];
 108+ if(prev_val <= currentUser && currentUser < next_val){
 109+ if(rate != "none"){
 110+ campaign[rate]();
 111+ }
 112+ break;
 113+ }
 114+ prev_val = next_val;
 115+ }
 116+ }//else
 117+ }
 118+
 119+};
\ No newline at end of file
Property changes on: branches/wmf/1.17wmf1/extensions/CustomUserSignup/modules/AccountCreationUserBucket.js
___________________________________________________________________
Added: svn:eol-style
1120 + native
Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserTemplate.php
@@ -0,0 +1,94 @@
 2+<?php
 3+
 4+class CustomUserloginTemplate extends UserloginTemplate {
 5+
 6+ protected $campaign = null;
 7+
 8+ function __construct() {
 9+ global $wgRequest;
 10+ parent::__construct();
 11+ $this->campaign = CustomUserSignupHooks::getCampaign();
 12+ }
 13+
 14+ function msg( $str ) {
 15+ // exists
 16+ if( $this->campaign && wfMessage( "customusertemplate-{$this->campaign}-$str" )->exists() ) {
 17+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str", true );
 18+ } else {
 19+ parent::msg( $str );
 20+ }
 21+ }
 22+
 23+ function msgWiki( $str ) {
 24+ // exists
 25+ if( $this->campaign && wfMessage( "customusertemplate-{$this->campaign}-$str" )->exists() ) {
 26+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str", false );
 27+ } else {
 28+ parent::msgWiki( $str );
 29+ }
 30+ }
 31+
 32+ function msgWikiCustom( $str, $checkifplain ) {
 33+ global $wgParser, $wgOut;
 34+
 35+ $text = $this->translator->translate( $str );
 36+ $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
 37+ $wgOut->parserOptions(), true );
 38+ $parsedText = $parserOutput->getText();
 39+ if( $checkifplain &&
 40+ ( strlen(strip_tags($parsedText)) == (strlen($parsedText)-7) )) {
 41+ // the parser encapsulates text in <p></p> (7 chars) If these
 42+ // were the only chars added to the text, then it was plaintext
 43+ echo htmlspecialchars( $text );
 44+ } else {
 45+ echo $parsedText;
 46+ }
 47+ }
 48+
 49+}
 50+
 51+class CustomUsercreateTemplate extends UsercreateTemplate {
 52+ protected $campaign = null;
 53+
 54+ function __construct() {
 55+ global $wgRequest;
 56+ parent::__construct();
 57+ $this->campaign = CustomUserSignupHooks::getCampaign();
 58+ }
 59+
 60+ function msg( $str ) {
 61+ // exists
 62+ if( $this->campaign && wfMessage( "customusertemplate-{$this->campaign}-$str" )->exists() ) {
 63+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str", true );
 64+ } else {
 65+ parent::msg( $str );
 66+ }
 67+ }
 68+
 69+ function msgWiki( $str ) {
 70+ // exists
 71+ if( $this->campaign && wfMessage( "customusertemplate-{$this->campaign}-$str" )->exists() ) {
 72+ $this->msgWikiCustom( "customusertemplate-{$this->campaign}-$str", false );
 73+ } else {
 74+ parent::msgWiki( $str );
 75+ }
 76+ }
 77+
 78+ function msgWikiCustom( $str, $checkifplain ) {
 79+ global $wgParser, $wgOut;
 80+
 81+ $text = $this->translator->translate( $str );
 82+ $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
 83+ $wgOut->parserOptions(), true );
 84+ $parsedText = $parserOutput->getText();
 85+ if( $checkifplain &&
 86+ ( strlen(strip_tags($parsedText)) == (strlen($parsedText)-7) )) {
 87+ // the parser encapsulates text in <p></p> (7 chars) If these
 88+ // were the only chars added to the text, then it was plaintext
 89+ echo htmlspecialchars( $text );
 90+ } else {
 91+ echo $parsedText;
 92+ }
 93+ }
 94+
 95+}
\ No newline at end of file
Property changes on: branches/wmf/1.17wmf1/extensions/CustomUserSignup/CustomUserTemplate.php
___________________________________________________________________
Added: svn:eol-style
196 + native
Index: branches/wmf/1.17wmf1/extensions/CustomUserSignup/README
@@ -0,0 +1,8 @@
 2+This extension lets you customize the messages seen in the user login process based on passing a "campaign" variable
 3+in to the Special:UserLogin page.
 4+
 5+So, if you append "&campaign={campaign}" to the user login process, any message created in includes/templates/Userlogin.php can be
 6+overridden with MediaWiki:customusertemplate-{campaign}-{message}.
 7+
 8+ex: If you wanted to change the text seen at the end of the signup page (a message called 'signupend') for users signing up from
 9+the "foo" campaign, you would edit MediaWiki:customusertemplate-foo-signupend page, and this would be substituted
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r86968Register Custom User Signup for Translate....raymond18:54, 26 April 2011
r869841.17wmf1: Deleting CustomUserSignup so I can recreate it properly. See CR on ...catrope20:24, 26 April 2011

Comments

#Comment by Reedy (talk | contribs)   20:19, 26 April 2011

You should really do SVN copy for these sorts of things, to begin with at least

#Comment by Catrope (talk | contribs)   20:27, 26 April 2011

Fixed in r86984 and r86986.

Status & tagging log