r98081 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98080‎ | r98081 | r98082 >
Date:20:13, 25 September 2011
Author:ashley
Status:deferred (Comments)
Tags:
Comment:
New extension that adds a checkbox to Special:UserLogin/signup and requires users to check it in order for their account to be created (ping bug #28107).
This extension is required if you have a wiki with SocialProfile extension and you want to give out points to users for referring new users to the wiki.
Modified paths:
  • /trunk/extensions/NewSignupPage (added) (history)
  • /trunk/extensions/NewSignupPage/NewSignupPage.i18n.php (added) (history)
  • /trunk/extensions/NewSignupPage/NewSignupPage.php (added) (history)
  • /trunk/extensions/NewSignupPage/user_register_track.sql (added) (history)

Diff [purge]

Index: trunk/extensions/NewSignupPage/NewSignupPage.i18n.php
@@ -0,0 +1,121 @@
 2+<?php
 3+/**
 4+ * Internationalization file for NewSignupPage extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English */
 13+$messages['en'] = array(
 14+ // Social tools
 15+ 'login-reg-recruited' => 'recruited <a href="$1">$2</a>',
 16+ // Text displayed next to the checkbox
 17+ 'shoutwiki-loginform-tos' => 'I am over 13 years of age and I have read, understood and agree to be bound by the <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Terms of Service</a> and <a href="http://www.shoutwiki.com/wiki/Privacy_policy">Privacy Policy</a>',
 18+ // Error message if the user doesn't accept the site's Terms of Service
 19+ 'shoutwiki-must-accept-tos' => "You must accept the site's Terms of Service in order to be able to create an account!",
 20+ // For Special:ListGroupRights
 21+ 'right-bypasstoscheck' => "Create new accounts without accepting the site's Terms of Service",
 22+);
 23+
 24+/** Czech (Česky) */
 25+$messages['cz'] = array(
 26+ 'shoutwiki-loginform-tos' => 'Já jsem přes 13 let a jsem si přečetl, pochopil a souhlasíte, že budete vázáni <a href="http://www.shoutwiki.com/wiki/Terms_of_use">podmínkami služby</a> a <a href="http://www.shoutwiki.com/wiki/Privacy_policy">ochrany soukromí</a>',
 27+ 'shoutwiki-must-accept-tos' => 'Musíte uznat stránek jde o služby, aby bylo možné vytvořit účet!',
 28+);
 29+
 30+/** Danish (Dansk) */
 31+$messages['da'] = array(
 32+ 'shoutwiki-loginform-tos' => 'Jeg er over 13 år og jeg har læst, forstået og accepterer at være bundet af <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Servicevilkår</a> og <a href="http://www.shoutwiki.com/wiki/Privacy_policy">behandling af personlige oplysninger</a>',
 33+ 'shoutwiki-must-accept-tos' => 'Du skal acceptere webstedets hensyn til service for at kunne oprette en konto!',
 34+);
 35+
 36+/** German (Deutsch) */
 37+$messages['de'] = array(
 38+ 'shoutwiki-loginform-tos' => 'Ich bin über 13 Jahre alt und ich habe gelesen, verstanden und stimmen zu, die <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Nutzungsbedingungen</a> und <a href="http://www.shoutwiki.com/wiki/Privacy_policy">Datenschutzbestimmungen</a>',
 39+ 'shoutwiki-must-accept-tos' => 'Sie müssen akzeptieren, die Website-Nutzungsbedingungen, um in der Lage, ein Konto erstellen!',
 40+);
 41+
 42+/** Greek (Ελληνικά) */
 43+$messages['el'] = array(
 44+ 'shoutwiki-loginform-tos' => 'Είμαι πάνω από 13 ετών και έχω διαβάσει, κατανοήσει και συμφωνήσει να δεσμεύεται από <a href="http://www.shoutwiki.com/wiki/Terms_of_use">τους Όρους Υπηρεσίας</a> και την <a href="http://www.shoutwiki.com/wiki/Privacy_policy">πολιτική προστασίας προσωπικών δεδομένων</a>',
 45+ 'shoutwiki-must-accept-tos' => 'Πρέπει να αποδεχτείτε την ιστοσελίδα της Όροι Υπηρεσίας, προκειμένου να μπορέσει να δημιουργήσει ένα λογαριασμό!',
 46+);
 47+
 48+/** Spanish (Español) */
 49+$messages['es'] = array(
 50+ 'shoutwiki-loginform-tos' => 'Soy mayor de 13 años de edad y he leído, entendido y acepta quedar obligado por los <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Términos de servicio</a> y la <a href="http://www.shoutwiki.com/wiki/Privacy_policy">Política de privacidad</a>',
 51+ 'shoutwiki-must-accept-tos' => 'Debes aceptar los términos del sitio del servicio con el fin de poder crear una cuenta!',
 52+);
 53+
 54+/** Finnish (Suomi) */
 55+$messages['fi'] = array(
 56+ 'login-reg-recruited' => 'värväsi käyttäjän <a href="$1">$2</a>',
 57+ 'shoutwiki-loginform-tos' => 'Olen yli 13-vuotias ja olen lukenut, ymmärtänyt ja sitoutunut noudattamaan <a href="http://www.shoutwiki.com/wiki/Terms_of_use">käyttöehtoja</a> ja <a href="http://www.shoutwiki.com/wiki/Privacy_policy">tietosuojakäytäntöä</a>',
 58+ 'shoutwiki-must-accept-tos' => 'Sinun tulee hyväksyä sivuston käyttöehdot voidaksesi luoda tunnuksen!',
 59+ 'right-bypasstoscheck' => 'Luoda uusia tunnuksia hyväksymättä sivuston käyttöehtoja',
 60+);
 61+
 62+/** French (Français) */
 63+$messages['fr'] = array(
 64+ 'shoutwiki-loginform-tos' => "Je suis de plus de 13 ans et j'ai lu, compris et accepté d'être lié par les <a href=\"http://www.shoutwiki.com/wiki/Terms_of_use\">Conditions d'utilisation</a> et <a href=\"http://www.shoutwiki.com/wiki/Privacy_policy\">politique de confidentialité</a>",
 65+ 'shoutwiki-must-accept-tos' => "Vous devez accepter les présentes Conditions de service afin d'être en mesure de créer un compte !",
 66+);
 67+
 68+/** Italian (Italiano) */
 69+$messages['it'] = array(
 70+ 'shoutwiki-loginform-tos' => 'Sono oltre 13 anni di età e che ho letto, capito ed accetti di essere vincolato dai <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Termini di servizio</a> e <a href="http://www.shoutwiki.com/wiki/Privacy_policy">policy sulla privacy</a>',
 71+ 'shoutwiki-must-accept-tos' => 'È necessario accettare il sito Termini e condizioni del servizio, al fine di essere in grado di creare un account!',
 72+);
 73+
 74+/** Japanese (日本語) */
 75+$messages['ja'] = array(
 76+ 'shoutwiki-loginform-tos' => '私は年齢13歳以上ですと私は、読んだことを理解し、同意に拘束されることには、 <a href="http://www.shoutwiki.com/wiki/Terms_of_use">利用規約</a> 、 <a href="http://www.shoutwiki.com/wiki/Privacy_policy">プライバシーポリシー</a>',
 77+);
 78+
 79+/** Korean (한국어) */
 80+$messages['ko'] = array(
 81+ 'shoutwiki-loginform-tos' => '내가 나이이고 13 년 이상을 읽고 이해하고 동의에 의해 구속 수있는 <a href="http://www.shoutwiki.com/wiki/Terms_of_use">서비스 약관</a>과 <a href="http://www.shoutwiki.com/wiki/Privacy_policy">개인 정보 보호 정책</a>',
 82+);
 83+
 84+/** Dutch (Nederlands)
 85+ * @author Mitchel Corstjens
 86+ */
 87+$messages['nl'] = array(
 88+ 'login-reg-recruited' => 'rekruteerde <a href="$1">$2</a>',
 89+ 'shoutwiki-loginform-tos' => 'Ik ben ouder dan 13 jaar en heb de <a href="http://www.shoutwiki.com/wiki/Terms_of_use">gebruiks overeenkomst</a> en de <a href="http://www.shoutwiki.com/wiki/Privacy_policy">Privacy Policy</a> gelezen en ga hier mee akkoord',
 90+ 'shoutwiki-must-accept-tos' => 'Je moet akkoord gaan met de gebruiks overeenkomst van de site om een account aan te kunnen maken!',
 91+ 'right-bypasstoscheck' => "Creëer een nieuwe account zonder akkoord te gaan met de gebruiks overeenkomst",
 92+);
 93+
 94+/** Norwegian (Norsk) */
 95+$messages['no'] = array(
 96+ 'shoutwiki-loginform-tos' => 'Jeg er over 13 år og jeg har lest, forstått og aksepterer å være bundet av <a href="http://www.shoutwiki.com/wiki/Terms_of_use">vilkår for bruk</a> og <a href="http://www.shoutwiki.com/wiki/Privacy_policy">personvernerklæring</a>',
 97+ 'shoutwiki-must-accept-tos' => 'Du må godta nettstedets Vilkår for bruk for å kunne opprette en konto!',
 98+);
 99+
 100+/** Portuguese (Português) */
 101+$messages['pt'] = array(
 102+ 'shoutwiki-loginform-tos' => 'Tenho mais de 13 anos de idade e eu tenho lido, entendido e concordado em se comprometer com o <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Termos de Serviço</a> e <a href="http://www.shoutwiki.com/wiki/Privacy_policy">política de privacidade</a>',
 103+ 'shoutwiki-must-accept-tos' => 'Você precisa aceitar os Termos de Serviço do site, a fim de ser capaz de criar uma conta!',
 104+);
 105+
 106+/** Romanian (Română) */
 107+$messages['ro'] = array(
 108+ 'shoutwiki-loginform-tos' => 'Eu sunt peste 13 de ani şi am citit, înţeles şi sunt de acord să fie obligat de către <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Termeni si conditii</a> şi <a href="http://www.shoutwiki.com/wiki/Privacy_policy">Politica de confidentialitate</a>',
 109+ 'shoutwiki-must-accept-tos' => 'Trebuie să acceptaţi al site-ului Termeni de furnizare a serviciilor pentru a putea fi capabile de a crea un cont!',
 110+);
 111+
 112+/** Russian (Русский) */
 113+$messages['ru'] = array(
 114+ 'shoutwiki-loginform-tos' => 'Я старше 13 лет, и я прочитал, понял и согласен быть связанными <a href="http://www.shoutwiki.com/wiki/Terms_of_use">Условия предоставления услуг</a> и <a href="http://www.shoutwiki.com/wiki/Privacy_policy">политика конфиденциальности</a>',
 115+ 'shoutwiki-must-accept-tos' => 'Вы должны согласиться с сайта Условия предоставления услуг, с тем чтобы иметь возможность создать учетную запись!',
 116+);
 117+
 118+/** Swedish (Svenska) */
 119+$messages['sv'] = array(
 120+ 'shoutwiki-loginform-tos' => 'Jag är över 13 år och jag har läst, förstått och samtycker till att vara bunden av <a href="http://www.shoutwiki.com/wiki/Terms_of_use">användarvillkor</a> och <a href="http://www.shoutwiki.com/wiki/Privacy_policy">sekretessvillkor</a>',
 121+ 'shoutwiki-must-accept-tos' => 'Du måste godkänna webbplats användarvillkoren för att kunna skapa ett konto!',
 122+);
\ No newline at end of file
Property changes on: trunk/extensions/NewSignupPage/NewSignupPage.i18n.php
___________________________________________________________________
Added: svn:eol-style
1123 + native
Index: trunk/extensions/NewSignupPage/NewSignupPage.php
@@ -0,0 +1,209 @@
 2+<?php
 3+/**
 4+ * NewSignupPage extension for MediaWiki -- enhances the default signup form
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @version 0.4.1
 9+ * @author Jack Phoenix <jack@countervandalism.net>
 10+ * @copyright Copyright © 2008-2011 Jack Phoenix
 11+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 12+ * @note Uses GPL-licensed code from LoginReg extension (functions
 13+ * fnRegisterAutoAddFriend and fnRegisterTrack)
 14+ */
 15+
 16+/**
 17+ * Protect against register_globals vulnerabilities.
 18+ * This line must be present before any global variable is referenced.
 19+ */
 20+if ( !defined( 'MEDIAWIKI' ) ) {
 21+ die( "This is not a valid entry point.\n" );
 22+}
 23+
 24+// Extension credits that will show up on Special:Version
 25+$wgExtensionCredits['other'][] = array(
 26+ 'name' => 'New Signup Page',
 27+ 'author' => 'Jack Phoenix',
 28+ 'version' => '0.4.1',
 29+ 'url' => 'http://www.mediawiki.org/wiki/Extension:NewSignupPage',
 30+ 'description' => 'Adds new features to [[Special:UserLogin/signup|signup form]]',
 31+);
 32+
 33+// Internationalization file
 34+$wgExtensionMessagesFiles['NewSignupPage'] = dirname( __FILE__ ) . '/NewSignupPage.i18n.php';
 35+
 36+// New user right, allows bypassing the ToS check on signup form
 37+$wgAvailableRights[] = 'bypasstoscheck';
 38+
 39+// Hooked functions
 40+$wgHooks['AbortNewAccount'][] = 'efTermsOfServiceAbortNewAccount';
 41+$wgHooks['UserCreateForm'][] = 'efTermsOfServiceOnSignup';
 42+
 43+// Function that conditionally enables some hooks
 44+$wgExtensionFunctions[] = 'efHandleSocialTools';
 45+
 46+# Configuration
 47+// Should we track new user registration? Requires that the user_register_track table exists in the DB.
 48+$wgRegisterTrack = false;
 49+// If the new user was referred to the site by an existing user, should we make them friends automatically?
 50+$wgAutoAddFriendOnInvite = false;
 51+// Initialize the extension, even if InviteEmail or UserRelationship classes do
 52+// not exist? Useful for testing.
 53+$wgForceNewSignupPageInitialization = false;
 54+
 55+// Checks if InviteContacts extension and social tools' core are both loaded and enables two hooked functions if so
 56+function efHandleSocialTools() {
 57+ global $wgForceNewSignupPageInitialization;
 58+ if(
 59+ class_exists( 'InviteEmail' ) && class_exists( 'UserRelationship' ) ||
 60+ $wgForceNewSignupPageInitialization
 61+ )
 62+ {
 63+ global $wgHooks;
 64+ $wgHooks['AddNewAccount'][] = 'fnRegisterTrack';
 65+ $wgHooks['AddNewAccount'][] = 'fnRegisterAutoAddFriend';
 66+ }
 67+}
 68+
 69+/**
 70+ * Adds the checkbox into Special:UserLogin/signup
 71+ *
 72+ * @param $template QuickTemplate instance
 73+ * @return Boolean: true
 74+ */
 75+function efTermsOfServiceOnSignup( &$template ) {
 76+ global $wgRequest;
 77+
 78+ // Terms of Service box
 79+ $template->addInputItem( 'wpTermsOfService', ''/*do *not* have this checked by default!*/, 'checkbox', 'shoutwiki-loginform-tos' );
 80+
 81+ // Referrer stuff for social wikis
 82+ $template->addInputItem( 'from', $wgRequest->getInt( 'from' ), 'hidden', '' );
 83+ $template->addInputItem( 'referral', $wgRequest->getVal( 'referral' ), 'hidden', '' );
 84+
 85+ return true;
 86+}
 87+
 88+/**
 89+ * Abort the creation of the new account if the user hasn't checked the checkbox
 90+ *
 91+ * @param $user Object: the User object about to be created (read-only, incomplete)
 92+ * @param $message String: error message to be displayed to the user, if any
 93+ * @return Boolean: false by default, true if user has checked the checkbox or has 'bypasstoscheck' right
 94+ */
 95+function efTermsOfServiceAbortNewAccount( $user, $message ) {
 96+ global $wgRequest, $wgUser;
 97+
 98+ if(
 99+ $wgRequest->getCheck( 'wpTermsOfService' ) ||
 100+ $wgUser->isAllowed( 'bypasstoscheck' )
 101+ )
 102+ {
 103+ return true;
 104+ } else {
 105+ $message = wfMsg( 'shoutwiki-must-accept-tos' );
 106+ return false;
 107+ }
 108+
 109+ return false; // since the checkbox isn't checked by default either
 110+}
 111+
 112+/**
 113+ * Automatically make the referring user and the newly-registered user friends
 114+ * if $wgAutoAddFriendOnInvite is set to true.
 115+ *
 116+ * @param $user Object: the User object representing the newly-created user
 117+ * @return Boolean: true
 118+ */
 119+function fnRegisterAutoAddFriend( $user ) {
 120+ global $wgRequest, $wgAutoAddFriendOnInvite;
 121+
 122+ if( $wgAutoAddFriendOnInvite ) {
 123+ $referral_user = $wgRequest->getVal( 'referral' );
 124+ if( $referral_user ) {
 125+ $user_id_referral = User::idFromName( $referral_user );
 126+ if( $user_id_referral ) {
 127+ // need to create fake request first
 128+ $rel = new UserRelationship( $referral_user );
 129+ $request_id = $rel->addRelationshipRequest(
 130+ $user->getName(), 1, '', false
 131+ );
 132+
 133+ // clear the status
 134+ $rel->updateRelationshipRequestStatus( $request_id, 1 );
 135+
 136+ // automatically add relationhips
 137+ $rel = new UserRelationship( $user->getName() );
 138+ $rel->addRelationship( $request_id, true );
 139+ }
 140+ }
 141+ }
 142+ return true;
 143+}
 144+
 145+/**
 146+ * Track new user registrations to the user_register_track database table if
 147+ * $wgRegisterTrack is set to true.
 148+ *
 149+ * @param $user Object: the User object representing the newly-created user
 150+ * @return Boolean: true
 151+ */
 152+function fnRegisterTrack( $user ) {
 153+ global $wgRequest, $wgRegisterTrack, $wgMemc;
 154+
 155+ if( $wgRegisterTrack ) {
 156+ $wgMemc->delete( wfMemcKey( 'users', 'new', '1' ) );
 157+
 158+ // How the user registered (via email from friend, just on the site etc.)?
 159+ $from = $wgRequest->getInt( 'from' );
 160+ if( !$from ) {
 161+ $from = 0;
 162+ }
 163+
 164+ // Track if the user clicked on email from friend
 165+ $user_id_referral = 0;
 166+ $user_name_referral = '';
 167+ $referral_user = $wgRequest->getVal( 'referral' );
 168+ if( $referral_user ) {
 169+ $user_registering_title = Title::makeTitle( NS_USER, $user->getName() );
 170+ $user_title = Title::newFromDBkey( $referral_user );
 171+ $user_id_referral = User::idFromName( $user_title->getText() );
 172+ if( $user_id_referral ) {
 173+ $user_name_referral = $user_title->getText();
 174+ }
 175+
 176+ $stats = new UserStatsTrack( $user_id_referral, $user_title->getText() );
 177+ $stats->incStatField( 'referral_complete' );
 178+
 179+ if( class_exists( 'UserSystemMessage' ) ) {
 180+ $m = new UserSystemMessage();
 181+ // Nees to be forContent because addMessage adds this into a
 182+ // database table - we don't want to display Japanese text
 183+ // to English users
 184+ $message = wfMsgForContent(
 185+ 'login-reg-recruited',
 186+ $user_registering_title->getFullURL(),
 187+ $user->getName()
 188+ );
 189+ $m->addMessage( $user_title->getText(), 1, $message );
 190+ }
 191+ }
 192+
 193+ // Track registration
 194+ $dbw = wfGetDB( DB_MASTER );
 195+ $dbw->insert(
 196+ 'user_register_track',
 197+ array(
 198+ 'ur_user_id' => $user->getID(),
 199+ 'ur_user_name' => $user->getName(),
 200+ 'ur_user_id_referral' => $user_id_referral,
 201+ 'ur_user_name_referral' => $user_name_referral,
 202+ 'ur_from' => $from,
 203+ 'ur_date' => date( 'Y-m-d H:i:s' )
 204+ ),
 205+ __METHOD__
 206+ );
 207+ $dbw->commit(); // Just in case...
 208+ }
 209+ return true;
 210+}
\ No newline at end of file
Property changes on: trunk/extensions/NewSignupPage/NewSignupPage.php
___________________________________________________________________
Added: svn:eol-style
1211 + native
Index: trunk/extensions/NewSignupPage/user_register_track.sql
@@ -0,0 +1,8 @@
 2+CREATE TABLE /*_*/user_register_track (
 3+ `ur_user_id` int(10) unsigned NOT NULL PRIMARY KEY default '0',
 4+ `ur_user_name` varchar(255) default NULL,
 5+ `ur_user_id_referral` int(10) unsigned default '0',
 6+ `ur_user_name_referral` varchar(255) default NULL,
 7+ `ur_from` int(5) default '0',
 8+ `ur_date` datetime default NULL
 9+) /*$wgDBTableOptions*/;
\ No newline at end of file
Property changes on: trunk/extensions/NewSignupPage/user_register_track.sql
___________________________________________________________________
Added: svn:eol-style
110 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r114343Fix r98081: use parseinline rather than raw html in messagedemon03:24, 21 March 2012

Comments

#Comment by Siebrand (talk | contribs)   20:17, 25 September 2011

Please add message documentation for the newly added messages. Thanks.

#Comment by Jack Phoenix (talk | contribs)   20:19, 25 September 2011
#Comment by Raymond (talk | contribs)   20:22, 25 September 2011

Prefix 'shoutwiki' inconsistent to extension name 'NewSignupPage'. I suggest changing the message prefix. And adding the prefix to 'login-reg-recruited'

#Comment by Jack Phoenix (talk | contribs)   20:37, 25 September 2011

It's actually very consistent — the messages with the 'shoutwiki' prefix are specific to ShoutWiki; it's not possible to make them as generic as we'd want to, because includes/specials/SpecialUserlogin.php and includes/templates/Userlogin.php both suck. The 'login-reg-' prefix in 'login-reg-recruited' is a leftover from when that part of the code was a part of a Wikia extension called LoginReg; its messags were prefixed with 'login-reg-'.

#Comment by Platonides (talk | contribs)   20:24, 25 September 2011

login-reg-recruited accepts html, which is discouraged (and given that there's no work to escape its arguments, it's safe just by luck).

#Comment by Jack Phoenix (talk | contribs)   20:38, 25 September 2011

Right; would wfMsgExt() with 'content' and 'parse' options be any better? I agree that the HTML looks ugly and it's most likely a leftover from the Wikia code.

#Comment by 😂 (talk | contribs)   14:22, 27 January 2012

Maybe 'parseinline' if you don't want it wrapped in <p> tags, but otherwise yeah.

Status & tagging log