# PEAR MAILER
#
- if ( function_exists( 'stream_resolve_include_path' ) ) {
- $found = stream_resolve_include_path( 'Mail.php' );
- } else {
- $found = Fallback::stream_resolve_include_path( 'Mail.php' );
- }
- if ( !$found ) {
+ if ( ! stream_resolve_include_path( 'Mail.php' ) ) {
throw new MWException( 'PEAR mail package is not installed' );
}
require_once( 'Mail.php' );
*/
class EmailNotification {
protected $subject, $body, $replyto, $from;
- protected $timestamp, $summary, $minorEdit, $oldid, $composed_common;
+ protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus;
protected $mailTargets = array();
/**
* @param $summary
* @param $minorEdit
* @param $oldid (default: false)
+ * @param $pageStatus (default: 'changed')
*/
- public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
+ public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $pageStatus = 'changed' ) {
global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
$wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
'summary' => $summary,
'minorEdit' => $minorEdit,
'oldid' => $oldid,
- 'watchers' => $watchers
+ 'watchers' => $watchers,
+ 'pageStatus' => $pageStatus
);
$job = new EnotifNotifyJob( $title, $params );
- $job->insert();
+ JobQueueGroup::singleton()->push( $job );
} else {
- $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
+ $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus );
}
}
* @param $minorEdit bool
* @param $oldid int Revision ID
* @param $watchers array of user IDs
+ * @param string $pageStatus
+ * @throws MWException
*/
- public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
+ public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit,
+ $oldid, $watchers, $pageStatus = 'changed' ) {
# we use $wgPasswordSender as sender's address
global $wgEnotifWatchlist;
global $wgEnotifMinorEdits, $wgEnotifUserTalk;
$this->oldid = $oldid;
$this->editor = $editor;
$this->composed_common = false;
+ $this->pageStatus = $pageStatus;
+
+ $formattedPageStatus = array( 'deleted', 'created', 'moved', 'restored', 'changed' );
+
+ wfRunHooks( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) );
+ if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
+ throw new MWException( 'Not a valid page status!' );
+ }
$userTalkId = false;
$keys = array();
$postTransformKeys = array();
+ $pageTitleUrl = $this->title->getCanonicalUrl();
+ $pageTitle = $this->title->getPrefixedText();
if ( $this->oldid ) {
// Always show a link to the diff which triggered the mail. See bug 32210.
- $keys['$NEWPAGE'] = wfMessage( 'enotif_lastdiff',
+ $keys['$NEWPAGE'] = "\n\n" . wfMessage( 'enotif_lastdiff',
$this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) )
->inContentLanguage()->text();
+
if ( !$wgEnotifImpersonal ) {
// For personal mail, also show a link to the diff of all changes
// since last visited.
- $keys['$NEWPAGE'] .= " \n" . wfMessage( 'enotif_lastvisited',
+ $keys['$NEWPAGE'] .= "\n\n" . wfMessage( 'enotif_lastvisited',
$this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) )
->inContentLanguage()->text();
}
$keys['$OLDID'] = $this->oldid;
- $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
} else {
- $keys['$NEWPAGE'] = wfMessage( 'enotif_newpagetext' )->inContentLanguage()->text();
# clear $OLDID placeholder in the message template
$keys['$OLDID'] = '';
- $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
+ $keys['$NEWPAGE'] = '';
}
$keys['$PAGETITLE'] = $this->title->getPrefixedText();
$keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
->inContentLanguage()->text();
$keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
+
} else {
$keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
$emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
$postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
# Now build message's subject and body
+ $this->subject = wfMessage( 'enotif_subject_' . $this->pageStatus )->inContentLanguage()
+ ->params( $pageTitle, $keys['$PAGEEDITOR'] )->escaped();
- $subject = wfMessage( 'enotif_subject' )->inContentLanguage()->plain();
- $subject = strtr( $subject, $keys );
- $subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
- $this->subject = strtr( $subject, $postTransformKeys );
+ $keys['$PAGEINTRO'] = wfMessage( 'enotif_body_intro_' . $this->pageStatus )
+ ->inContentLanguage()->params( $pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl )
+ ->escaped();
$body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
$body = strtr( $body, $keys );
/**
* Same as sendPersonalised but does impersonal mail suitable for bulk
* mailing. Takes an array of MailAddress objects.
- * @return Status
+ * @param $addresses array
+ * @return Status|null
*/
function sendImpersonal( $addresses ) {
global $wgContLang;
- if ( empty( $addresses ) )
- return;
+ if ( empty( $addresses ) ) {
+ return null;
+ }
$body = str_replace(
array( '$WATCHINGUSERNAME',