/usr/share/mediawiki-extensions/base/NewUserNotif/NewUserNotif.class.php is in mediawiki-extensions-base 2.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | <?php
/**
* Extension to provide customisable email notification of new user creation
*
* @addtogroup Extensions
* @author Rob Church <robchur@gmail.com>
*/
require_once( 'UserMailer.php' );
class NewUserNotifier {
private $sender;
private $user;
/**
* Constructor
*/
public function NewUserNotifier() {
global $wgNewUserNotifSender;
$this->sender = $wgNewUserNotifSender;
}
/**
* Send all email notifications
*
* @param User $user User that was created
*/
public function execute( $user ) {
$this->user = $user;
wfLoadExtensionMessages( 'NewUserNotifier' );
$this->sendExternalMails();
$this->sendInternalMails();
}
/**
* Send email to external addresses
*/
private function sendExternalMails() {
global $wgNewUserNotifEmailTargets, $wgSitename;
foreach( $wgNewUserNotifEmailTargets as $target ) {
userMailer(
new MailAddress( $target ),
new MailAddress( $this->sender ),
wfMsgForContent( 'newusernotifsubj', $wgSitename ),
$this->makeMessage( $target, $this->user )
);
}
}
/**
* Send email to users
*/
private function sendInternalMails() {
global $wgNewUserNotifTargets, $wgSitename;
foreach( $wgNewUserNotifTargets as $userSpec ) {
$user = $this->makeUser( $userSpec );
if( $user instanceof User && $user->isEmailConfirmed() ) {
$user->sendMail(
wfMsgForContent( 'newusernotifsubj', $wgSitename ),
$this->makeMessage( $user->getName(), $this->user ),
$this->sender
);
}
}
}
/**
* Initialise a user from an identifier or a username
*
* @param mixed $spec User identifier or name
* @return User
*/
private function makeUser( $spec ) {
$name = is_integer( $spec ) ? User::whoIs( $spec ) : $spec;
$user = User::newFromName( $name );
if( $user instanceof User && $user->getId() > 0 )
return $user;
return null;
}
/**
* Build a notification email
*
* @param string $recipient Name of the recipient
* @param User $user User that was created
*/
private function makeMessage( $recipient, $user ) {
global $wgSitename, $wgContLang;
return wfMsgForContent(
'newusernotifbody',
$recipient,
$user->getName(),
$wgSitename,
$wgContLang->timeAndDate( wfTimestampNow() ),
$wgContLang->date( wfTimestampNow() ),
$wgContLang->time( wfTimestampNow() )
);
}
/**
* Hook account creation
*
* @param User $user User that was created
* @return bool
*/
public static function hook( $user ) {
$notifier = new self();
$notifier->execute( $user );
return true;
}
}
|