xref: /dokuwiki/inc/ChangeLog/PageChangeLog.php (revision c71927663aade6cf69a15ca99cabe28d9a6db62f)
1<?php
2
3namespace dokuwiki\ChangeLog;
4
5/**
6 * handles changelog of a wiki page
7 */
8class PageChangeLog extends ChangeLog
9{
10
11    /**
12     * Returns path to changelog
13     *
14     * @return string path to file
15     */
16    protected function getChangelogFilename()
17    {
18        return metaFN($this->id, '.changes');
19    }
20
21    /**
22     * Returns path to current page/media
23     *
24     * @param string|int $rev empty string or revision timestamp
25     * @return string path to file
26     */
27    protected function getFilename($rev = '')
28    {
29        return wikiFN($this->id, $rev);
30    }
31
32
33
34    /**
35     * Adds an entry to the changelog
36     *
37     * @param array $info    Revision info structure of a page
38     * @param int $timestamp logline date (optional)
39     * @return array added logline as revision info
40     *
41     * @see also addLogEntry() in inc/changelog.php file
42     */
43    public function addLogEntry(array $info, $timestamp = null)
44    {
45        global $conf;
46
47        $strip = ["\t", "\n"];
48        $revInfo = array(
49            'date' => $timestamp ?? $info['date'],
50            'ip'   => $info['ip'],
51            'type' => str_replace($strip, '', $info['type']),
52            'id'   => $this->id,
53            'user' => $info['user'],
54            'sum'  => \dokuwiki\Utf8\PhpString::substr(str_replace($strip, '', $info['sum']), 0, 255),
55            'extra' => str_replace($strip, '', $info['extra']),
56            'sizechange' => $info['sizechange'],
57        );
58
59        // add changelog lines
60        $logline = implode("\t", $revInfo) ."\n";
61        io_saveFile(metaFN($this->id,'.changes'), $logline, $append = true);
62        io_saveFile($conf['changelog'], $logline, $append = true); //global changelog cache
63
64        // update cache
65        if (isset($timestamp)) unset($this->cache[$this->id][$info['date']]);
66        $this->currentRevision = $revInfo['date'];
67        $this->cache[$this->id][$this->currentRevision] = $revInfo;
68        return $revInfo;
69    }
70
71}
72