[Mediawiki-l] Allow Anonymous User Emails

Air Force CGOC Webmaster webmaster at afcgoc.org
Sun Jan 14 02:10:52 UTC 2007


Alexis,

Thanks for getting on the right track.  I ended up writing an extension to
make it work.  Here's the extension.  It takes the part before the @ sign as
a parameter after the page name and then the part after the @ sign is
hard-coded. It would need to be adapted, but feel free to use it as you see
fit!


<?php
if(!defined('MEDIAWIKI'))
   die();

$wgExtensionFunctions[] = 'wmsSetupMailto';
$wgExtensionCredits['specialpage'][] = array(
   'name' => 'Mailto',
   'author' => '1Lt Mike Straw',
   'description' => 'Sends email from a non-logged in user, with email
address, to an AFGCOC.org address'
);

function wmsSetupMailto() {
   global $IP, $wgMessageCache;
   require_once($IP . '/includes/SpecialPage.php');
   SpecialPage::addPage(new SpecialPage('Mailto', '', true,
'wmsSpecialMailto', false));
   $wgMessageCache->addMessage('mailto', 'Mailto');
   require_once('UserMailer.php');
}

function wmsSpecialMailto($par) {
   global $wgOut, $wgRequest;
   $wgOut->setPageTitle("Send an Email");

   if ( "" == $par) {
      wfDebug( "Target is empty.\n" );
      $wgOut->showErrorPage( "notargettitle", "notargettext" );
      return;
   }

   if ($wgRequest->wasPosted()) {

      # Send the email
      $to=new MailAddress($par.'@afcgoc.org');
      $from=new MailAddress($wgRequest->getVal('FromEmail'),
$wgRequest->getVal('FromName'));
      $subject="[AFCGOC] ".$wgRequest->getVal('MsgSubject');
      $body="The following message was submitted on the AFCGOC web
page:\n\n";
      $body.=$wgRequest->getVal('MsgBody');
      userMailer( $to, $from, $subject, $body );
      $wgOut->addWikiText("Message successfully sent to
".$par."&#064;afcgoc.org");
   } else {
      $wgOut->addWikiText("Sending mail to ".$par."&#064;afcgoc.org<p>");
      $wgOut->addHTML("<form method=post>
<table border=0>
<tr>
<th align=\"right\">Your Name:</th>
<td><input name=\"FromName\" type=\"text\" size=\"80\"></td>
</tr>
<th align=\"right\">Your Email Address:</th>
<td><input name=\"FromEmail\" type=\"text\" size=\"80\"></td>
</tr>
<tr>
<th align=\"right\">Email Subject:</th>
<td><input name=\"MsgSubject\" type=\"text\" size=\"80\"></td>
</tr>
<tr>
<th align=\"right\">Email Text:</th>
<td><textarea name=\"MsgBody\" rows=\"10\" cols=\"80\"></textarea></td>
</tr>
<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Send
Email\">
</td></tr>
</table>
</form>");
   }
}
?>



On 1/9/07, Alexis Moinet <alexis.moinet at fpms.ac.be> wrote:
>
> Air Force CGOC Webmaster a écrit :
> >The one thing I
> > do want to allow is for anonymous users to send email via
> > Special:Emailuser.  How do I open just that page/function to anonymous
> > users?
>
>
> You can either write an extension (maybe there is already one existing) or
> hack the code of the mailing function (include/SpecialEmailuser.php)
>
> if you change the code of SpecialEmailUser.php, at least, you'll have to
> comment (or change) in the function wfSpecialEmailuser($par) these lines :
>
> if( !$wgUser->canSendEmail() ) {
>                wfDebug( "User can't send.\n" );
>                $wgOut->showErrorPage( "mailnologin", "mailnologintext" );
>                return;
> }
>
> (function canSendEmail() call isEmailConfirmed() which returns false if
> Anon)
>
> you might have to change something else in that file or in the mail form
> (which could get in trouble when it will try to display the sender name) ,
> but I don't know what
>
>
>
>
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at lists.wikimedia.org
> http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>
>


More information about the MediaWiki-l mailing list