xref: /dokuwiki/inc/ChangeLog/PageChangeLog.php (revision 01e8d739c8b53aeb1d0a653331d65eb1f8394002)
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     * Returns mode
33     *
34     * @return string RevisionInfo::MODE_PAGE
35     */
36    protected function getMode()
37    {
38        return RevisionInfo::MODE_PAGE;
39    }
40
41    /**
42     * Returns path to the global page-changelog file
43     *
44     * @return string path to file
45     */
46    protected function getGlobalChangelogFilename()
47    {
48        global $conf;
49        return $conf['changelog'];
50    }
51
52    /**
53     * Copy the externally-edited page to the attic at the synthesized revision date.
54     * If the file mtime is older than the last known revision (broken chronology),
55     * touch the file forward so future reads see a consistent state.
56     *
57     * @param array $revInfo synthesized revision info
58     * @return bool true on success (or nothing to copy), false if the attic write failed
59     */
60    protected function saveExternalAttic(array $revInfo)
61    {
62        $file = $this->getFilename();
63        if (!file_exists($file)) return true;
64
65        // rescue: file mtime older than last revision — touch forward to the synthesized date
66        if (empty($revInfo['timestamp'])) {
67            if (!@touch($file, $revInfo['date'])) return false;
68            clearstatcache(false, $file);
69        }
70
71        $atticfile = $this->getFilename($revInfo['date']);
72        return io_writeWikiPage($atticfile, io_readWikiPage($file, $this->id, ''), $this->id, $revInfo['date']);
73    }
74}
75