Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

SpecialEmailuser.php

Go to the documentation of this file.
00001 <?php 00002 00003 require_once('UserMailer.php'); 00004 00005 function wfSpecialEmailuser( $par ) { 00006 global $wgUser, $wgOut, $wgRequest; 00007 00008 if ( 0 == $wgUser->getID() || 00009 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) { 00010 $wgOut->errorpage( "mailnologin", "mailnologintext" ); 00011 return; 00012 } 00013 00014 $action = $wgRequest->getVal( 'action' ); 00015 if( empty( $par ) ) { 00016 $target = $wgRequest->getVal( 'target' ); 00017 } else { 00018 $target = $par; 00019 } 00020 if ( "" == $target ) { 00021 $wgOut->errorpage( "notargettitle", "notargettext" ); 00022 return; 00023 } 00024 $nt = Title::newFromURL( $target ); 00025 $nu = User::newFromName( $nt->getText() ); 00026 $id = $nu->idForName(); 00027 00028 if ( 0 == $id ) { 00029 $wgOut->errorpage( "noemailtitle", "noemailtext" ); 00030 return; 00031 } 00032 $nu->setID( $id ); 00033 $address = $nu->getEmail(); 00034 00035 if ( ( false === strpos( $address, "@" ) ) || 00036 ( 1 == $nu->getOption( "disablemail" ) ) ) { 00037 $wgOut->errorpage( "noemailtitle", "noemailtext" ); 00038 return; 00039 } 00040 00041 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target ); 00042 00043 if ( "success" == $action ) { $f->showSuccess(); } 00044 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); } 00045 else { $f->showForm( "" ); } 00046 } 00047 00048 class EmailUserForm { 00049 00050 var $mAddress; 00051 var $target; 00052 var $text, $subject; 00053 00054 function EmailUserForm( $addr, $target ) 00055 { 00056 global $wgRequest; 00057 $this->mAddress = $addr; 00058 $this->target = $target; 00059 $this->text = $wgRequest->getText( 'wpText' ); 00060 $this->subject = $wgRequest->getText( 'wpSubject' ); 00061 } 00062 00063 function showForm( $err ) 00064 { 00065 global $wgOut, $wgUser, $wgLang; 00066 00067 $wgOut->setPagetitle( wfMsg( "emailpage" ) ); 00068 $wgOut->addWikiText( wfMsg( "emailpagetext" ) ); 00069 00070 if ( $this->subject === "" ) { 00071 $this->subject = wfMsg( "defemailsubject" ); 00072 } 00073 00074 $emf = wfMsg( "emailfrom" ); 00075 $sender = $wgUser->getName(); 00076 $emt = wfMsg( "emailto" ); 00077 $rcpt = str_replace( "_", " ", $this->target ); 00078 $emr = wfMsg( "emailsubject" ); 00079 $emm = wfMsg( "emailmessage" ); 00080 $ems = wfMsg( "emailsend" ); 00081 $encSubject = htmlspecialchars( $this->subject ); 00082 00083 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" ); 00084 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" ); 00085 00086 if ( "" != $err ) { 00087 $wgOut->setSubtitle( wfMsg( "formerror" ) ); 00088 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" ); 00089 } 00090 $wgOut->addHTML( "<p> 00091 <form id=\"emailuser\" method=\"post\" action=\"{$action}\"> 00092 <table border=0><tr> 00093 <td align=right>{$emf}:</td> 00094 <td align=left><strong>{$sender}</strong></td> 00095 </tr><tr> 00096 <td align=right>{$emt}:</td> 00097 <td align=left><strong>{$rcpt}</strong></td> 00098 </tr><tr> 00099 <td align=right>{$emr}:</td> 00100 <td align=left> 00101 <input type=text name=\"wpSubject\" value=\"{$encSubject}\"> 00102 </td> 00103 </tr><tr> 00104 <td align=right>{$emm}:</td> 00105 <td align=left> 00106 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual> 00107 {$this->text} 00108 </textarea> 00109 </td></tr><tr> 00110 <td>&nbsp;</td><td align=left> 00111 <input type=submit name=\"wpSend\" value=\"{$ems}\"> 00112 </td></tr></table> 00113 </form>\n" ); 00114 00115 } 00116 00117 function doSubmit() 00118 { 00119 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding; 00120 00121 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">"; 00122 00123 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text ); 00124 00125 if (! $mailResult) 00126 { 00127 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" ); 00128 $encTarget = wfUrlencode( $this->target ); 00129 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) ); 00130 } 00131 else 00132 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult); 00133 } 00134 00135 function showSuccess() 00136 { 00137 global $wgOut, $wgUser; 00138 00139 $wgOut->setPagetitle( wfMsg( "emailsent" ) ); 00140 $wgOut->addHTML( wfMsg( "emailsenttext" ) ); 00141 00142 $wgOut->returnToMain( false ); 00143 } 00144 } 00145 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7