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  $userName = substr( $userName, 1 );
48  $user = $userFactory->newFromId( $userName );
49  } else {
50  $user = $userFactory->newFromName( $userName );
51  }
52 
53  // Checking whether User object is valid and has an actual id
54  if ( !$user || !$user->getId() || !$user->loadFromId() ) {
55  $this->fatalError( "Error: user '$userName' could not be loaded" );
56  }
57 
58  // Blank the email address
59  $user->invalidateEmail();
60  $user->saveSettings();
61  $this->output( "Done!\n" );
62  }
63 }
64 
65 $maintClass = DeleteUserEmail::class;
66 require_once RUN_MAINTENANCE_IF_MAIN;
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:203
DeleteUserEmail\execute
execute()
Do the actual work.
Definition: deleteUserEmail.php:43
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
$maintClass
$maintClass
Definition: deleteUserEmail.php:65
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
DeleteUserEmail\__construct
__construct()
Default constructor.
Definition: deleteUserEmail.php:37
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:300
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435
DeleteUserEmail
Definition: deleteUserEmail.php:36
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:353