1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace dokuwiki\Subscriptions; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Diff; |
8
|
|
|
use InlineDiffFormatter; |
9
|
|
|
use UnifiedDiffFormatter; |
10
|
|
|
|
11
|
|
|
class PageSubscriptionSender extends SubscriptionSender |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Send the diff for some page change |
16
|
|
|
* |
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 |
23
|
|
|
* |
24
|
|
|
* @return bool true if successfully sent |
25
|
|
|
*/ |
26
|
|
|
public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '', $current_rev = null) |
27
|
|
|
{ |
28
|
|
|
global $DIFF_INLINESTYLES; |
29
|
|
|
|
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, '&'), |
36
|
|
|
]; |
37
|
|
|
$hrep = []; |
38
|
|
|
|
39
|
|
|
if ($rev) { |
|
|
|
|
40
|
|
|
$subject = 'changed'; |
41
|
|
|
$trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); |
42
|
|
|
|
43
|
|
|
$old_content = rawWiki($id, $rev); |
44
|
|
|
$new_content = rawWiki($id); |
45
|
|
|
|
46
|
|
|
$df = new Diff( |
47
|
|
|
explode("\n", $old_content), |
48
|
|
|
explode("\n", $new_content) |
49
|
|
|
); |
50
|
|
|
$dformat = new UnifiedDiffFormatter(); |
51
|
|
|
$tdiff = $dformat->format($df); |
52
|
|
|
|
53
|
|
|
$DIFF_INLINESTYLES = true; |
54
|
|
|
$df = new Diff( |
55
|
|
|
explode("\n", $old_content), |
56
|
|
|
explode("\n", $new_content) |
57
|
|
|
); |
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)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$trep['DIFF'] = $tdiff; |
70
|
|
|
$hrep['DIFF'] = $hdiff; |
71
|
|
|
|
72
|
|
|
$headers = ['Message-Id' => $this->getMessageID($id)]; |
73
|
|
|
if ($rev) { |
|
|
|
|
74
|
|
|
$headers['In-Reply-To'] = $this->getMessageID($id, $rev); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->send( |
78
|
|
|
$subscriber_mail, |
79
|
|
|
$subject, |
80
|
|
|
$id, |
81
|
|
|
$template, |
82
|
|
|
$trep, |
83
|
|
|
$hrep, |
84
|
|
|
$headers |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: