Extension:STSGMassMailer
From MediaWiki.org
|
STGSMassMailer Release status: beta |
|
|---|---|
| Implementation | Special page, Notify |
| Description | Adds a special page to the wiki for mass-emailing |
| Author(s) | Martin Dale Lyness, Paul Grinberg |
| Version | 0.3.5 (December 1, 2007) |
| Download | Download here |
Contents |
[edit] Description
STGS MassMailer adds a special page called Mass E-mail which allows to send a mass emailing to all wiki users with valid email addresses. It also allows you to pick and choose which persons to send to, and you can even add extra email address that are not in your database. Since there is definite possibility of abuse, this special page is only available to users who have the delete access on the wiki (i.e. sysops or any other user defined group with privileges to do so).
[edit] Installation Instructions
[edit] v0.3.x
[edit] Step 1
Copy the following contents to extensions/SpecialMassEmail.setup.php
<?php # Alert the user that this is not a valid entry point to MediaWiki if they try to access the skin file directly. if (!defined('MEDIAWIKI')) { echo <<<EOT To install SpecialMassEmail extension, put the following line in LocalSettings.php: require_once( "$IP/extensions/SpecialMassEmail.php" ); EOT; exit( 1 ); } $wgAutoloadClasses['MassEmail'] = dirname(__FILE__) . '/SpecialMassEmail.body.php'; $wgSpecialPages['MassEmail'] = 'MassEmail'; $wgHooks['LoadAllMessages'][] = 'MassEmail::loadMessages'; $wgExtensionCredits['specialpage'][] = array( 'version' => '0.3.5', 'name' => 'MassEmail', 'author' => array('Martin Dale Lyness', 'Paul Grinberg'), 'email' => 'martin dot lyness at gmail dot com, gri6507 at yahoo dot com', 'url' => 'http://www.mediawiki.org/wiki/Extension:STSGMassMailer', 'description' => 'This simple extension will allow any user with priveledges to "delete" to send emails to the entire or partial list of registered users on the wiki (given they used an email address when they signed up), and any number of external users');
[edit] Step 2
Copy the following contents to extensions/SpecialMassEmail.body.php
<?php class MassEmail extends SpecialPage { function MassEmail() { global $wgUser; if($wgUser->isAllowed("delete")) { SpecialPage::SpecialPage("MassEmail"); self::loadMessages(); } } function execute() { global $wgOut, $wgRequest, $wgUser, $wgParser; $this->setHeaders(); if($wgUser->isAllowed("delete")) { $secret = $wgRequest->getVal("massMailerHidden"); if($secret != sha1("stsg")) { $wgParser->mTitle = "The Mass Mailer Extension"; $wgOut->addHTML("<form method=\"post\">"); $wgOut->addHTML("<input type=\"hidden\" value=\"".sha1("stsg")."\" name=\"massMailerHidden\" />"); /** * Create a table to make things look pretty */ $wgOut->addHTML("<div style=\"border: thin solid #000000; width:90%;\"><table cellpadding=\"15\" width=\"100%\" cellspacing=\"0\" border=\"0\">"); /** * Need to generate a multi-select menu for senders to select who to send and not send this message to. */ $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'user', 'user_name', '', __METHOD__); /** * Put Email list on one side and the message/subject on the other */ $wgOut->addHTML("<tr><td>"); $wgOut->addHTML('<select name="idArray[]" size="12" multiple="multiple">'); $users = array(); for ( $row = $dbr->fetchObject($res); $row; $row = $dbr->fetchObject($res)) { $u = User::newFromName($row->user_name); if ($u->isAllowed('read') && ($u->getEmail() != '')) $users[strtolower($u->getRealName())] = $u->getID(); } ksort($users); foreach ($users as $name => $id) { $wgOut->addHTML("<option selected=\"selected\" value=\"".$id."\">".$name."</option>"); } $wgOut->addHTML('</select></td><td>'); $wgOut->addHTML("\n<label>Subject: <input name=\"emailSbj\" type=\"text\" size=\"40\" /></label><br />"); $wgOut->addHTML("\n<label>Message: <textarea name=\"emailMsg\" cols=\"40\" rows=\"8\"></textarea></label></td></tr><tr><td colspan=\"2\">"); $wgOut->addHTML("<label>Additonal Emails: <input type=\"text\" name=\"addEmails\" value=\"comma separated\" size=\"50\"></label> "); $wgOut->addHTML("<input type=\"submit\" value=\"Send Emails\" /></td></tr></table></div></form>"); } else { /** * Try to send the mass mailing, if fail then output error */ $sendChk = MassEmail::sendMailToAll(); if($sendChk) $wgOut->addHTML("<h2>Messages Sent Successfully</h2>"); else $wgOut->addHTML($sendChk); } } } function sendMailToAll() { global $wgUser, $wgOut, $wgRequest, $wgSitename; $idArray = $wgRequest->getArray('idArray'); $message = $wgRequest->getVal('emailMsg'); $subject = "[${wgSitename}] " . $wgRequest->getVal('emailSbj'); $emailAdd = $wgRequest->getVal('addEmails'); $from = $wgUser->getRealName(); $sender = new MailAddress( $wgUser->getEmail(), $from ); $to = ''; foreach ($idArray as $name => $id) { if (constant("MW_USER_VERSION") < 4) { $u = new User(); $u->mId = $id; } else { $u = User::newFromId($id); } $to .= $u->getEmail() . ", "; $u->sendMail($subject, $message, $sender->toString()); } if($emailAdd != "comma separated" && trim($emailAdd) != "") { require_once('UserMailer.php'); foreach (explode(',', $emailAdd) as $additional_email) { $to .= "$additional_email, "; userMailer(new MailAddress($additional_email), $sender, $subject, $message); } } /** * Add result information to the renderer */ $wgOut->addWikiText("'''From:''' $from\n"); $wgOut->addWikiText("'''To:''' $to\n"); $wgOut->addwikiText("'''Subject:''' $subject\n"); $wgOut->addWikiText("'''Body:''' $message\n"); } function loadMessages() { static $messagesLoaded = false; global $wgMessageCache; if ( $messagesLoaded ) return; $messagesLoaded = true; $allMessages = array( 'en' => array( 'massemail' => 'Mass E-Mail' ), ); foreach ( $allMessages as $lang => $langMessages ) { $wgMessageCache->addMessages( $langMessages, $lang ); } return true; } }
[edit] Step 3
Add the following text to your LocalSettings.php
require_once( "$IP/extensions/SpecialMassEmail.setup.php" );
[edit] v0.2.0
[edit] Step 1
Paste the following code into $IP/includes/SpecialMassMailer.php
<?php /** * This simple extension will allow the administrator or users in the 'massMailer' group * to send emails to the entire or partial list of registered users on the wiki. (given * they used an email address when they signed up.) This was originally designed for the * Student Technology Services Group at the University of Minneosta by founder Martin Dale * Lyness * @author Martin Dale Lyness <martin.lyness@gmail.com> * @version 0.2.0 * @copyright Use freely, just give me credit for my work ;) * @package MediaWiki * @subpackage SpecialPages */ /** * This function produces the page output based on the user's account informaiton * (ie, wether they should have access to the mass mailer or not) */ function wfSpecialMassMailer($para) { global $wgUser,$wgOut,$wgParser,$wgDBserver, $wgDBuser, $wgDBpassword, $wgDBprefix; $wgOut->setPagetitle( "Mass E-Mailer" ); $webreq = new WebRequest(); /** * I've explicitly added the 'delete' option to developer's not users */ if($wgUser->isAllowed("delete")) { if($webreq->wasPosted()) $secret = $webreq->getVal("massMailerHidden"); else $secret = false; /** * If form is submitted already then process it, if not then display form */ if($secret!=sha1("stsg")) { $wgParser->mTitle = "The Mass Mailer Extension - By: Martin Dale Lyness"; $wgOut->addHTML("<form method=\"post\">"); $wgOut->addHTML("<input type=\"hidden\" value=\"".sha1("stsg")."\" name=\"massMailerHidden\" />"); /** * Create a table to make things look pritty */ $wgOut->addHTML("<div style=\"border: thin solid #000000; width:90%;\"><table cellpadding=\"15\" width=\"100%\" cellspacing=\"0\" border=\"0\">"); /** * Need to generate a multi-select menu for senders to select who to send and not send this message to. */ $sql = "SELECT `user_real_name`,`user_email` FROM `".$wgDBprefix."user`"; /** * Did not use Database class be cause the documentation was missing and the API file looked incomplete * I could not find the required calls :(... */ $conn_id = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword); mysql_select_db($wgDBname, $conn_id); $result = mysql_query($sql, $conn_id); /** * Put Email list on one side and the message/subject on the other */ $wgOut->addHTML("<tr><td>"); $wgOut->addHTML('<select name="emailArray[]" size="12" multiple="multiple">'); while(($assoc=mysql_fetch_array($result))) { $wgOut->addHTML("<option selected=\"selected\" value=\"".$assoc[1]."\">".$assoc[0]."</option>"); } $wgOut->addHTML('</select></td><td>'); $wgOut->addHTML("\n<label>Subject: <input name=\"emailSbj\" type=\"text\" size=\"40\" /></label><br />"); $wgOut->addHTML("\n<label>Message: <textarea name=\"emailMsg\" cols=\"40\" rows=\"8\"></textarea></label></td></tr><tr><td colspan=\"2\">"); $wgOut->addHTML("<label>Additonal Emails: <input type=\"text\" name=\"addEmails\" value=\"comma separated\" size=\"50\"></label> "); $wgOut->addHTML("<input type=\"submit\" value=\"Send Emails\" /></td></tr></table></div>"); } else { /** * Try to send the mass mailing, if fail then ouptut error */ $sendChk = sendMailToAll(); if($sendChk) $wgOut->addHTML("<h2>Messages Sent Successfully</h2>"); else $wgOut->addHTML($sendChk); } } else { $wgOut->addHTML("<h2>I was informed you don't have permission to view this page.</h2>"); $wgOut->addHTML("If you feel I was told wrong then please contact my supervisor, Martin Lyness."); } return $output; } /** * This function sends the posted message to every user selected. */ function sendMailToAll() { global $wgUser,$wgOut; $webreq = new WebRequest(); /** * I'll be a good boy and get the post vars using the wikimedia objects :). * Nevermind, it keeps giving me problems i just get it the normal way :(. */ if(isset($_POST['emailArray']) && isset($_POST['emailMsg']) && isset($_POST['emailSbj']) && $webreq->wasPosted()) { $emailArray = $webreq->getArray('emailArray'); $message = $webreq->getVal('emailMsg'); $subject = $webreq->getVal('emailSbj'); $emailAdd = $webreq->getVal('addEmails'); /* $emailArray = $_POST['emailArray']; $message = $_POST['emailMsg']; $subject = $_POST['emailSbj']; */ } else { return "Could not find Post variables!".var_dump($_POST); } /** * Using the logged in user's information I'll create the 'From' header */ $from = $wgUser->getRealName()." <".$wgUser->getEmail().">"; $headers = "MIME-Version: 1.0\n" . "Content-type: text/plain; charset={$wgOutputEncoding}\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: STSG-MediaWiki mailer\n". 'From: ' . $from . "\n"; /** * Send the Email to everyone in the list (One big bunch) */ $to = implode(", ", $emailArray); /** * See if we need to add additional emails to the mailing */ if($emailAdd!="comma separated" && trim($emailAdd) != "") { $to .= ", ".$emailAdd; } /** * Add result informatoin to the renderer */ $wgOut->addHTML("<strong>Emails sent to:</strong> ".$to."<br />"); $wgOut->addHTML("<strong>Subject Line:</strong> ".$subject."<br />"); $wgOut->addHTML("<strong>Headers Added:</strong> <br />".$headers."<br />"); $wgOut->addHTML("<strong>Message Sent:</strong> <br />".$message."<br />"); if(mail($to, $subject, $message, $headers)) return true; else return false; }
[edit] Step 2
- Modify the file $IP/includes/SpecialPages.php
- Around line '74' add: 'MassMailer' => array('SpecialPage', 'MassMailer'),
[edit] Step 3
- Modify the languages/messages/Messages*.php file
- Add the line: 'massmailer' => 'The Mass Mailer', to the $specialPageAliases array and look for the comment '# Miscellaneous special pages' and add the same there.
[edit] Questions
- When I try to access: Special:MassMailer or Special:massmailer, I get the page that says I've requested an invalid special page. But clicking to the list of special pages (Special:Specialpages) shows the <massmailer> at the top where you can click on it to access the extension. So although it's working fine, the presence of the brackets makes me feel I've omitted something.
- Solution : I didn't describe this step originally, but step 3 should fix this problem.
- I'm using MediaWiki 1.7. When I press the "Send Emails" button in the Special Page, i get the following error: "Fatal error: Call to undefined method User::newfromid() in /var/lib/mediawiki1.7/extensions/SpecialMassEmail.body.php on line 83". Is this due to my "old" MediaWiki Version? What can I do to fix this problem?
- You are correct. The old versions of MediaWiki did not have the User::getFromId() function. I have made changes to the code (see new version 0.3.4) to conditionally work with older versions of MW. In theory it should work, but I have no way of easily verifying it. Can you please test this and post your results? --Gri6507 12:48, 25 September 2007 (UTC)
- It worked! I noticed that there are some extra newlines in the Email (one at the beginnig of the body, and every newline I made in the body-text-area is doubled in the resulting email).
- The doubling of lines sounds like you are running the wiki on a Windows machine. The extension should be able to notice that and fix the "problem". I will look into that sometime soon. --Gri6507 14:42, 25 September 2007 (UTC)
- It worked! I noticed that there are some extra newlines in the Email (one at the beginnig of the body, and every newline I made in the body-text-area is doubled in the resulting email).
- You are correct. The old versions of MediaWiki did not have the User::getFromId() function. I have made changes to the code (see new version 0.3.4) to conditionally work with older versions of MW. In theory it should work, but I have no way of easily verifying it. Can you please test this and post your results? --Gri6507 12:48, 25 September 2007 (UTC)
- I just discovered this extension but I can't run it correctly... Everything seems correct but when I try to send a mail to me (to test) using MassMailer (selecting my name in the list), I am redirected to Special:Search page just after clicking "send" button, and no mail is send... Using last MediaWiki version... Any idea ? Cedsib 12:14, 25 October 2007 (UTC)
- Are you logged as a user who has delete permissions? Try logging in as a sysop and run your test again. --Gri6507 13:00, 25 October 2007 (UTC)
- Thanks for your answer ! Yes, the user has Sysop & admin rights, and can delete any page... Is there another way to test MassMailer ? Is there any server requirement ?
- Any other (helping ?) info: just after clicking "Send emails", URL is still "http://fr.scoutwiki.org/Special:MassEmail" but content is Special:Search page...
- thanks :-) Cedsib 15:40, 28 October 2007 (UTC)
- To the best of my knowledge, the only server requirements are the ones described in includes/UserMailer.php
/**
* This function will perform a direct (authenticated) login to
* a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
* array of parameters. It requires PEAR:Mail to do that.
* Otherwise it just uses the standard PHP 'mail' function.
*
* @param $to MailAddress: recipient's email
* @param $from MailAddress: sender's email
* @param $subject String: email's subject.
* @param $body String: email's text.
* @param $replyto String: optional reply-to email (default: null).
*/
function userMailer( $to, $from, $subject, $body, $replyto=null ) {
-
- The behavior you are describing really does not make sense to me. The only thing I can think of to be next is to start adding debug statements in the code for the extension to see where things start going wrong. The best way to do that is to sprinkle
-
$wgOut->addWikiText("STS Test #n");
- where n is 1,2,3,etc throughout the execute() function. This way, when you run your test you should at least in theory see some test messages printed at the top of the resulting wiki page and, at least in theory, at some point you'll stop seeing those messages which will pin point the source of the problem. Can you please try this and post your results? --Gri6507 19:01, 28 October 2007 (UTC)
- BUG FOUND !
You did not closed your "form" object ;-) ==> It was validating the search form ;-)
-
- I also add:
$thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
just after
$secret = $wgRequest->getVal("massMailerHidden");
and changed
$wgOut->addHTML("<form method=\"post\">");
by
$wgOut->addHTML("<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\">");
-
- Cedsib 21:56, 28 October 2007 (UTC)
-
- Also added:
&& (! $u->isBlockedFromEmailuser()))
because we should not email a user who doesn't want to be mailed.
Cedsib 22:09, 28 October 2007 (UTC)
-
-
- Nice find! If you'd like, feel free to incorporate these changes into the code (it is, after all, posted here, so you can edit it too). Thanks! --Gri6507 03:04, 6 November 2007 (UTC)
-
I do have another question ! I tried to use HTML syntax or Wiki syntax, in the mail, but that does'nt work... Do you have an idea to improve mail display ?
- I tried that too and since it didn't work, I stopped. Basically, my only thought is that if you use wiki syntax, you need to parse it to make it into HTML. Of course, if you start with HTML, then you are OK. In either case, sending that type of email will require the email to be formatted to as HTML. My guess is that if you start the email with something like <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> then the message should come across just fine. --Gri6507 03:04, 6 November 2007 (UTC)
Cedsib 20:18, 1 November 2007 (UTC)
[edit] Revisions
- v0.3.5 - December 1, 2007 - Fixed a bug where on some installations, hitting the "send" button would actually take the user to the Special:Search page. Also, a few typos in comments.
- v0.3.4 - September 25, 2007 - work with versions of MediaWiki where User.php version is less than 4 (i.e. MediaWiki 1.7.3)
- v0.3.3 - September 7, 2007 - work around a sendmail problem where sending emails to a LARGE list of people at once causes sendmail to misbehave
- v0.3.2 - September 6, 2007 - fixed a bug where email only worked to the sender of the message
- v0.3.1 - September 6, 2007 - updated the subject line of the sent email to have the site name in it.
- v0.3 - September 6, 2007 - updated to be more inline with standard wiki Special Page syntax. Does not require hacking any core files
- v0.2.0 -

