Merge branch 'master' into revisionHandle3
[dokuwiki.git] / inc / Subscriptions / PageSubscriptionSender.php
blobe5577c1afebfdf64b895554cd2ce7ebf56e71a06
1 <?php
4 namespace dokuwiki\Subscriptions;
7 use Diff;
8 use InlineDiffFormatter;
9 use UnifiedDiffFormatter;
11 class PageSubscriptionSender extends SubscriptionSender
14 /**
15 * Send the diff for some page change
17 * @param string $subscriber_mail The target mail address
18 * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...)
19 * @param string $id Page for which the notification is
20 * @param int|null $rev Old revision if any
21 * @param string $summary Change summary if any
22 * @param int|null $current_rev New revision if any
24 * @return bool true if successfully sent
26 public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '', $current_rev = null)
28 global $DIFF_INLINESTYLES;
30 // prepare replacements (keys not set in hrep will be taken from trep)
31 $trep = [
32 'PAGE' => $id,
33 'NEWPAGE' => wl($id, $current_rev?('rev='.$current_rev):'', true, '&'),
34 'SUMMARY' => $summary,
35 'SUBSCRIBE' => wl($id, ['do' => 'subscribe'], true, '&'),
37 $hrep = [];
39 if ($rev) {
40 $subject = 'changed';
41 $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&');
43 $old_content = rawWiki($id, $rev);
44 $new_content = rawWiki($id);
46 $df = new Diff(
47 explode("\n", $old_content),
48 explode("\n", $new_content)
50 $dformat = new UnifiedDiffFormatter();
51 $tdiff = $dformat->format($df);
53 $DIFF_INLINESTYLES = true;
54 $df = new Diff(
55 explode("\n", $old_content),
56 explode("\n", $new_content)
58 $dformat = new InlineDiffFormatter();
59 $hdiff = $dformat->format($df);
60 $hdiff = '<table>' . $hdiff . '</table>';
61 $DIFF_INLINESTYLES = false;
62 } else {
63 $subject = 'newpage';
64 $trep['OLDPAGE'] = '---';
65 $tdiff = rawWiki($id);
66 $hdiff = nl2br(hsc($tdiff));
69 $trep['DIFF'] = $tdiff;
70 $hrep['DIFF'] = $hdiff;
72 $headers = ['Message-Id' => $this->getMessageID($id)];
73 if ($rev) {
74 $headers['In-Reply-To'] = $this->getMessageID($id, $rev);
77 return $this->send(
78 $subscriber_mail,
79 $subject,
80 $id,
81 $template,
82 $trep,
83 $hrep,
84 $headers