User:Robchurch/Minimum Username Length
From MediaWiki.org
This is an older, obsolete version of the extension. The code here will not be maintained. For the stable "released" version, please see Extension:Minimum Name Length.
<?php
/**
* Extension enforces a minimum username length
* during account registration
*
* @package MediaWiki
* @subpackage Extensions
* @author Rob Church <robchur@gmail.com>
*/
if( defined( 'MEDIAWIKI' ) ) {
$wgHooks['AbortNewAccount'][] = 'efMinimumNameLength';
$wgExtensionCredits['other'][] = array(
'name' => 'Minimum Username Length',
'author' => 'Rob Church'
);
/**
* Minimum username length to enforce
*/
$wgMinimumUsernameLength = 5;
/**
* Hooks account creation and checks the
* username length, cancelling with an error
* if the username is too short
*
* @param User $user User object being created
* @param string $error Reference to error message to show
* @return bool
*/
function efMinimumNameLength( $user, &$error ) {
global $wgMinimumUsernameLength;
if( mb_strlen( $user->getName() ) < $wgMinimumUsernameLength ) {
$error = 'Your username is too short. The minimum length is ' . $wgMinimumUsernameLength . '.';
return false;
} else {
return true;
}
}
} else {
echo( "This file is an extension to the MediaWiki software. It cannot be used standalone.\n" );
exit( 1 );
}
?>