2004-02-28 07:08:13 +00:00
|
|
|
<?php
|
2005-01-27 18:19:16 +00:00
|
|
|
/**
|
|
|
|
|
* UserMailer.php
|
|
|
|
|
* Copyright (C) 2004 Thomas Gries <mail@tgries.de>
|
|
|
|
|
* http://www.mediawiki.org/
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-01-27 18:19:16 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* @author <brion@pobox.com>
|
|
|
|
|
* @author <mail@tgries.de>
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2005-05-14 17:55:04 +00:00
|
|
|
* Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-05-14 17:55:04 +00:00
|
|
|
function wfRFC822Phrase( $phrase ) {
|
|
|
|
|
$phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
|
|
|
|
|
return '"' . $phrase . '"';
|
2004-12-18 03:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-12 06:04:45 +00:00
|
|
|
class MailAddress {
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $address String with an email address, or a User object
|
|
|
|
|
* @param string $name Human-readable name if a string address is given
|
|
|
|
|
*/
|
|
|
|
|
function MailAddress( $address, $name=null ) {
|
|
|
|
|
if( is_object( $address ) && is_a( $address, 'User' ) ) {
|
|
|
|
|
$this->address = $address->getEmail();
|
|
|
|
|
$this->name = $address->getName();
|
|
|
|
|
} else {
|
|
|
|
|
$this->address = strval( $address );
|
|
|
|
|
$this->name = strval( $name );
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-12 06:04:45 +00:00
|
|
|
/**
|
|
|
|
|
* Return formatted and quoted address to insert into SMTP headers
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function toString() {
|
2006-08-30 13:51:37 +00:00
|
|
|
# PHP's mail() implementation under Windows is somewhat shite, and
|
|
|
|
|
# can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
|
|
|
|
|
# so don't bother generating them
|
|
|
|
|
if( $this->name != '' && !wfIsWindows() ) {
|
2006-06-09 08:24:47 +00:00
|
|
|
$quoted = wfQuotedPrintable( $this->name );
|
|
|
|
|
if( strpos( $quoted, '.' ) !== false ) {
|
|
|
|
|
$quoted = '"' . $quoted . '"';
|
|
|
|
|
}
|
|
|
|
|
return "$quoted <{$this->address}>";
|
2005-12-12 06:04:45 +00:00
|
|
|
} else {
|
|
|
|
|
return $this->address;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @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: false).
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
function userMailer( $to, $from, $subject, $body, $replyto=false ) {
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgUser, $wgSMTP, $wgOutputEncoding, $wgErrorString;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 03:47:11 +00:00
|
|
|
if (is_array( $wgSMTP )) {
|
2004-08-22 17:24:50 +00:00
|
|
|
require_once( 'Mail.php' );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-02-27 12:48:07 +00:00
|
|
|
$timestamp = time();
|
2006-06-09 08:24:47 +00:00
|
|
|
$dest = $to->address;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-12 06:04:45 +00:00
|
|
|
$headers['From'] = $from->toString();
|
2006-06-09 08:24:47 +00:00
|
|
|
$headers['To'] = $to->toString();
|
2005-05-14 17:55:04 +00:00
|
|
|
if ( $replyto ) {
|
|
|
|
|
$headers['Reply-To'] = $replyto;
|
|
|
|
|
}
|
2005-12-12 06:04:45 +00:00
|
|
|
$headers['Subject'] = wfQuotedPrintable( $subject );
|
2005-12-12 04:51:53 +00:00
|
|
|
$headers['Date'] = date( 'r' );
|
2004-08-22 17:24:50 +00:00
|
|
|
$headers['MIME-Version'] = '1.0';
|
|
|
|
|
$headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
|
|
|
|
|
$headers['Content-transfer-encoding'] = '8bit';
|
2005-12-12 06:04:45 +00:00
|
|
|
$headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>'; // FIXME
|
2004-12-18 03:47:11 +00:00
|
|
|
$headers['X-Mailer'] = 'MediaWiki mailer';
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-02-27 12:48:07 +00:00
|
|
|
// Create the mail object using the Mail::factory method
|
2004-08-22 17:24:50 +00:00
|
|
|
$mail_object =& Mail::factory('smtp', $wgSMTP);
|
2006-06-09 08:24:47 +00:00
|
|
|
wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
|
2005-12-12 06:04:45 +00:00
|
|
|
$mailResult =& $mail_object->send($dest, $headers, $body);
|
2005-08-02 13:35:19 +00:00
|
|
|
|
|
|
|
|
# Based on the result return an error string,
|
2005-12-04 20:20:03 +00:00
|
|
|
if ($mailResult === true) {
|
2004-08-22 17:24:50 +00:00
|
|
|
return '';
|
2005-12-04 20:20:03 +00:00
|
|
|
} elseif (is_object($mailResult)) {
|
2005-12-12 04:51:53 +00:00
|
|
|
wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
|
2004-02-27 12:48:07 +00:00
|
|
|
return $mailResult->getMessage();
|
2005-12-04 20:20:03 +00:00
|
|
|
} else {
|
2005-12-12 04:51:53 +00:00
|
|
|
wfDebug( "PEAR::Mail failed, unknown error result\n" );
|
2004-08-22 17:24:50 +00:00
|
|
|
return 'Mail object return unknown error.';
|
2005-12-04 20:20:03 +00:00
|
|
|
}
|
2004-12-18 03:47:11 +00:00
|
|
|
} else {
|
|
|
|
|
# In the following $headers = expression we removed "Reply-To: {$from}\r\n" , because it is treated differently
|
|
|
|
|
# (fifth parameter of the PHP mail function, see some lines below)
|
2004-02-27 12:48:07 +00:00
|
|
|
$headers =
|
2004-08-15 23:48:39 +00:00
|
|
|
"MIME-Version: 1.0\n" .
|
|
|
|
|
"Content-type: text/plain; charset={$wgOutputEncoding}\n" .
|
2004-12-18 03:47:11 +00:00
|
|
|
"Content-Transfer-Encoding: 8bit\n" .
|
|
|
|
|
"X-Mailer: MediaWiki mailer\n".
|
2005-12-12 06:04:45 +00:00
|
|
|
'From: ' . $from->toString() . "\n";
|
2004-12-18 03:47:11 +00:00
|
|
|
if ($replyto) {
|
2005-05-14 17:55:04 +00:00
|
|
|
$headers .= "Reply-To: $replyto\n";
|
2004-12-18 03:47:11 +00:00
|
|
|
}
|
2004-04-01 13:05:20 +00:00
|
|
|
|
2005-12-12 06:04:45 +00:00
|
|
|
$dest = $to->toString();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgErrorString = '';
|
|
|
|
|
set_error_handler( 'mailErrorHandler' );
|
2005-12-12 06:04:45 +00:00
|
|
|
wfDebug( "Sending mail via internal mail() function to $dest\n" );
|
|
|
|
|
mail( $dest, wfQuotedPrintable( $subject ), $body, $headers );
|
2004-04-01 13:05:20 +00:00
|
|
|
restore_error_handler();
|
|
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
if ( $wgErrorString ) {
|
|
|
|
|
wfDebug( "Error sending mail: $wgErrorString\n" );
|
|
|
|
|
}
|
2004-04-01 13:05:20 +00:00
|
|
|
return $wgErrorString;
|
2004-02-27 12:48:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2005-12-04 20:20:03 +00:00
|
|
|
* Get the mail error message in global $wgErrorString
|
|
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $code Integer: error number
|
|
|
|
|
* @param $string String: error message
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-04-01 13:05:20 +00:00
|
|
|
function mailErrorHandler( $code, $string ) {
|
|
|
|
|
global $wgErrorString;
|
2005-12-04 20:20:03 +00:00
|
|
|
$wgErrorString = preg_replace( "/^mail\(\): /", '', $string );
|
2004-04-01 13:05:20 +00:00
|
|
|
}
|
2004-12-18 03:47:11 +00:00
|
|
|
|
|
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
/**
|
2005-01-27 18:19:16 +00:00
|
|
|
* This module processes the email notifications when the current page is
|
|
|
|
|
* changed. It looks up the table watchlist to find out which users are watching
|
|
|
|
|
* that page.
|
2004-12-18 10:23:54 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* The current implementation sends independent emails to each watching user for
|
|
|
|
|
* the following reason:
|
2004-12-18 10:23:54 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* - Each watching user will be notified about the page edit time expressed in
|
|
|
|
|
* his/her local time (UTC is shown additionally). To achieve this, we need to
|
|
|
|
|
* find the individual timeoffset of each watching user from the preferences..
|
2004-12-18 10:23:54 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* Suggested improvement to slack down the number of sent emails: We could think
|
|
|
|
|
* of sending out bulk mails (bcc:user1,user2...) for all these users having the
|
|
|
|
|
* same timeoffset in their preferences.
|
2004-12-18 10:23:54 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* Visit the documentation pages under http://meta.wikipedia.com/Enotif
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* @package MediaWiki
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2004-12-18 10:23:54 +00:00
|
|
|
*/
|
|
|
|
|
class EmailNotification {
|
2006-04-19 15:46:24 +00:00
|
|
|
/**@{{
|
|
|
|
|
* @private
|
2005-01-27 18:19:16 +00:00
|
|
|
*/
|
2004-12-18 10:23:54 +00:00
|
|
|
var $to, $subject, $body, $replyto, $from;
|
2005-05-14 17:55:04 +00:00
|
|
|
var $user, $title, $timestamp, $summary, $minorEdit, $oldid;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2006-04-19 15:46:24 +00:00
|
|
|
/**@}}*/
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-01-27 18:19:16 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $title Title object
|
2005-01-27 18:19:16 +00:00
|
|
|
* @param $timestamp
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $summary
|
|
|
|
|
* @param $minorEdit
|
2005-01-27 18:19:16 +00:00
|
|
|
* @param $oldid (default: false)
|
|
|
|
|
*/
|
2005-05-14 17:55:04 +00:00
|
|
|
function notifyOnPageChange(&$title, $timestamp, $summary, $minorEdit, $oldid=false) {
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# we use $wgEmergencyContact as sender's address
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgUser, $wgEnotifWatchlist;
|
|
|
|
|
global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
|
2005-05-14 17:55:04 +00:00
|
|
|
|
2005-05-28 15:33:22 +00:00
|
|
|
$fname = 'UserMailer::notifyOnPageChange';
|
|
|
|
|
wfProfileIn( $fname );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# The following code is only run, if several conditions are met:
|
|
|
|
|
# 1. EmailNotification for pages (other than user_talk pages) must be enabled
|
|
|
|
|
# 2. minor edits (changes) are only regarded if the global flag indicates so
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
$isUserTalkPage = ($title->getNamespace() == NS_USER_TALK);
|
|
|
|
|
$enotifusertalkpage = ($isUserTalkPage && $wgEnotifUserTalk);
|
2005-12-07 11:52:34 +00:00
|
|
|
$enotifwatchlistpage = $wgEnotifWatchlist;
|
|
|
|
|
|
|
|
|
|
if ( (!$minorEdit || $wgEnotifMinorEdits) ) {
|
|
|
|
|
if( $wgEnotifWatchlist ) {
|
|
|
|
|
// Send updates to watchers other than the current editor
|
|
|
|
|
$userCondition = 'wl_user <> ' . intval( $wgUser->getId() );
|
|
|
|
|
} elseif( $wgEnotifUserTalk && $title->getNamespace() == NS_USER_TALK ) {
|
|
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
|
|
|
|
if( is_null( $targetUser ) ) {
|
|
|
|
|
wfDebug( "$fname: user-talk-only mode; no such user\n" );
|
|
|
|
|
$userCondition = false;
|
|
|
|
|
} elseif( $targetUser->getId() == $wgUser->getId() ) {
|
|
|
|
|
wfDebug( "$fname: user-talk-only mode; editor is target user\n" );
|
|
|
|
|
$userCondition = false;
|
|
|
|
|
} else {
|
|
|
|
|
// Don't notify anyone other than the owner of the talk page
|
|
|
|
|
$userCondition = 'wl_user = ' . intval( $targetUser->getId() );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Notifications disabled
|
|
|
|
|
$userCondition = false;
|
|
|
|
|
}
|
|
|
|
|
if( $userCondition ) {
|
|
|
|
|
$dbr =& wfGetDB( DB_MASTER );
|
|
|
|
|
extract( $dbr->tableNames( 'watchlist' ) );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
$res = $dbr->select( 'watchlist', array( 'wl_user' ),
|
|
|
|
|
array(
|
|
|
|
|
'wl_title' => $title->getDBkey(),
|
|
|
|
|
'wl_namespace' => $title->getNamespace(),
|
|
|
|
|
$userCondition,
|
|
|
|
|
'wl_notificationtimestamp IS NULL',
|
|
|
|
|
), $fname );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
# if anyone is watching ... set up the email message text which is
|
|
|
|
|
# common for all receipients ...
|
|
|
|
|
if ( $dbr->numRows( $res ) > 0 ) {
|
|
|
|
|
$this->title =& $title;
|
|
|
|
|
$this->timestamp = $timestamp;
|
|
|
|
|
$this->summary = $summary;
|
|
|
|
|
$this->minorEdit = $minorEdit;
|
|
|
|
|
$this->oldid = $oldid;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
$this->composeCommonMailtext();
|
|
|
|
|
$watchingUser = new User();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
# ... now do for all watching users ... if the options fit
|
|
|
|
|
for ($i = 1; $i <= $dbr->numRows( $res ); $i++) {
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
$wuser = $dbr->fetchObject( $res );
|
|
|
|
|
$watchingUser->setID($wuser->wl_user);
|
2006-08-18 01:43:33 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
if ( ( $enotifwatchlistpage && $watchingUser->getOption('enotifwatchlistpages') ) ||
|
2006-08-18 01:43:33 +00:00
|
|
|
( $enotifusertalkpage
|
|
|
|
|
&& $watchingUser->getOption('enotifusertalkpages')
|
|
|
|
|
&& $title->equals( $watchingUser->getTalkPage() ) )
|
2005-12-07 11:52:34 +00:00
|
|
|
&& (!$minorEdit || ($wgEnotifMinorEdits && $watchingUser->getOption('enotifminoredits') ) )
|
|
|
|
|
&& ($watchingUser->isEmailConfirmed() ) ) {
|
|
|
|
|
# ... adjust remaining text and page edit time placeholders
|
|
|
|
|
# which needs to be personalized for each user
|
|
|
|
|
$this->composeAndSendPersonalisedMail( $watchingUser );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-07 11:52:34 +00:00
|
|
|
} # if the watching user has an email address in the preferences
|
|
|
|
|
}
|
2005-05-28 15:33:22 +00:00
|
|
|
}
|
2004-12-18 10:23:54 +00:00
|
|
|
} # if anyone is watching
|
2005-05-14 17:55:04 +00:00
|
|
|
} # if $wgEnotifWatchlist = true
|
2005-05-29 04:29:29 +00:00
|
|
|
|
|
|
|
|
if ( $wgShowUpdatedMarker || $wgEnotifWatchlist ) {
|
2005-08-02 13:35:19 +00:00
|
|
|
# mark the changed watch-listed page with a timestamp, so that the page is
|
2005-05-29 04:29:29 +00:00
|
|
|
# listed with an "updated since your last visit" icon in the watch list, ...
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
$success = $dbw->update( 'watchlist',
|
|
|
|
|
array( /* SET */
|
2005-08-02 13:35:19 +00:00
|
|
|
'wl_notificationtimestamp' => $dbw->timestamp($timestamp)
|
2005-05-29 04:29:29 +00:00
|
|
|
), array( /* WHERE */
|
|
|
|
|
'wl_title' => $title->getDBkey(),
|
|
|
|
|
'wl_namespace' => $title->getNamespace(),
|
|
|
|
|
), 'UserMailer::NotifyOnChange'
|
|
|
|
|
);
|
2005-12-04 20:20:03 +00:00
|
|
|
# FIXME what do we do on failure ?
|
2005-05-29 04:29:29 +00:00
|
|
|
}
|
2006-07-26 03:51:49 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-12-18 10:23:54 +00:00
|
|
|
} # function NotifyOnChange
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
/**
|
2006-04-19 15:46:24 +00:00
|
|
|
* @private
|
2004-12-18 10:23:54 +00:00
|
|
|
*/
|
2005-05-14 17:55:04 +00:00
|
|
|
function composeCommonMailtext() {
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgUser, $wgEmergencyContact, $wgNoReplyAddress;
|
|
|
|
|
global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
$summary = ($this->summary == '') ? ' - ' : $this->summary;
|
|
|
|
|
$medit = ($this->minorEdit) ? wfMsg( 'minoredit' ) : '';
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# You as the WikiAdmin and Sysops can make use of plenty of
|
|
|
|
|
# named variables when composing your notification emails while
|
|
|
|
|
# simply editing the Meta pages
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
$subject = wfMsgForContent( 'enotif_subject' );
|
|
|
|
|
$body = wfMsgForContent( 'enotif_body' );
|
2004-12-18 10:23:54 +00:00
|
|
|
$from = ''; /* fail safe */
|
|
|
|
|
$replyto = ''; /* fail safe */
|
|
|
|
|
$keys = array();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# regarding the use of oldid as an indicator for the last visited version, see also
|
|
|
|
|
# http://bugzilla.wikipeda.org/show_bug.cgi?id=603 "Delete + undelete cycle doesn't preserve old_id"
|
|
|
|
|
# However, in the case of a new page which is already watched, we have no previous version to compare
|
2005-05-14 17:55:04 +00:00
|
|
|
if( $this->oldid ) {
|
2005-07-10 02:52:33 +00:00
|
|
|
$difflink = $this->title->getFullUrl( 'diff=0&oldid=' . $this->oldid );
|
|
|
|
|
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
|
2005-05-14 17:55:04 +00:00
|
|
|
$keys['$OLDID'] = $this->oldid;
|
|
|
|
|
$keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
|
2004-12-18 03:47:11 +00:00
|
|
|
} else {
|
2005-05-14 17:55:04 +00:00
|
|
|
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' );
|
2004-12-18 10:23:54 +00:00
|
|
|
# clear $OLDID placeholder in the message template
|
|
|
|
|
$keys['$OLDID'] = '';
|
2005-05-14 17:55:04 +00:00
|
|
|
$keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
|
2004-12-18 03:47:11 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
|
|
|
|
$body = strtr( $body, $keys );
|
2005-05-14 17:55:04 +00:00
|
|
|
$pagetitle = $this->title->getPrefixedText();
|
2004-12-18 10:23:54 +00:00
|
|
|
$keys['$PAGETITLE'] = $pagetitle;
|
2005-07-10 02:52:33 +00:00
|
|
|
$keys['$PAGETITLE_URL'] = $this->title->getFullUrl();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
$keys['$PAGEMINOREDIT'] = $medit;
|
|
|
|
|
$keys['$PAGESUMMARY'] = $summary;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
$subject = strtr( $subject, $keys );
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# Reveal the page editor's address as REPLY-TO address only if
|
|
|
|
|
# the user has not opted-out and the option is enabled at the
|
|
|
|
|
# global configuration level.
|
2005-05-14 17:55:04 +00:00
|
|
|
$name = $wgUser->getName();
|
2005-12-12 06:04:45 +00:00
|
|
|
$adminAddress = new MailAddress( $wgEmergencyContact, 'WikiAdmin' );
|
|
|
|
|
$editorAddress = new MailAddress( $wgUser );
|
2005-05-14 17:55:04 +00:00
|
|
|
if( $wgEnotifRevealEditorAddress
|
|
|
|
|
&& ( $wgUser->getEmail() != '' )
|
|
|
|
|
&& $wgUser->getOption( 'enotifrevealaddr' ) ) {
|
|
|
|
|
if( $wgEnotifFromEditor ) {
|
2004-12-18 10:23:54 +00:00
|
|
|
$from = $editorAddress;
|
|
|
|
|
} else {
|
|
|
|
|
$from = $adminAddress;
|
|
|
|
|
$replyto = $editorAddress;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$from = $adminAddress;
|
|
|
|
|
$replyto = $wgNoReplyAddress;
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
if( $wgUser->isIP( $name ) ) {
|
2004-12-18 10:23:54 +00:00
|
|
|
#real anon (user:xxx.xxx.xxx.xxx)
|
2005-03-26 01:21:01 +00:00
|
|
|
$subject = str_replace('$PAGEEDITOR', 'anonymous user '. $name, $subject);
|
2005-07-10 02:52:33 +00:00
|
|
|
$keys['$PAGEEDITOR'] = 'anonymous user ' . $name;
|
|
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
|
2004-12-18 10:23:54 +00:00
|
|
|
} else {
|
2005-03-26 01:21:01 +00:00
|
|
|
$subject = str_replace('$PAGEEDITOR', $name, $subject);
|
|
|
|
|
$keys['$PAGEEDITOR'] = $name;
|
2005-07-10 02:52:33 +00:00
|
|
|
$emailPage = Title::makeTitle( NS_SPECIAL, 'Emailuser/' . $name );
|
|
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = $emailPage->getFullUrl();
|
2004-12-18 10:23:54 +00:00
|
|
|
}
|
2005-07-10 02:52:33 +00:00
|
|
|
$userPage = $wgUser->getUserPage();
|
|
|
|
|
$keys['$PAGEEDITOR_WIKI'] = $userPage->getFullUrl();
|
2004-12-18 10:23:54 +00:00
|
|
|
$body = strtr( $body, $keys );
|
2005-07-10 02:52:33 +00:00
|
|
|
$body = wordwrap( $body, 72 );
|
|
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# now save this as the constant user-independent part of the message
|
|
|
|
|
$this->from = $from;
|
|
|
|
|
$this->replyto = $replyto;
|
2005-05-14 17:55:04 +00:00
|
|
|
$this->subject = $subject;
|
2004-12-18 10:23:54 +00:00
|
|
|
$this->body = $body;
|
2004-12-18 03:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
/**
|
|
|
|
|
* Does the per-user customizations to a notification e-mail (name,
|
|
|
|
|
* timestamp in proper timezone, etc) and sends it out.
|
|
|
|
|
* Returns true if the mail was sent successfully.
|
|
|
|
|
*
|
|
|
|
|
* @param User $watchingUser
|
|
|
|
|
* @param object $mail
|
|
|
|
|
* @return bool
|
2006-04-19 15:46:24 +00:00
|
|
|
* @private
|
2004-12-18 10:23:54 +00:00
|
|
|
*/
|
2005-05-14 17:55:04 +00:00
|
|
|
function composeAndSendPersonalisedMail( $watchingUser ) {
|
2004-12-18 10:23:54 +00:00
|
|
|
global $wgLang;
|
2005-05-14 17:55:04 +00:00
|
|
|
// From the PHP manual:
|
2005-08-02 13:35:19 +00:00
|
|
|
// Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
|
2005-05-14 17:55:04 +00:00
|
|
|
// The mail command will not parse this properly while talking with the MTA.
|
2005-12-12 06:04:45 +00:00
|
|
|
$to = new MailAddress( $watchingUser );
|
2005-05-14 17:55:04 +00:00
|
|
|
$body = str_replace( '$WATCHINGUSERNAME', $watchingUser->getName() , $this->body );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
$timecorrection = $watchingUser->getOption( 'timecorrection' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
# $PAGEEDITDATE is the time and date of the page change
|
|
|
|
|
# expressed in terms of individual local time of the notification
|
|
|
|
|
# recipient, i.e. watching user
|
|
|
|
|
$body = str_replace('$PAGEEDITDATE',
|
2005-05-14 17:55:04 +00:00
|
|
|
$wgLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
|
2004-12-18 10:23:54 +00:00
|
|
|
$body);
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-05-14 17:55:04 +00:00
|
|
|
$error = userMailer( $to, $this->from, $this->subject, $body, $this->replyto );
|
2004-12-18 10:23:54 +00:00
|
|
|
return ($error == '');
|
|
|
|
|
}
|
2004-12-18 03:47:11 +00:00
|
|
|
|
|
|
|
|
} # end of class EmailNotification
|
2004-04-01 13:05:20 +00:00
|
|
|
?>
|