/**
  * Modify HTML body of email
  * This method is helper for onComposeCommonBodyMail hook function
  *
  * @param Title $title
  * @param array $keys
  * @param string $body
  * @param User $editor
  * @param string $bodyHTML
  * @param array $postTransformKeys
  * @param string $action
  * @return bool
  */
 public function bodyBlogpost(Title $title, &$keys, &$body, User $editor, &$bodyHTML, &$postTransformKeys, $action = FollowHelper::LOG_ACTION_BLOG_POST)
 {
     /* @var $wgLang Language */
     global $wgLang;
     wfProfileIn(__METHOD__);
     $msgContentHTML = wfMsgHTMLwithLanguageAndAlternative('enotif_body' . ($action == '' ? '' : '_' . $action), 'enotif_body', $this->app->wg->LanguageCode);
     $content = $msgContentHTML[1];
     $username = $editor->getName();
     /*
      * $title variable has wrong value. Use $keys['$PAGETITLE'] to get title of the post ($oPostTitle).
      * $keys['$PAGETITLE'] is being generated by MailNotifyBuildKeys hook
      */
     $oPostTitle = Title::newFromText($keys['$PAGETITLE'], NS_BLOG_ARTICLE);
     $oRevision = Revision::newFromId($oPostTitle->getLatestRevID());
     $timestamp = time();
     if ($oRevision instanceof Revision) {
         $timestamp = $oRevision->getTimestamp();
     }
     $date = $wgLang->date(wfTimestamp(TS_MW, $timestamp));
     /* render blog post info (avatar, author, date, title and short text) */
     $post_info_params = array('language' => $this->app->wg->LanguageCode, 'post_url' => $oPostTitle->getFullURL(), 'post_title' => $oPostTitle->getSubpageText(), 'username' => $username, 'user_page_url' => $editor->getUserPage()->getFullURL(), 'avatar_url' => AvatarService::renderAvatar($username, self::EMAIL_AVATAR_DEFAULT_WIDTH), 'date' => $date);
     $postInfoHTML = $this->app->renderView("EmailTemplates", "PostInfo", $post_info_params);
     $keys['$POST_INFO'] = $postInfoHTML;
     /* render button HTML to be replaced in body of mail */
     $button_params = array('language' => $this->app->wg->LanguageCode, 'link_url' => $oPostTitle->getFullURL(), 'link_text' => wfMessage('read-the-whole-post')->plain());
     $buttonHTML = $this->app->renderView("EmailTemplates", "Button", $button_params);
     $keys['$BUTTON'] = $buttonHTML;
     $keys['$TITLE_STYLE'] = ' style="color:#2c85d5;font-size:17px;font-weight:bold;"';
     /* render body of mail */
     $body_params = array('language' => $this->app->wg->LanguageCode, 'content' => $content);
     $bodyHTML = $this->app->renderView("EmailTemplates", "NewBlogPostMail", $body_params);
     wfProfileOut(__METHOD__);
     return true;
 }
Example #2
0
 /**
  * Generate the generic "this page has been changed" e-mail text.
  */
 private function composeCommonMailtext()
 {
     $this->composedCommon = true;
     $action = strtolower($this->action);
     $subject = wfMessage('enotif_subject_' . $action)->inContentLanguage()->text();
     if (wfEmptyMsg('enotif_subject_' . $action, $subject)) {
         $subject = wfMessage('enotif_subject')->inContentLanguage()->text();
     }
     list($body, $bodyHTML) = wfMsgHTMLwithLanguageAndAlternative('enotif_body' . ($action == '' ? '' : '_' . $action), 'enotif_body', F::app()->wg->LanguageCode);
     # 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
     $keys = [];
     $postTransformKeys = [];
     if ($this->isNewPage()) {
         // watchlist link tracking
         list($keys['$NEWPAGE'], $keys['$NEWPAGEHTML']) = wfMsgHTMLwithLanguageAndAlternative('enotif_lastvisited', 'enotif_lastvisited', F::app()->wg->LanguageCode, [], $this->title->getFullUrl('s=wldiff&diff=0&previousRevId=' . $this->previousRevId));
         $keys['$OLDID'] = $this->previousRevId;
         $keys['$CHANGEDORCREATED'] = wfMessage('changed')->inContentLanguage()->plain();
     } else {
         if ($action == '') {
             // no previousRevId + empty action = create edit, ok to use newpagetext
             $keys['$NEWPAGEHTML'] = $keys['$NEWPAGE'] = wfMessage('enotif_newpagetext')->inContentLanguage()->plain();
         } else {
             // no previousRevId + action = event, dont show anything, confuses users
             $keys['$NEWPAGEHTML'] = $keys['$NEWPAGE'] = '';
         }
         # clear $OLDID placeholder in the message template
         $keys['$OLDID'] = '';
         $keys['$CHANGEDORCREATED'] = wfMessage('created')->inContentLanguage()->plain();
     }
     $keys['$PAGETITLE'] = $this->title->getPrefixedText();
     $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl('s=wl');
     $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMessage('minoredit')->inContentLanguage()->plain() : '';
     $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl('action=unwatch');
     $keys['$ACTION'] = $this->action;
     // Hook registered in FollowHelper -- used for blogposts and categoryAdd
     wfRunHooks('MailNotifyBuildKeys', [&$keys, $this->action, $this->otherParam]);
     if ($this->editor->isAnon()) {
         # real anon (user:xxx.xxx.xxx.xxx)
         $keys['$PAGEEDITOR'] = wfMessage('enotif_anon_editor', $this->editor->getName())->inContentLanguage()->plain();
         $keys['$PAGEEDITOR_EMAIL'] = wfMessage('noemailtitle')->inContentLanguage()->plain();
     } else {
         $keys['$PAGEEDITOR'] = F::app()->wg->EnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
         $emailPage = SpecialPage::getSafeTitleFor('Emailuser', $this->editor->getName());
         $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
     }
     $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalUrl();
     $summary = $this->summary == '' ? wfMessage('enotif_no_summary')->inContentLanguage()->plain() : '"' . $this->summary . '"';
     $postTransformKeys['$PAGESUMMARY'] = $summary;
     // Now build message's subject and body
     // ArticleComment -- updates subject and $keys['$PAGEEDITOR'] if anon editor
     // EmailTemplatesHooksHelper -- updates subject if blogpost
     // TopListHelper -- updates subject if title is toplist
     wfRunHooks('ComposeCommonSubjectMail', [$this->title, &$keys, &$subject, $this->editor]);
     $subject = strtr($subject, $keys);
     $subject = MessageCache::singleton()->transform($subject, false, null, $this->title);
     $this->subject = strtr($subject, $postTransformKeys);
     // ArticleComment -- updates body and $keys['$PAGEEDITOR'] if anon editor
     // EmailTemplatesHooksHelper -- changes body to blog post. EmailTemplates only enabled on community and messaging so this tranforms
     //     any watched page email coming from Community to a blog post (I think)
     // TopListHelper -- updates body if title is toplist
     wfRunHooks('ComposeCommonBodyMail', [$this->title, &$keys, &$body, $this->editor, &$bodyHTML, &$postTransformKeys]);
     $body = strtr($body, $keys);
     $body = MessageCache::singleton()->transform($body, false, null, $this->title);
     $this->body = wordwrap(strtr($body, $postTransformKeys), 72);
     if ($bodyHTML) {
         $bodyHTML = strtr($bodyHTML, $keys);
         $bodyHTML = MessageCache::singleton()->transform($bodyHTML, false, null, $this->title);
         $this->bodyHTML = strtr($bodyHTML, $postTransformKeys);
     }
 }
Example #3
0
 /**
  * Generate the generic "this page has been changed" e-mail text.
  */
 private function composeCommonMailtext()
 {
     global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
     global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
     global $wgEnotifImpersonal, $wgEnotifUseRealName;
     global $wgLanguageCode;
     $this->composed_common = true;
     # <Wikia>
     $action = strtolower($this->action);
     $subject = wfMsgForContent('enotif_subject_' . $action);
     if (wfEmptyMsg('enotif_subject_' . $action, $subject)) {
         $subject = wfMsgForContent('enotif_subject');
     }
     list($body, $bodyHTML) = wfMsgHTMLwithLanguageAndAlternative('enotif_body' . ($action == '' ? '' : '_' . $action), 'enotif_body', $wgLanguageCode);
     # </Wikia>
     # 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
     $keys = array();
     $postTransformKeys = array();
     if ($this->oldid) {
         if ($wgEnotifImpersonal) {
             // For impersonal mail, show a diff link to the last revision.
             $keys['$NEWPAGE'] = wfMsgForContent('enotif_lastdiff', $this->title->getCanonicalUrl('diff=next&oldid=' . $this->oldid));
         } else {
             /* WIKIA change, watchlist link tracking, rt#33913 */
             list($keys['$NEWPAGE'], $keys['$NEWPAGEHTML']) = wfMsgHTMLwithLanguageAndAlternative('enotif_lastvisited', 'enotif_lastvisited', $wgLanguageCode, array(), $this->title->getFullUrl('s=wldiff&diff=0&oldid=' . $this->oldid));
             # </Wikia>
         }
         $keys['$OLDID'] = $this->oldid;
         $keys['$CHANGEDORCREATED'] = wfMsgForContent('changed');
     } else {
         # <Wikia>
         if ($action == '') {
             //no oldid + empty action = create edit, ok to use newpagetext
             $keys['$NEWPAGEHTML'] = $keys['$NEWPAGE'] = wfMsgForContent('enotif_newpagetext');
         } else {
             //no oldid + action = event, dont show anything, confuses users
             $keys['$NEWPAGEHTML'] = $keys['$NEWPAGE'] = '';
         }
         # </Wikia>
         # clear $OLDID placeholder in the message template
         $keys['$OLDID'] = '';
         $keys['$CHANGEDORCREATED'] = wfMsgForContent('created');
     }
     $keys['$PAGETITLE'] = $this->title->getPrefixedText();
     $keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl('s=wl');
     $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMsgForContent('minoredit') : '';
     $keys['$UNWATCHURL'] = $this->title->getCanonicalUrl('action=unwatch');
     # <Wikia>
     $keys['$ACTION'] = $this->action;
     wfRunHooks('MailNotifyBuildKeys', array(&$keys, $this->action, $this->other_param));
     # </Wikia>
     if ($this->editor->isAnon()) {
         # real anon (user:xxx.xxx.xxx.xxx)
         $keys['$PAGEEDITOR'] = wfMsgForContent('enotif_anon_editor', $this->editor->getName());
         $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent('noemailtitle');
     } else {
         $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
         $emailPage = SpecialPage::getSafeTitleFor('Emailuser', $this->editor->getName());
         $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalUrl();
     }
     $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalUrl();
     # <Wikia>
     // RT #1294 Bartek 07.05.2009, use the language of the wiki
     $summary = $this->summary == '' ? wfMsgForContent('enotif_no_summary') : '"' . $this->summary . '"';
     # </Wikia>
     # Replace this after transforming the message, bug 35019
     $postTransformKeys['$PAGESUMMARY'] = $summary;
     # Now build message's subject and body
     # <Wikia>
     wfRunHooks('ComposeCommonSubjectMail', array($this->title, &$keys, &$subject, $this->editor));
     # </Wikia>
     $subject = strtr($subject, $keys);
     $subject = MessageCache::singleton()->transform($subject, false, null, $this->title);
     $this->subject = strtr($subject, $postTransformKeys);
     wfRunHooks('ComposeCommonBodyMail', array($this->title, &$keys, &$body, $this->editor, &$bodyHTML, &$postTransformKeys));
     $body = strtr($body, $keys);
     $body = MessageCache::singleton()->transform($body, false, null, $this->title);
     $this->body = wordwrap(strtr($body, $postTransformKeys), 72);
     # <Wikia>
     if ($bodyHTML) {
         $bodyHTML = strtr($bodyHTML, $keys);
         $bodyHTML = MessageCache::singleton()->transform($bodyHTML, false, null, $this->title);
         $this->bodyHTML = strtr($bodyHTML, $postTransformKeys);
     }
     # </Wikia>
     # 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.
     $adminAddress = new MailAddress($wgPasswordSender, $wgPasswordSenderName);
     if ($wgEnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getOption('enotifrevealaddr')) {
         $editorAddress = new MailAddress($this->editor);
         if ($wgEnotifFromEditor) {
             $this->from = $editorAddress;
         } else {
             $this->from = $adminAddress;
             $this->replyto = $editorAddress;
         }
     } else {
         $this->from = $adminAddress;
         $this->replyto = new MailAddress($wgNoReplyAddress);
     }
 }