Extension:CustomUserCreateForm
From MediaWiki.org
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
CustomUserCreateForm Release status: beta |
|||
|---|---|---|---|
| Implementation | User identity | ||
| Description | Replace the standard user create form with a custom form. | ||
| Author(s) | Matthew Vickery (Mattvicktalk) | ||
| Last version | 0.1 (2007-06-13) | ||
| MediaWiki | 1.10+ | ||
| Database changes | No | ||
| License | GNU open source | ||
| Download | copy the code form here | ||
|
|||
| Check usage and version matrix | |||
The CustomUserCreateForm extension replaces the standard user creation form with a custom form.
Contents |
Usage [edit]
Use to change the layout of the user create form or add additional fields to the form. To store data for custom fields create an event handler for the AddNewAccount hook and in the event handler get the user ID for the new record in the user table from the $user parameter. The global $wgRequest will contain the values of submitted custom fields which can then be stored in the user_properties table against the user ID.
Installation [edit]
- Create a folder named customUserCreateForm in your extension folder.
- Create a new file named customUserCreateForm.php in the above folder and paste the code below into the file.
- Create a folder named templates inside the customUserCreateForm folder you created above
- Make a copy of includes/templates/Userlogin.php in extensions/customUserCreateForm/templates/
- Rename the copy of Userlogin.php to customUserlogin.php
- Within the new customUserlogin.php file rename UsercreateTemplate class to customUsercreateTemplate.
- Within the new customUserlogin.php file rename UserloginTemplate class to customUserloginTemplate.
- Edit customUsercreateTemplate class as you require.
- Add the line below to the bottom of your LocalSettings.php file.
- Decide if you do not wish to allow non-Sysops to create user accounts via E-mail and delete the highlighted lines of code if so.
Changes to LocalSettings.php [edit]
require_once($IP."/extensions/customUserCreateForm/customUserCreateForm.php");
Code [edit]
<?php /** * Replace the standard user create form with a custom form * * Installation: Create a folder named customUserCreateForm in your extension folder. * Create a new file named customUserCreateForm.php in the above folder and paste this code into the file. * Create a folder named templates inside the customUserCreateForm folder you created above * Make a copy of includes/templates/Userlogin.php in extensions/customUserCreateForm/templates/ * Rename the copy of Userlogin.php to customUserlogin.php * Within the new customUserlogin.php file rename UsercreateTemplate class to customUsercreateTemplate. * Edit customUsercreateTemplate class as you require. * Add the line below to the bottom of your LocalSettings.php file. * Decide if you do not wish to allow non-Sysops to create user accounts via E-mail * and delete the highlighted lines of code if so. * * require_once($IP."/extensions/customUserCreateForm/customUserCreateForm.php"); * * @author Matthew Vickery * @version 1.0 */ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension and not a valid entry point' ); } $wgExtensionCredits['other'][] = array( 'name' => 'CustomUserCreateForm', 'version' => '0.1', 'author' => 'Matthew Vickery', 'url' => 'https://www.mediawiki.org/wiki/Extension:CustomUserCreateForm', 'description' => 'Replaces the standard user creation form with a custom form' ); $wgHooks['UserCreateForm'][] = 'customUserCreateForm'; function customUserCreateForm( &$template ) { // include the request global so we can grab the return page from it global $wgRequest ; // grab the return to page if this exists $mReturnTo = $wgRequest->getVal( 'returnto' ); // Grab data from the existing template before we destory it when creating a new template $tempData = $template->data ; // include our custom create account template include( 'templates/customUserlogin.php' ); // create a new template object using the custom template $template = new customUsercreateTemplate(); $q = 'action=submitlogin&type=signup'; $linkq = 'type=login'; $linkmsg = 'gotaccount'; // if there is a return to page adjust relevant links if ( !empty( $mReturnTo ) ) { $returnto = '&returnto=' . wfUrlencode( $mReturnTo ); $q .= $returnto; $linkq .= $returnto; } // add the old template data to the new template foreach ($tempData as $key => $value) { $template->set( $key, $value ) ; } /* * * * SPECIAL CASE * ------------ * The following two lines of code allow non-Sysops to create accounts via E-mail * This is functionality I want to implement on my Wiki * Remove these lines if you want only Sysops to create accounts via E-mail * (Sysops only is the default MediaWiki configuration) * * * * * * */ global $wgEnableEmail ; $template->set( 'createemail', $wgEnableEmail ); // unset the temporary data var unset ($tempData) ; return true ; }