xref: /dokuwiki/inc/ChangeLog/PageChangeLog.php (revision d4f83172d9533c4d84f450fe22ef630816b21d75)
1<?php
2
3namespace dokuwiki\ChangeLog;
4
5/**
6 * Class PageChangeLog; handles changelog of a wiki page
7 */
8class PageChangeLog extends ChangeLog
9{
10    /**
11     * Returns path to changelog
12     *
13     * @return string path to file
14     */
15    protected function getChangelogFilename()
16    {
17        return metaFN($this->id, '.changes');
18    }
19
20    /**
21     * Returns path to current page/media
22     *
23     * @param string|int $rev empty string or revision timestamp
24     * @return string path to file
25     */
26    protected function getFilename($rev = '')
27    {
28        return wikiFN($this->id, $rev);
29    }
30
31
32
33    /**
34     * Adds an entry to the changelog
35     *
36     * @param array $info    Revision info structure of a page
37     * @param int $timestamp log line date (optional)
38     * @return array revision info of added log line
39     *
40     * @see also addLogEntry() in inc/changelog.php file
41     */
42    public function addLogEntry(array $info, $timestamp = null)
43    {
44        global $conf;
45
46        if (isset($timestamp)) unset($this->cache[$this->id][$info['date']]);
47
48        // add changelog lines
49        $logline = static::buildLogLine($info, $timestamp);
50        io_saveFile(metaFN($this->id, '.changes'), $logline, true);
51        io_saveFile($conf['changelog'], $logline, true); //global changelog cache
52
53        // update cache
54        $this->currentRevision = $info['date'];
55        $this->cache[$this->id][$this->currentRevision] = $info;
56        return $info;
57    }
58}
59