2004-02-28 07:08:13 +00:00
|
|
|
<?php
|
2005-01-27 18:19:16 +00:00
|
|
|
/**
|
|
|
|
|
* 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>
|
2007-10-03 08:46:17 +00:00
|
|
|
* @author Tim Starling
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
|
|
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
|
|
|
|
* Stores a single person's name and email address.
|
|
|
|
|
* These are passed in via the constructor, and will be returned in SMTP
|
|
|
|
|
* header format when requested.
|
|
|
|
|
*/
|
2005-12-12 06:04:45 +00:00
|
|
|
class MailAddress {
|
|
|
|
|
/**
|
2008-06-27 10:24:00 +00:00
|
|
|
* @param $address Mixed: string with an email address, or a User object
|
|
|
|
|
* @param $name String: human-readable name if a string address is given
|
2005-12-12 06:04:45 +00:00
|
|
|
*/
|
2008-11-03 21:31:47 +00:00
|
|
|
function __construct( $address, $name = null, $realName = null ) {
|
2006-12-04 11:28:48 +00:00
|
|
|
if( is_object( $address ) && $address instanceof User ) {
|
2005-12-12 06:04:45 +00:00
|
|
|
$this->address = $address->getEmail();
|
|
|
|
|
$this->name = $address->getName();
|
2008-11-03 21:31:47 +00:00
|
|
|
$this->realName = $address->getRealName();
|
2005-12-12 06:04:45 +00:00
|
|
|
} else {
|
|
|
|
|
$this->address = strval( $address );
|
|
|
|
|
$this->name = strval( $name );
|
2008-11-03 21:31:47 +00:00
|
|
|
$this->reaName = strval( $realName );
|
2005-12-12 06:04:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
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() ) {
|
2008-11-03 21:31:47 +00:00
|
|
|
global $wgEnotifUseRealName;
|
|
|
|
|
$name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name;
|
|
|
|
|
$quoted = wfQuotedPrintable( $name );
|
2008-01-22 03:52:14 +00:00
|
|
|
if( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
|
2006-06-09 08:24:47 +00:00
|
|
|
$quoted = '"' . $quoted . '"';
|
|
|
|
|
}
|
|
|
|
|
return "$quoted <{$this->address}>";
|
2005-12-12 06:04:45 +00:00
|
|
|
} else {
|
|
|
|
|
return $this->address;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
function __toString() {
|
|
|
|
|
return $this->toString();
|
2007-05-05 12:08:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2007-10-03 08:46:17 +00:00
|
|
|
* Collection of static functions for sending mail
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-10-03 08:46:17 +00:00
|
|
|
class UserMailer {
|
|
|
|
|
/**
|
|
|
|
|
* Send mail using a PEAR mailer
|
|
|
|
|
*/
|
|
|
|
|
protected static function sendWithPear($mailer, $dest, $headers, $body)
|
|
|
|
|
{
|
2008-02-13 05:05:53 +00:00
|
|
|
$mailResult = $mailer->send($dest, $headers, $body);
|
2007-10-03 08:46:17 +00:00
|
|
|
|
|
|
|
|
# Based on the result return an error string,
|
2008-02-13 05:05:53 +00:00
|
|
|
if( PEAR::isError( $mailResult ) ) {
|
2007-10-03 08:46:17 +00:00
|
|
|
wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
|
2008-02-13 05:05:53 +00:00
|
|
|
return new WikiError( $mailResult->getMessage() );
|
2007-10-03 08:46:17 +00:00
|
|
|
} else {
|
2008-02-13 05:05:53 +00:00
|
|
|
return true;
|
2007-10-03 08:46:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2007-10-03 08:46:17 +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.
|
|
|
|
|
*
|
|
|
|
|
* @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).
|
2008-08-27 21:15:42 +00:00
|
|
|
* @param $contentType String: optional custom Content-Type
|
2008-02-13 05:05:53 +00:00
|
|
|
* @return mixed True on success, a WikiError object on failure.
|
2007-10-03 08:46:17 +00:00
|
|
|
*/
|
2008-08-27 21:15:42 +00:00
|
|
|
static function send( $to, $from, $subject, $body, $replyto=null, $contentType=null ) {
|
2007-10-03 08:46:17 +00:00
|
|
|
global $wgSMTP, $wgOutputEncoding, $wgErrorString, $wgEnotifImpersonal;
|
|
|
|
|
global $wgEnotifMaxRecips;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if ( is_array( $to ) ) {
|
|
|
|
|
wfDebug( __METHOD__.': sending mail to ' . implode( ',', $to ) . "\n" );
|
|
|
|
|
} else {
|
2007-10-11 07:04:59 +00:00
|
|
|
wfDebug( __METHOD__.': sending mail to ' . implode( ',', array( $to->toString() ) ) . "\n" );
|
2007-10-03 08:46:17 +00:00
|
|
|
}
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if (is_array( $wgSMTP )) {
|
|
|
|
|
require_once( 'Mail.php' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
$msgid = str_replace(" ", "_", microtime());
|
|
|
|
|
if (function_exists('posix_getpid'))
|
|
|
|
|
$msgid .= '.' . posix_getpid();
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if (is_array($to)) {
|
|
|
|
|
$dest = array();
|
|
|
|
|
foreach ($to as $u)
|
|
|
|
|
$dest[] = $u->address;
|
|
|
|
|
} else
|
|
|
|
|
$dest = $to->address;
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
$headers['From'] = $from->toString();
|
|
|
|
|
|
2008-05-26 09:48:52 +00:00
|
|
|
if ($wgEnotifImpersonal) {
|
2007-10-03 08:46:17 +00:00
|
|
|
$headers['To'] = 'undisclosed-recipients:;';
|
2008-05-26 09:48:52 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$headers['To'] = implode( ", ", (array )$dest );
|
|
|
|
|
}
|
2006-10-04 23:35:29 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if ( $replyto ) {
|
|
|
|
|
$headers['Reply-To'] = $replyto->toString();
|
|
|
|
|
}
|
|
|
|
|
$headers['Subject'] = wfQuotedPrintable( $subject );
|
|
|
|
|
$headers['Date'] = date( 'r' );
|
|
|
|
|
$headers['MIME-Version'] = '1.0';
|
2008-08-27 21:15:42 +00:00
|
|
|
$headers['Content-type'] = (is_null($contentType) ?
|
|
|
|
|
'text/plain; charset='.$wgOutputEncoding : $contentType);
|
2007-10-03 08:46:17 +00:00
|
|
|
$headers['Content-transfer-encoding'] = '8bit';
|
|
|
|
|
$headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME
|
|
|
|
|
$headers['X-Mailer'] = 'MediaWiki mailer';
|
|
|
|
|
|
|
|
|
|
// Create the mail object using the Mail::factory method
|
|
|
|
|
$mail_object =& Mail::factory('smtp', $wgSMTP);
|
|
|
|
|
if( PEAR::isError( $mail_object ) ) {
|
|
|
|
|
wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
|
2008-02-13 05:05:53 +00:00
|
|
|
return new WikiError( $mail_object->getMessage() );
|
2007-05-05 12:08:24 +00:00
|
|
|
}
|
2004-04-01 13:05:20 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
|
2008-02-13 05:05:53 +00:00
|
|
|
$chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
|
|
|
|
|
foreach ($chunks as $chunk) {
|
|
|
|
|
$e = self::sendWithPear($mail_object, $chunk, $headers, $body);
|
|
|
|
|
if( WikiError::isError( $e ) )
|
|
|
|
|
return $e;
|
|
|
|
|
}
|
2007-10-03 08:46:17 +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)
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
# Line endings need to be different on Unix and Windows due to
|
2007-10-03 08:46:17 +00:00
|
|
|
# the bug described at http://trac.wordpress.org/ticket/2603
|
|
|
|
|
if ( wfIsWindows() ) {
|
|
|
|
|
$body = str_replace( "\n", "\r\n", $body );
|
|
|
|
|
$endl = "\r\n";
|
|
|
|
|
} else {
|
|
|
|
|
$endl = "\n";
|
|
|
|
|
}
|
2008-08-27 21:15:42 +00:00
|
|
|
$ctype = (is_null($contentType) ?
|
|
|
|
|
'text/plain; charset='.$wgOutputEncoding : $contentType);
|
2007-10-03 08:46:17 +00:00
|
|
|
$headers =
|
|
|
|
|
"MIME-Version: 1.0$endl" .
|
2008-08-27 21:15:42 +00:00
|
|
|
"Content-type: $ctype$endl" .
|
2007-10-03 08:46:17 +00:00
|
|
|
"Content-Transfer-Encoding: 8bit$endl" .
|
|
|
|
|
"X-Mailer: MediaWiki mailer$endl".
|
|
|
|
|
'From: ' . $from->toString();
|
|
|
|
|
if ($replyto) {
|
|
|
|
|
$headers .= "{$endl}Reply-To: " . $replyto->toString();
|
|
|
|
|
}
|
2007-05-06 07:14:10 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
$wgErrorString = '';
|
|
|
|
|
$html_errors = ini_get( 'html_errors' );
|
|
|
|
|
ini_set( 'html_errors', '0' );
|
|
|
|
|
set_error_handler( array( 'UserMailer', 'errorHandler' ) );
|
|
|
|
|
wfDebug( "Sending mail via internal mail() function\n" );
|
2007-07-12 21:16:03 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if (function_exists('mail')) {
|
|
|
|
|
if (is_array($to)) {
|
|
|
|
|
foreach ($to as $recip) {
|
|
|
|
|
$sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$wgErrorString = 'PHP is not configured to send mail';
|
|
|
|
|
}
|
2007-05-06 07:14:10 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
restore_error_handler();
|
|
|
|
|
ini_set( 'html_errors', $html_errors );
|
2004-04-01 13:05:20 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
if ( $wgErrorString ) {
|
|
|
|
|
wfDebug( "Error sending mail: $wgErrorString\n" );
|
2008-02-13 05:05:53 +00:00
|
|
|
return new WikiError( $wgErrorString );
|
2007-10-03 08:46:17 +00:00
|
|
|
} elseif (! $sent) {
|
|
|
|
|
//mail function only tells if there's an error
|
|
|
|
|
wfDebug( "Error sending mail\n" );
|
2008-02-13 05:05:53 +00:00
|
|
|
return new WikiError( 'mailer error' );
|
2007-10-03 08:46:17 +00:00
|
|
|
} else {
|
2008-02-13 05:05:53 +00:00
|
|
|
return true;
|
2007-10-03 08:46:17 +00:00
|
|
|
}
|
2005-05-14 17:55:04 +00:00
|
|
|
}
|
2007-07-12 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/**
|
|
|
|
|
* Get the mail error message in global $wgErrorString
|
|
|
|
|
*
|
|
|
|
|
* @param $code Integer: error number
|
|
|
|
|
* @param $string String: error message
|
|
|
|
|
*/
|
|
|
|
|
static function errorHandler( $code, $string ) {
|
|
|
|
|
global $wgErrorString;
|
2008-07-09 17:49:51 +00:00
|
|
|
$wgErrorString = preg_replace( '/^mail\(\)(\s*\[.*?\])?: /', '', $string );
|
2007-10-03 08:46:17 +00:00
|
|
|
}
|
2007-07-12 21:25:22 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/**
|
|
|
|
|
* Converts a string into a valid RFC 822 "phrase", such as is used for the sender name
|
|
|
|
|
*/
|
|
|
|
|
static function rfc822Phrase( $phrase ) {
|
|
|
|
|
$phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) );
|
|
|
|
|
return '"' . $phrase . '"';
|
|
|
|
|
}
|
2004-04-01 13:05:20 +00:00
|
|
|
}
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2004-12-18 10:23:54 +00:00
|
|
|
class EmailNotification {
|
2008-12-17 07:08:16 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Send users an email.
|
|
|
|
|
*
|
|
|
|
|
* @param $editor User whose action precipitated the notification.
|
|
|
|
|
* @param $timestamp of the event.
|
|
|
|
|
* @param Callback that returns an an array of Users who will recieve the notification.
|
|
|
|
|
* @param Callback that returns an array($keys, $body, $subject) where
|
|
|
|
|
* * $keys is a dictionary whose keys will be replaced with the corresponding
|
|
|
|
|
* values within the subject and body of the message.
|
|
|
|
|
* * $body is the name of the message that will be used for the email body.
|
|
|
|
|
* * $subject is the name of the message that will be used for the subject.
|
|
|
|
|
* Both messages are resolved using the content language.
|
|
|
|
|
* The messageCompositionFunction is invoked for each recipient user;
|
|
|
|
|
* The keys returned are merged with those given by EmailNotification::commonMessageKeys().
|
|
|
|
|
* The recipient is appended to the arguments given to messageCompositionFunction.
|
|
|
|
|
* Both callbacks are to be given in the same formats accepted by the hook system.
|
|
|
|
|
*/
|
2008-12-17 17:27:43 +00:00
|
|
|
static function notify( $editor, $timestamp, $userListFunction, $messageCompositionFunction ) {
|
2008-12-17 07:08:16 +00:00
|
|
|
global $wgEnotifUseRealName, $wgEnotifImpersonal;
|
|
|
|
|
global $wgLang;
|
|
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
$users = wfInvoke( 'userList', $userListFunction );
|
|
|
|
|
if( !count( $users ) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
$common_keys = self::commonMessageKeys( $editor );
|
|
|
|
|
foreach( $users as $u ) {
|
|
|
|
|
list( $user_keys, $body_msg_name, $subj_msg_name ) =
|
|
|
|
|
wfInvoke( 'message', $messageCompositionFunction, array( $u ) );
|
|
|
|
|
$keys = array_merge( $common_keys, $user_keys );
|
2008-12-17 07:08:16 +00:00
|
|
|
|
|
|
|
|
if( $wgEnotifImpersonal ) {
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$WATCHINGUSERNAME'] = wfMsgForContent( 'enotif_impersonal_salutation' );
|
|
|
|
|
$keys['$PAGEEDITDATE'] = $wgLang->timeanddate( $timestamp, true, false, false );
|
2008-12-17 07:08:16 +00:00
|
|
|
} else {
|
|
|
|
|
$keys['$WATCHINGUSERNAME'] = $wgEnotifUseRealName ? $u->getRealName() : $u->getName();
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$PAGEEDITDATE'] = $wgLang->timeAndDate( $timestamp, true, false,
|
|
|
|
|
$u->getOption( 'timecorrection' ) );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
$subject = strtr( wfMsgForContent( $subj_msg_name ), $keys );
|
2008-12-17 07:08:16 +00:00
|
|
|
$body = wordwrap( strtr( wfMsgForContent( $body_msg_name ), $keys ), 72 );
|
|
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
$to = new MailAddress( $u );
|
2008-12-17 07:08:16 +00:00
|
|
|
$from = $keys['$FROM_HEADER'];
|
|
|
|
|
$replyto = $keys['$REPLYTO_HEADER'];
|
2008-12-17 17:27:43 +00:00
|
|
|
UserMailer::send( $to, $from, $subject, $body, $replyto );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
static function commonMessageKeys( $editor ) {
|
2008-12-17 07:08:16 +00:00
|
|
|
global $wgEnotifUseRealName, $wgEnotifRevealEditorAddress;
|
|
|
|
|
global $wgNoReplyAddress, $wgPasswordSender;
|
|
|
|
|
|
|
|
|
|
$keys = array();
|
|
|
|
|
|
|
|
|
|
$name = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
|
|
|
|
|
|
|
|
|
|
$adminAddress = new MailAddress( $wgPasswordSender, 'WikiAdmin' );
|
|
|
|
|
$editorAddress = new MailAddress( $editor );
|
|
|
|
|
if( $wgEnotifRevealEditorAddress
|
|
|
|
|
&& $editor->getEmail() != ''
|
|
|
|
|
&& $editor->getOption( 'enotifrevealaddr' ) ) {
|
|
|
|
|
if( $wgEnotifFromEditor ) {
|
|
|
|
|
$from = $editorAddress;
|
|
|
|
|
} else {
|
|
|
|
|
$from = $adminAddress;
|
|
|
|
|
$replyto = $editorAddress;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$from = $adminAddress;
|
|
|
|
|
$replyto = new MailAddress( $wgNoReplyAddress );
|
|
|
|
|
}
|
|
|
|
|
$keys['$FROM_HEADER'] = $from;
|
|
|
|
|
$keys['$REPLYTO_HEADER'] = $replyto;
|
2007-03-28 14:16:43 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
if( $editor->isAnon() ) {
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $name );
|
2008-12-17 07:08:16 +00:00
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
|
|
|
|
|
} else{
|
|
|
|
|
$keys['$PAGEEDITOR'] = $name;
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = SpecialPage::getSafeTitleFor( 'Emailuser', $name )->getFullUrl();
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
$keys['$PAGEEDITOR_WIKI'] = $editor->getUserPage()->getFullUrl();
|
|
|
|
|
|
|
|
|
|
return $keys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @deprecated
|
|
|
|
|
* Use PageChangeNotification::notifyOnPageChange instead.
|
|
|
|
|
*/
|
|
|
|
|
function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) {
|
|
|
|
|
PageChangeNotification::notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageChangeNotification {
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Send emails corresponding to the user $editor editing the page $title.
|
2007-10-03 08:46:17 +00:00
|
|
|
* Also updates wl_notificationtimestamp.
|
|
|
|
|
*
|
|
|
|
|
* May be deferred via the job queue.
|
|
|
|
|
*
|
|
|
|
|
* @param $editor User object
|
|
|
|
|
* @param $title Title object
|
|
|
|
|
* @param $timestamp
|
|
|
|
|
* @param $summary
|
|
|
|
|
* @param $minorEdit
|
|
|
|
|
* @param $oldid (default: false)
|
|
|
|
|
*/
|
2008-12-17 17:27:43 +00:00
|
|
|
static function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
|
2007-05-11 16:42:18 +00:00
|
|
|
global $wgEnotifUseJobQ;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
if ( $title->getNamespace() < 0 )
|
2007-07-09 14:21:49 +00:00
|
|
|
return;
|
|
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
if ( $wgEnotifUseJobQ ) {
|
2007-05-11 16:42:18 +00:00
|
|
|
$params = array(
|
|
|
|
|
"editor" => $editor->getName(),
|
2008-05-17 23:34:28 +00:00
|
|
|
"editorID" => $editor->getID(),
|
2007-05-11 16:42:18 +00:00
|
|
|
"timestamp" => $timestamp,
|
|
|
|
|
"summary" => $summary,
|
|
|
|
|
"minorEdit" => $minorEdit,
|
|
|
|
|
"oldid" => $oldid);
|
2007-06-21 19:11:24 +00:00
|
|
|
$job = new EnotifNotifyJob( $title, $params );
|
2007-05-11 16:42:18 +00:00
|
|
|
$job->insert();
|
|
|
|
|
} else {
|
2008-12-17 17:27:43 +00:00
|
|
|
self::actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid );
|
2007-05-11 16:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Immediate version of notifyOnPageChange().
|
2007-10-03 08:46:17 +00:00
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Send emails corresponding to the user $editor editing the page $title.
|
2007-10-03 08:46:17 +00:00
|
|
|
* Also updates wl_notificationtimestamp.
|
|
|
|
|
*
|
|
|
|
|
* @param $editor User object
|
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)
|
|
|
|
|
*/
|
2008-12-17 17:27:43 +00:00
|
|
|
static function actuallyNotifyOnPageChange( $editor, $title, $timestamp,
|
|
|
|
|
$summary, $minorEdit, $oldid = false ) {
|
2008-12-17 07:08:16 +00:00
|
|
|
global $wgShowUpdatedMarker, $wgEnotifWatchlist;
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
EmailNotification::notify( $editor, $timestamp,
|
|
|
|
|
array( 'PageChangeNotification::usersList', array( $editor, $title, $minorEdit ) ),
|
|
|
|
|
array( 'PageChangeNotification::message', array( $oldid, $minorEdit, $summary, $title, $editor ) ) );
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2008-10-30 10:04:30 +00:00
|
|
|
$latestTimestamp = Revision::getTimestampFromId( $title, $title->getLatestRevID() );
|
2008-10-09 03:41:29 +00:00
|
|
|
// Do not update watchlists if something else already did.
|
|
|
|
|
if ( $timestamp >= $latestTimestamp && ($wgShowUpdatedMarker || $wgEnotifWatchlist) ) {
|
2008-05-17 23:34:28 +00:00
|
|
|
# Mark the changed watch-listed page with a timestamp, so that the page is
|
|
|
|
|
# listed with an "updated since your last visit" icon in the watch list. Do
|
|
|
|
|
# not do this to users for their own edits.
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2007-10-03 08:46:17 +00:00
|
|
|
$dbw->update( 'watchlist',
|
2005-05-29 04:29:29 +00:00
|
|
|
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(),
|
2008-05-17 23:34:28 +00:00
|
|
|
'wl_notificationtimestamp IS NULL',
|
|
|
|
|
'wl_user != ' . $editor->getID()
|
2007-10-03 08:46:17 +00:00
|
|
|
), __METHOD__
|
2005-05-29 04:29:29 +00:00
|
|
|
);
|
|
|
|
|
}
|
2007-05-11 16:42:18 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static function message( $stuff ) {
|
|
|
|
|
global $wgEnotifImpersonal;
|
2008-12-10 06:40:05 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
list( $oldid, $medit, $summary, $title, $user ) = $stuff;
|
2008-12-17 07:08:16 +00:00
|
|
|
$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
|
2008-12-17 07:08:16 +00:00
|
|
|
if( $oldid ) {
|
|
|
|
|
$difflink = $title->getFullUrl( 'diff=0&oldid=' . $oldid );
|
2005-07-10 02:52:33 +00:00
|
|
|
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink );
|
2008-12-17 07:08:16 +00:00
|
|
|
$keys['$OLDID'] = $oldid;
|
2005-05-14 17:55:04 +00:00
|
|
|
$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
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
if ($wgEnotifImpersonal && $oldid) {
|
|
|
|
|
# For impersonal mail, show a diff link to the last revision.
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
|
|
|
|
|
$title->getFullURL( "oldid={$oldid}&diff=prev" ) );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
$keys['$PAGETITLE'] = $title->getPrefixedText();
|
|
|
|
|
$keys['$PAGETITLE_URL'] = $title->getFullUrl();
|
|
|
|
|
$keys['$PAGEMINOREDIT'] = $medit ? wfMsg( 'minoredit' ) : '';
|
2008-12-17 17:27:43 +00:00
|
|
|
$keys['$PAGESUMMARY'] = ( $summary == '' ) ? ' - ' : $summary;
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
return array( $keys, 'enotif_body', 'enotif_subject' );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
static function usersList( $stuff ) {
|
2008-12-17 07:08:16 +00:00
|
|
|
global $wgEnotifWatchlist, $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges;
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
list( $editor, $title, $minorEdit ) = $stuff;
|
2008-12-17 07:08:16 +00:00
|
|
|
$recipients = array();
|
2008-03-21 00:39:32 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
# User talk pages:
|
|
|
|
|
$userTalkId = false;
|
2008-12-17 17:27:43 +00:00
|
|
|
if( $title->getNamespace() == NS_USER_TALK && ( !$minorEdit || $wgEnotifMinorEdits ) ) {
|
|
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
2008-03-21 00:39:32 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
if ( !$targetUser || $targetUser->isAnon() )
|
|
|
|
|
$msg = "user talk page edited, but user does not exist";
|
2007-10-03 08:46:17 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
else if ( $targetUser->getId() == $editor->getId() )
|
|
|
|
|
$msg = "user edited their own talk page, no notification sent";
|
2008-12-10 06:02:14 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
else if ( !$targetUser->getOption( 'enotifusertalkpages' ) )
|
2008-12-17 07:08:16 +00:00
|
|
|
$msg = "talk page owner doesn't want notifications";
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
else if ( !$targetUser->isEmailConfirmed() )
|
|
|
|
|
$msg = "talk page owner doesn't have validated email";
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
$msg = "sending talk page update notification";
|
|
|
|
|
$recipients[] = $targetUser;
|
|
|
|
|
$userTalkId = $targetUser->getId(); # won't be included in watchlist, below.
|
|
|
|
|
}
|
2008-12-17 17:27:43 +00:00
|
|
|
wfDebug( __METHOD__ . ': ' . $msg . "\n" );
|
2008-12-10 06:40:05 +00:00
|
|
|
}
|
2008-12-17 17:27:43 +00:00
|
|
|
wfDebug( "Did not send a user-talk notification.\n" );
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2008-12-17 17:27:43 +00:00
|
|
|
if( $wgEnotifWatchlist && ( !$minorEdit || $wgEnotifMinorEdits ) ) {
|
2008-12-17 07:08:16 +00:00
|
|
|
// Send updates to watchers other than the current editor
|
|
|
|
|
$userCondition = 'wl_user != ' . $editor->getID();
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
if ( $userTalkId !== false ) {
|
|
|
|
|
// Already sent an email to this person
|
|
|
|
|
$userCondition .= ' AND wl_user != ' . intval( $userTalkId );
|
|
|
|
|
}
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
list( $user ) = $dbr->tableNamesN( 'user' );
|
2008-12-10 06:02:14 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
$res = $dbr->select( array( 'watchlist', 'user' ),
|
|
|
|
|
array( "$user.*" ),
|
|
|
|
|
array(
|
|
|
|
|
'wl_user=user_id',
|
|
|
|
|
'wl_title' => $title->getDBkey(),
|
|
|
|
|
'wl_namespace' => $title->getNamespace(),
|
|
|
|
|
$userCondition,
|
|
|
|
|
'wl_notificationtimestamp IS NULL',
|
|
|
|
|
), __METHOD__ );
|
|
|
|
|
$userArray = UserArray::newFromResult( $res );
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
foreach ( $userArray as $watchingUser ) {
|
|
|
|
|
if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
|
|
|
|
|
( !$minorEdit || $watchingUser->getOption('enotifminoredits') ) &&
|
|
|
|
|
$watchingUser->isEmailConfirmed() ) {
|
|
|
|
|
$recipients[] = $watchingUser;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
|
2008-12-17 17:27:43 +00:00
|
|
|
$recipients[] = User::newFromName( $name );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
2008-12-10 06:40:05 +00:00
|
|
|
|
2008-12-17 07:08:16 +00:00
|
|
|
return $recipients;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/**
|
|
|
|
|
* Backwards compatibility functions
|
|
|
|
|
*/
|
|
|
|
|
function wfRFC822Phrase( $s ) {
|
|
|
|
|
return UserMailer::rfc822Phrase( $s );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
function userMailer( $to, $from, $subject, $body, $replyto=null ) {
|
|
|
|
|
return UserMailer::send( $to, $from, $subject, $body, $replyto );
|
|
|
|
|
}
|