5 * @subpackage SpecialPage
11 require_once('UserMailer.php');
13 function wfSpecialEmailuser( $par ) {
14 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail;
16 if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
17 $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
21 if( !$wgUser->canSendEmail() ) {
22 wfDebug( "User can't send.\n" );
23 $wgOut->showErrorPage( "mailnologin", "mailnologintext" );
27 $action = $wgRequest->getVal( 'action' );
28 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
29 if ( "" == $target ) {
30 wfDebug( "Target is empty.\n" );
31 $wgOut->showErrorPage( "notargettitle", "notargettext" );
35 $nt = Title
::newFromURL( $target );
36 if ( is_null( $nt ) ) {
37 wfDebug( "Target is invalid title.\n" );
38 $wgOut->showErrorPage( "notargettitle", "notargettext" );
42 $nu = User
::newFromName( $nt->getText() );
43 if( is_null( $nu ) ||
!$nu->canReceiveEmail() ) {
44 wfDebug( "Target is invalid user or can't receive.\n" );
45 $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
49 $f = new EmailUserForm( $nu );
51 if ( "success" == $action ) {
52 $f->showSuccess( $nu );
53 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
54 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
64 * @subpackage SpecialPage
74 function EmailUserForm( $target ) {
76 $this->target
= $target;
77 $this->text
= $wgRequest->getText( 'wpText' );
78 $this->subject
= $wgRequest->getText( 'wpSubject' );
82 global $wgOut, $wgUser;
84 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
85 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
87 if ( $this->subject
=== "" ) {
88 $this->subject
= wfMsg( "defemailsubject" );
91 $emf = wfMsg( "emailfrom" );
92 $sender = $wgUser->getName();
93 $emt = wfMsg( "emailto" );
94 $rcpt = $this->target
->getName();
95 $emr = wfMsg( "emailsubject" );
96 $emm = wfMsg( "emailmessage" );
97 $ems = wfMsg( "emailsend" );
98 $encSubject = htmlspecialchars( $this->subject
);
100 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
101 $action = $titleObj->escapeLocalURL( "target=" .
102 urlencode( $this->target
->getName() ) . "&action=submit" );
103 $token = $wgUser->editToken();
106 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
107 <table border='0' id='mailheader'><tr>
108 <td align='right'>{$emf}:</td>
109 <td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
111 <td align='right'>{$emt}:</td>
112 <td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
114 <td align='right'>{$emr}:</td>
116 <input type='text' size='60' maxlength='200' name=\"wpSubject\" value=\"{$encSubject}\" />
120 <span id='wpTextLabel'><label for=\"wpText\">{$emm}:</label><br /></span>
121 <textarea name=\"wpText\" rows='20' cols='80' wrap='virtual' style=\"width: 100%;\">" . htmlspecialchars( $this->text
) .
123 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
124 <input type='hidden' name='wpEditToken' value=\"$token\" />
129 function doSubmit() {
130 global $wgOut, $wgUser;
132 $to = new MailAddress( $this->target
);
133 $from = new MailAddress( $wgUser );
134 $subject = $this->subject
;
136 if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text
) ) ) {
138 $mailResult = userMailer( $to, $from, $subject, $this->text
);
140 if( WikiError
::isError( $mailResult ) ) {
141 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
143 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
144 $encTarget = wfUrlencode( $this->target
->getName() );
145 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
146 wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $this->text
) );
151 function showSuccess( &$user ) {
154 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
155 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
157 $wgOut->returnToMain( false, $user->getUserPage() );