http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98081
Revision: 98081 Author: ashley Date: 2011-09-25 20:13:07 +0000 (Sun, 25 Sep 2011) Log Message: ----------- 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. Added Paths: ----------- trunk/extensions/NewSignupPage/ trunk/extensions/NewSignupPage/NewSignupPage.i18n.php trunk/extensions/NewSignupPage/NewSignupPage.php trunk/extensions/NewSignupPage/user_register_track.sql Added: trunk/extensions/NewSignupPage/NewSignupPage.i18n.php =================================================================== --- trunk/extensions/NewSignupPage/NewSignupPage.i18n.php (rev 0) +++ trunk/extensions/NewSignupPage/NewSignupPage.i18n.php 2011-09-25 20:13:07 UTC (rev 98081) @@ -0,0 +1,121 @@ +<?php +/** + * Internationalization file for NewSignupPage extension. + * + * @file + * @ingroup Extensions + */ + +$messages = array(); + +/** English */ +$messages['en'] = array( + // Social tools + 'login-reg-recruited' => 'recruited <a href="$1">$2</a>', + // Text displayed next to the checkbox + '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>', + // Error message if the user doesn't accept the site's Terms of Service + 'shoutwiki-must-accept-tos' => "You must accept the site's Terms of Service in order to be able to create an account!", + // For Special:ListGroupRights + 'right-bypasstoscheck' => "Create new accounts without accepting the site's Terms of Service", +); + +/** Czech (Česky) */ +$messages['cz'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Musíte uznat stránek jde o služby, aby bylo možné vytvořit účet!', +); + +/** Danish (Dansk) */ +$messages['da'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Du skal acceptere webstedets hensyn til service for at kunne oprette en konto!', +); + +/** German (Deutsch) */ +$messages['de'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Sie müssen akzeptieren, die Website-Nutzungsbedingungen, um in der Lage, ein Konto erstellen!', +); + +/** Greek (Ελληνικά) */ +$messages['el'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Πρέπει να αποδεχτείτε την ιστοσελίδα της Όροι Υπηρεσίας, προκειμένου να μπορέσει να δημιουργήσει ένα λογαριασμό!', +); + +/** Spanish (Español) */ +$messages['es'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Debes aceptar los términos del sitio del servicio con el fin de poder crear una cuenta!', +); + +/** Finnish (Suomi) */ +$messages['fi'] = array( + 'login-reg-recruited' => 'värväsi käyttäjän <a href="$1">$2</a>', + '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>', + 'shoutwiki-must-accept-tos' => 'Sinun tulee hyväksyä sivuston käyttöehdot voidaksesi luoda tunnuksen!', + 'right-bypasstoscheck' => 'Luoda uusia tunnuksia hyväksymättä sivuston käyttöehtoja', +); + +/** French (Français) */ +$messages['fr'] = array( + '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>", + 'shoutwiki-must-accept-tos' => "Vous devez accepter les présentes Conditions de service afin d'être en mesure de créer un compte !", +); + +/** Italian (Italiano) */ +$messages['it'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'È necessario accettare il sito Termini e condizioni del servizio, al fine di essere in grado di creare un account!', +); + +/** Japanese (日本語) */ +$messages['ja'] = array( + '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>', +); + +/** Korean (한국어) */ +$messages['ko'] = array( + '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>', +); + +/** Dutch (Nederlands) + * @author Mitchel Corstjens + */ +$messages['nl'] = array( + 'login-reg-recruited' => 'rekruteerde <a href="$1">$2</a>', + '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', + 'shoutwiki-must-accept-tos' => 'Je moet akkoord gaan met de gebruiks overeenkomst van de site om een account aan te kunnen maken!', + 'right-bypasstoscheck' => "Creëer een nieuwe account zonder akkoord te gaan met de gebruiks overeenkomst", +); + +/** Norwegian (Norsk) */ +$messages['no'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Du må godta nettstedets Vilkår for bruk for å kunne opprette en konto!', +); + +/** Portuguese (Português) */ +$messages['pt'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Você precisa aceitar os Termos de Serviço do site, a fim de ser capaz de criar uma conta!', +); + +/** Romanian (Română) */ +$messages['ro'] = array( + '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>', + '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!', +); + +/** Russian (Русский) */ +$messages['ru'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Вы должны согласиться с сайта Условия предоставления услуг, с тем чтобы иметь возможность создать учетную запись!', +); + +/** Swedish (Svenska) */ +$messages['sv'] = array( + '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>', + 'shoutwiki-must-accept-tos' => 'Du måste godkänna webbplats användarvillkoren för att kunna skapa ett konto!', +); \ No newline at end of file Property changes on: trunk/extensions/NewSignupPage/NewSignupPage.i18n.php ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/extensions/NewSignupPage/NewSignupPage.php =================================================================== --- trunk/extensions/NewSignupPage/NewSignupPage.php (rev 0) +++ trunk/extensions/NewSignupPage/NewSignupPage.php 2011-09-25 20:13:07 UTC (rev 98081) @@ -0,0 +1,209 @@ +<?php +/** + * NewSignupPage extension for MediaWiki -- enhances the default signup form + * + * @file + * @ingroup Extensions + * @version 0.4.1 + * @author Jack Phoenix <j...@countervandalism.net> + * @copyright Copyright © 2008-2011 Jack Phoenix + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + * @note Uses GPL-licensed code from LoginReg extension (functions + * fnRegisterAutoAddFriend and fnRegisterTrack) + */ + +/** + * Protect against register_globals vulnerabilities. + * This line must be present before any global variable is referenced. + */ +if ( !defined( 'MEDIAWIKI' ) ) { + die( "This is not a valid entry point.\n" ); +} + +// Extension credits that will show up on Special:Version +$wgExtensionCredits['other'][] = array( + 'name' => 'New Signup Page', + 'author' => 'Jack Phoenix', + 'version' => '0.4.1', + 'url' => 'http://www.mediawiki.org/wiki/Extension:NewSignupPage', + 'description' => 'Adds new features to [[Special:UserLogin/signup|signup form]]', +); + +// Internationalization file +$wgExtensionMessagesFiles['NewSignupPage'] = dirname( __FILE__ ) . '/NewSignupPage.i18n.php'; + +// New user right, allows bypassing the ToS check on signup form +$wgAvailableRights[] = 'bypasstoscheck'; + +// Hooked functions +$wgHooks['AbortNewAccount'][] = 'efTermsOfServiceAbortNewAccount'; +$wgHooks['UserCreateForm'][] = 'efTermsOfServiceOnSignup'; + +// Function that conditionally enables some hooks +$wgExtensionFunctions[] = 'efHandleSocialTools'; + +# Configuration +// Should we track new user registration? Requires that the user_register_track table exists in the DB. +$wgRegisterTrack = false; +// If the new user was referred to the site by an existing user, should we make them friends automatically? +$wgAutoAddFriendOnInvite = false; +// Initialize the extension, even if InviteEmail or UserRelationship classes do +// not exist? Useful for testing. +$wgForceNewSignupPageInitialization = false; + +// Checks if InviteContacts extension and social tools' core are both loaded and enables two hooked functions if so +function efHandleSocialTools() { + global $wgForceNewSignupPageInitialization; + if( + class_exists( 'InviteEmail' ) && class_exists( 'UserRelationship' ) || + $wgForceNewSignupPageInitialization + ) + { + global $wgHooks; + $wgHooks['AddNewAccount'][] = 'fnRegisterTrack'; + $wgHooks['AddNewAccount'][] = 'fnRegisterAutoAddFriend'; + } +} + +/** + * Adds the checkbox into Special:UserLogin/signup + * + * @param $template QuickTemplate instance + * @return Boolean: true + */ +function efTermsOfServiceOnSignup( &$template ) { + global $wgRequest; + + // Terms of Service box + $template->addInputItem( 'wpTermsOfService', ''/*do *not* have this checked by default!*/, 'checkbox', 'shoutwiki-loginform-tos' ); + + // Referrer stuff for social wikis + $template->addInputItem( 'from', $wgRequest->getInt( 'from' ), 'hidden', '' ); + $template->addInputItem( 'referral', $wgRequest->getVal( 'referral' ), 'hidden', '' ); + + return true; +} + +/** + * Abort the creation of the new account if the user hasn't checked the checkbox + * + * @param $user Object: the User object about to be created (read-only, incomplete) + * @param $message String: error message to be displayed to the user, if any + * @return Boolean: false by default, true if user has checked the checkbox or has 'bypasstoscheck' right + */ +function efTermsOfServiceAbortNewAccount( $user, $message ) { + global $wgRequest, $wgUser; + + if( + $wgRequest->getCheck( 'wpTermsOfService' ) || + $wgUser->isAllowed( 'bypasstoscheck' ) + ) + { + return true; + } else { + $message = wfMsg( 'shoutwiki-must-accept-tos' ); + return false; + } + + return false; // since the checkbox isn't checked by default either +} + +/** + * Automatically make the referring user and the newly-registered user friends + * if $wgAutoAddFriendOnInvite is set to true. + * + * @param $user Object: the User object representing the newly-created user + * @return Boolean: true + */ +function fnRegisterAutoAddFriend( $user ) { + global $wgRequest, $wgAutoAddFriendOnInvite; + + if( $wgAutoAddFriendOnInvite ) { + $referral_user = $wgRequest->getVal( 'referral' ); + if( $referral_user ) { + $user_id_referral = User::idFromName( $referral_user ); + if( $user_id_referral ) { + // need to create fake request first + $rel = new UserRelationship( $referral_user ); + $request_id = $rel->addRelationshipRequest( + $user->getName(), 1, '', false + ); + + // clear the status + $rel->updateRelationshipRequestStatus( $request_id, 1 ); + + // automatically add relationhips + $rel = new UserRelationship( $user->getName() ); + $rel->addRelationship( $request_id, true ); + } + } + } + return true; +} + +/** + * Track new user registrations to the user_register_track database table if + * $wgRegisterTrack is set to true. + * + * @param $user Object: the User object representing the newly-created user + * @return Boolean: true + */ +function fnRegisterTrack( $user ) { + global $wgRequest, $wgRegisterTrack, $wgMemc; + + if( $wgRegisterTrack ) { + $wgMemc->delete( wfMemcKey( 'users', 'new', '1' ) ); + + // How the user registered (via email from friend, just on the site etc.)? + $from = $wgRequest->getInt( 'from' ); + if( !$from ) { + $from = 0; + } + + // Track if the user clicked on email from friend + $user_id_referral = 0; + $user_name_referral = ''; + $referral_user = $wgRequest->getVal( 'referral' ); + if( $referral_user ) { + $user_registering_title = Title::makeTitle( NS_USER, $user->getName() ); + $user_title = Title::newFromDBkey( $referral_user ); + $user_id_referral = User::idFromName( $user_title->getText() ); + if( $user_id_referral ) { + $user_name_referral = $user_title->getText(); + } + + $stats = new UserStatsTrack( $user_id_referral, $user_title->getText() ); + $stats->incStatField( 'referral_complete' ); + + if( class_exists( 'UserSystemMessage' ) ) { + $m = new UserSystemMessage(); + // Nees to be forContent because addMessage adds this into a + // database table - we don't want to display Japanese text + // to English users + $message = wfMsgForContent( + 'login-reg-recruited', + $user_registering_title->getFullURL(), + $user->getName() + ); + $m->addMessage( $user_title->getText(), 1, $message ); + } + } + + // Track registration + $dbw = wfGetDB( DB_MASTER ); + $dbw->insert( + 'user_register_track', + array( + 'ur_user_id' => $user->getID(), + 'ur_user_name' => $user->getName(), + 'ur_user_id_referral' => $user_id_referral, + 'ur_user_name_referral' => $user_name_referral, + 'ur_from' => $from, + 'ur_date' => date( 'Y-m-d H:i:s' ) + ), + __METHOD__ + ); + $dbw->commit(); // Just in case... + } + return true; +} \ No newline at end of file Property changes on: trunk/extensions/NewSignupPage/NewSignupPage.php ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/extensions/NewSignupPage/user_register_track.sql =================================================================== --- trunk/extensions/NewSignupPage/user_register_track.sql (rev 0) +++ trunk/extensions/NewSignupPage/user_register_track.sql 2011-09-25 20:13:07 UTC (rev 98081) @@ -0,0 +1,8 @@ +CREATE TABLE /*_*/user_register_track ( + `ur_user_id` int(10) unsigned NOT NULL PRIMARY KEY default '0', + `ur_user_name` varchar(255) default NULL, + `ur_user_id_referral` int(10) unsigned default '0', + `ur_user_name_referral` varchar(255) default NULL, + `ur_from` int(5) default '0', + `ur_date` datetime default NULL +) /*$wgDBTableOptions*/; \ No newline at end of file Property changes on: trunk/extensions/NewSignupPage/user_register_track.sql ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs