Skip to content

Commit faf1789

Browse files
committed
fix: don't prevent creator from a new page's metadata 🐛
Calling pageinfo() durint IO_WIKIPAGE_WRITE of newly created pages caused the page's metadata file to be written prematurely which in turn caused the creator to be omitted from the page's metadata. This reworks the create_mail_body action to no longer call pageinfo(). See also dokuwiki/dokuwiki#2401
1 parent d531e70 commit faf1789

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

_test/mail.unit.test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function test_change_mail_body () {
5252
$oldrevision = pageinfo();
5353
$oldrevision = $oldrevision['lastmod'];
5454
sleep(1);
55+
global $INFO;
56+
$INFO = pageinfo();
5557
saveWikiText('start', 'start second', 'foobar');
5658
$newrevision = pageinfo();
5759
$newrevision = $newrevision['lastmod'];
@@ -100,6 +102,9 @@ function test_approve_mail_body () {
100102
$auth->createUser('john','x','John Smith','abc@def.gh');
101103
$_SERVER['REMOTE_USER'] = 'john';
102104
$USERINFO['name'] = 'John Smith';
105+
106+
global $INFO;
107+
$INFO = pageinfo();
103108
saveWikiText('start', 'start first', 'foobar');
104109

105110
$_SERVER['REMOTE_USER'] = 'mike';

action/mail.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function send_change_mail(&$event, $param) {
4040
global $ACT;
4141
global $INFO;
4242
global $conf;
43-
$data = pageinfo();
4443

4544
if ($ACT != 'save') {
4645
return true;
@@ -71,7 +70,7 @@ function send_change_mail(&$event, $param) {
7170
}
7271

7372
// get mail sender
74-
$ReplyTo = $data['userinfo']['mail'];
73+
$ReplyTo = $INFO['userinfo']['mail'];
7574

7675
if ($ReplyTo == $receiver) {
7776
return true;
@@ -82,7 +81,7 @@ function send_change_mail(&$event, $param) {
8281
}
8382

8483
// get mail subject
85-
$timestamp = dformat($data['lastmod'], $conf['dformat']);
84+
$timestamp = dformat(filemtime(wikiFN($ID)), $conf['dformat']);
8685
$subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $timestamp;
8786

8887
$body = $this->create_mail_body('change');
@@ -106,16 +105,16 @@ function send_change_mail(&$event, $param) {
106105
public function create_mail_body($action) {
107106
global $ID;
108107
global $conf;
109-
$pageinfo = pageinfo();
108+
global $INFO;
110109

111110
// get mail text
112-
$rev = $pageinfo['lastmod'];
111+
$rev = filemtime(wikiFN($ID));
113112

114113
if ($action === 'change') {
115114
$body = io_readFile($this->localFN('mailchangetext'));
116115

117116
//If there is no approved revision show the diff to the revision before. Otherwise show the diff to the last approved revision.
118-
if($this->hlp->hasApprovals($pageinfo['meta'])) {
117+
if($this->hlp->hasApprovals($INFO['meta'])) {
119118
$aprpre = 'Aproved';
120119
$oldrev = $this->hlp->getLatestApprovedRevision($ID);
121120
$difflink = $this->hlp->getDifflink($ID, $oldrev, $rev);
@@ -128,7 +127,7 @@ public function create_mail_body($action) {
128127

129128
$body = str_replace('@DIFF@', $difflink, $body);
130129
$body = str_replace('@APRPRE@', $aprpre, $body);
131-
$summary = $pageinfo['meta']['last_change']['sum'];
130+
$summary = $INFO['meta']['last_change']['sum'];
132131
$body = str_replace('@SUMMARY@', $summary, $body);
133132
if ($oldrev === false ) {
134133
$oldlink = '---';

0 commit comments

Comments
 (0)