MediaWiki  master
deleteUserEmail.php
Go to the documentation of this file.
1 <?php
28 
29 require_once __DIR__ . '/Maintenance.php';
30 
37  public function __construct() {
38  parent::__construct();
39  $this->addDescription( "Delete a user's email" );
40  $this->addArg( 'user', 'Username or user ID, if starts with #', true );
41  }
42 
43  public function execute() {
44  $userFactory = MediaWikiServices::getInstance()->getUserFactory();
45  $userName = $this->getArg( 0 );
46  if ( preg_match( '/^#\d+$/', $userName ) ) {
47  $user = $userFactory->newFromId( (int)substr( $userName, 1 ) );
48  } else {
49  $user = $userFactory->newFromName( $userName );
50  }
51 
52  // Checking whether User object is valid and has an actual id
53  if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) {
54  $this->fatalError( "Error: user '$userName' could not be loaded" );
55  }
56 
57  // Blank the email address
58  $user->invalidateEmail();
59  $user->saveSettings();
60  $this->output( "Done!\n" );
61  }
62 }
63 
64 $maintClass = DeleteUserEmail::class;
65 require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Service locator for MediaWiki core services.
$maintClass