User:Acook~mediawikiwiki

Welcome to my userpage.

I will finish my extension later - I didn't want to save the page yet, below is the rough draft.

Download instructions
Please cut and paste the code found below and place it in. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation
To install this extension, add the following to LocalSettings.php:

Code
Copy and paste this into EmailUsers.php and place it in your EmailUsers folder.

');		# Addition of named list		$wgOut->addWikiText(wfMsg('ea_selectlist'));		$wgOut->addHTML("{$this->list} \n");		$wgOut->addHTML(' ');		$wgOut->addHTML(' '.wfMsg('ea_compose').' ');		# Subject		$wgOut->addWikiText(wfMsg('ea_subject'));		$wgOut->addHTML(wfElement('input',array('type' => 'text', 'name' => 'ea_subject', 'value' => $this->subject, 'style' => "width:100%")));		# Header		$wgOut->addWikiText(wfMsg('ea_header'));		$wgOut->addHTML("{$this->header} \n");

$wgOut->addHTML(" "); # Submit buttons & hidden values $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'ea_send', 'value' => wfMsg('ea_send')))); $wgOut->addHTML(wfElement('input',array('type' => 'submit','name' => 'ea_show', 'value' => wfMsg('ea_show')))); $wgOut->addHTML(wfElement('input',array('type' => 'hidden','name' => 'ea_title','value' => $this->title))); $wgOut->addHTML(' '); # If the show button was clicked, render the list if (isset($_REQUEST['ea_show'])) return $this->send(false); }	# Send the message to the recipients (or just list them if arg = false) function send($send = true) { global $wgOut,$wgUser,$wgParser,$wgServer,$wgScript,$wgArticlePath,$wgScriptPath, $wgEmailUsersGroup,$wgEmailUsersAllowRemoteAddr,$wgEmailUsersAllowAllUsers; # Set error and bail if user not in postmaster group, and request not from trusted address if ($wgEmailUsersGroup && !in_array($wgEmailUsersGroup,$wgUser->getGroups) && !in_array($_SERVER['REMOTE_ADDR'],$wgEmailUsersAllowRemoteAddr)) { $wgOut->addWikiText(wfMsg('ea_error',$this->title,'Permission denied')); return false; }		$db      = &wfGetDB(DB_SLAVE); $title   = Title::newFromText($this->title); $opt     = new ParserOptions; # Get contact article titles from selected cat if ($this->cat) { $cl    = $db->tableName('categorylinks'); $result = $db->query("SELECT cl_from FROM $cl WHERE cl_to = '{$this->cat}' ORDER BY cl_sortkey"); while ($row = mysql_fetch_row($result)) $this->addRecipient(Title::newFromID($row[0])); }		# Get email addresses from users in selected group if ($this->group && ($wgEmailUsersAllowAllUsers || $this->group != 'user')) { $u = str_replace('`','',$db->tableName('user')); $ug = str_replace('`','',$db->tableName('user_groups')); if ($this->group == 'user') $sql = "SELECT user_email FROM $u WHERE user_email != ''"; else $sql = "SELECT $u.user_email FROM $u,$ug WHERE $ug.ug_user = $u.user_id AND $ug.ug_group = '{$this->group}'"; $result = $db->query($sql); if ($result instanceof ResultWrapper) $result = $result->result; while ($row = $db->fetchRow($result)) $this->addRecipient($row[0]); }		# Recipients from list (expand templates in wikitext) $list = $wgParser->preprocess($this->list,$title,$opt); foreach (preg_split("/[\\x00-\\x1f,;*]+/",$list) as $item) $this->addRecipient($item); # Compose the wikitext content of the article to send

if ($this->header) $message = "{$this->header}\n\n$message"; # Convert the message text to html unless textonly if ($this->textonly == '') { # Parse the wikitext using absolute URL's for local article links $tmp          = array($wgArticlePath,$wgScriptPath,$wgScript); $wgArticlePath = $wgServer.$wgArticlePath; $wgScriptPath = $wgServer.$wgScriptPath; $wgScript     = $wgServer.$wgScript; $message      = $wgParser->parse($message,$title,$opt,true,true)->getText; list($wgArticlePath,$wgScriptPath,$wgScript) = $tmp;

# Create a html wrapper for the message $head   = "  "; $message = " $head$message "; }		# Send message or list recipients $count = count($this->recipients); if ($count > 0) { # Set up new mailer instance if sending if ($send) { $mail          = new PHPMailer; $mail->From    = $wgUser->isValidEmailAddr($wgUser->getEmail) ? $wgUser->getEmail : "wiki@$wgServer"; $mail->FromName = User::whoIsReal($wgUser->getId); $mail->Subject = $this->subject; $mail->Body    = $message; $mail->IsHTML(!$this->textonly); }			else $msg = wfMsg('ea_listrecipients',$count); # Loop through recipients sending or adding to list foreach ($this->recipients as $recipient) $send ? $mail->AddAddress($recipient) : $msg .= "\n*[mailto:$recipient $recipient]"; if ($send) { if ($state = $mail->Send) $msg = wfMsg('ea_sent',$this->title,$count,$wgUser->getName); else $msg = wfMsg('ea_error',$this->title,$mail->ErrorInfo); }			else $state = $count; }		else $msg = wfMsg('ea_error',$this->title,wfMsg('ea_norecipients')); $wgOut->addWikiText($msg); return $state; }	# Add a recipient the list # - accepts title objects for article containing email address, or string of actual address function addRecipient($recipient) { if (is_object($recipient) && $recipient->exists) { $article = new Article($recipient); if (preg_match('/[a-z0-9_.-]+@[a-z0-9_.-]+/i',$article->getContent,$emails)) $recipient = $emails[0]; else $recipient = ''; }		if ($valid = User::isValidEmailAddr($recipient)) $this->recipients[] = $recipient; return $valid; }	} function wfSetupEmailUsers { global $wgLanguageCode,$wgMessageCache; # Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'EmailUsers'       => "EmailUsers", 'ea_heading'         => "=== Send an email to users of your Wiki. ===\nUse the form below to send a mass email to selected users or groups.", 'ea_norecipients'    => "No valid email addresses found!", 'ea_listrecipients'  => "=== List of $1 recipients ===", 'ea_error'           => "Error sending email: $2", 'ea_sent'            => "Your email has successfully been sent to $2 recipient(s).  Send another email or return to the Main Page.", 'ea_selectrecipients' => "Select recipients", 'ea_compose'         => "Compose content", 'ea_selectlist'      => "Send to additional recipients\n" . "*''separate email addresses with a semicolon  No Spaces", 'ea_show'            => "Show recipients", 'ea_send'            => "Send!", 'ea_subject'         => "Enter a subject line for the email (HTML allowed)", 'ea_header'          => "Body of your email", ));		}	# Add the specialpage to the environment SpecialPage::addPage(new SpecialEmailUsers); } ?>
 * 1) Called from $wgExtensionFunctions array when initialising extensions

Copy and paste this into class.phpmailer.php and place it in your EmailUsers folder.