summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'AntiSpoof/AntiSpoofHooks.php')
-rw-r--r--AntiSpoof/AntiSpoofHooks.php145
1 files changed, 0 insertions, 145 deletions
diff --git a/AntiSpoof/AntiSpoofHooks.php b/AntiSpoof/AntiSpoofHooks.php
deleted file mode 100644
index e8a72923..00000000
--- a/AntiSpoof/AntiSpoofHooks.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-class AntiSpoofHooks {
- /**
- * @param $updater DatabaseUpdater
- * @return bool
- */
- public static function asUpdateSchema( $updater = null ) {
- if ( $updater === null ) {
- global $wgExtNewTables, $wgDBtype;
- $wgExtNewTables[] = array(
- 'spoofuser',
- __DIR__ . '/sql/patch-antispoof.' . $wgDBtype . '.sql', true );
- } else {
- $updater->addExtensionUpdate( array( 'addTable', 'spoofuser',
- __DIR__ . '/sql/patch-antispoof.' . $updater->getDB()->getType() . '.sql', true ) );
- }
- return true;
- }
-
- /**
- * Can be used to cancel user account creation
- *
- * @param $user User
- * @param $message string
- * @return bool true to continue, false to abort user creation
- */
- public static function asAbortNewAccountHook( $user, &$message ) {
- global $wgAntiSpoofAccounts, $wgUser, $wgRequest;
-
- if ( !$wgAntiSpoofAccounts ) {
- $mode = 'LOGGING ';
- $active = false;
- } elseif ( $wgRequest->getCheck( 'wpIgnoreAntiSpoof' ) &&
- $wgUser->isAllowed( 'override-antispoof' ) ) {
- $mode = 'OVERRIDE ';
- $active = false;
- } else {
- $mode = '';
- $active = true;
- }
-
- $name = $user->getName();
- $spoof = new SpoofUser( $name );
- if ( $spoof->isLegal() ) {
- $normalized = $spoof->getNormalized();
- $conflicts = $spoof->getConflicts();
- if ( empty( $conflicts ) ) {
- wfDebugLog( 'antispoof', "{$mode}PASS new account '$name' [$normalized]" );
- } else {
- wfDebugLog( 'antispoof', "{$mode}CONFLICT new account '$name' [$normalized] spoofs " . implode( ',', $conflicts ) );
- if ( $active ) {
- $numConflicts = count( $conflicts );
- $message = wfMessage( 'antispoof-conflict-top', $name )
- ->numParams( $numConflicts )->escaped();
- $message .= '<ul>';
- foreach ( $conflicts as $simUser ) {
- $message .= '<li>' . wfMessage( 'antispoof-conflict-item', $simUser )->escaped() . '</li>';
- }
- $message .= '</ul>' . wfMessage( 'antispoof-conflict-bottom' )->escaped();
- return false;
- }
- }
- } else {
- $error = $spoof->getError();
- wfDebugLog( 'antispoof', "{$mode}ILLEGAL new account '$name' $error" );
- if ( $active ) {
- $message = wfMessage( 'antispoof-name-illegal', $name, $error )->text();
- return false;
- }
- }
- return true;
- }
-
- /**
- * Set the ignore spoof thingie
- * (Manipulate the user create form)
- *
- * @param $template UsercreateTemplate
- * @return bool
- */
- public static function asUserCreateFormHook( &$template ) {
- global $wgRequest, $wgAntiSpoofAccounts, $wgUser;
-
- if ( $wgAntiSpoofAccounts && $wgUser->isAllowed( 'override-antispoof' ) ) {
- $template->addInputItem( 'wpIgnoreAntiSpoof',
- $wgRequest->getCheck( 'wpIgnoreAntiSpoof' ),
- 'checkbox', 'antispoof-ignore' );
- }
- return true;
- }
-
- /**
- * On new account creation, record the username's thing-bob.
- * (Called after a user account is created)
- *
- * @param $user User
- * @return bool
- */
- public static function asAddNewAccountHook( $user ) {
- $spoof = new SpoofUser( $user->getName() );
- $spoof->record();
- return true;
- }
-
- /**
- * On rename, remove the old entry and add the new
- * (After a sucessful user rename)
- *
- * @param $uid
- * @param $oldName string
- * @param $newName string
- * @return bool
- */
- public static function asAddRenameUserHook( $uid, $oldName, $newName ) {
- $spoof = new SpoofUser( $newName );
- $spoof->update( $oldName );
- return true;
- }
-
- /**
- * Register tests
- *
- * @param array $files
- * @return bool
- */
- public static function asUnitTestsList( array &$files ) {
- // @codeCoverageIgnoreStart
- $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/' );
-
- /**
- * @var SplFileInfo $fileInfo
- */
- $ourFiles = array();
- foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
- if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
- $ourFiles[] = $fileInfo->getPathname();
- }
- }
-
- $files = array_merge( $files, $ourFiles );
- return true;
- // @codeCoverageIgnoreEnd
- }
-}