Automatically Refuse Spam Users

From WinWolf3D/WDC

For MediaWiki 1.5.2.

If you block guest users from editing pages, spammers will start making junk user accounts. Luckily their usernames follow some patterns. This code will cause user names that match the patterns to be automatically blocked upon creation.

includes/User.php

  • Open includes/User.php
  • Find:
function isAllowedToCreateAccount() {
  • Add BEFORE:
// 20080907 - Detect spam-like names. - ANB
function isSpamName($userName) {
	$patterns = array(
		"/^([A-Z0-9][a-z0-9]{4}){2}$/", // AcdarZelsi, C4tboCtroc
		"/^([A-Z0-9][a-z0-9]{2}){2}$/", // RozNar
	);
	foreach( $patterns as $pattern ) {
		if (preg_match($pattern, $userName)) {
			return true;
		}
	}
	return false;
}
  • Close file

includes/SpecialUserlogin.php

  • Open includes/SpecialUserlogin.php
  • Find:
if (!$wgUser->isAllowedToCreateAccount()) {
  • Add BEFORE
// 20080907 - Automatically refuse spam-like names. - ANB
if ($wgUser->isSpamName($this->mName)) {
	$this->userNotPrivilegedMessage();
	return false;
}
  • Close file