xref: /dokuwiki/inc/ChangeLog/PageChangeLog.php (revision 01e8d739c8b53aeb1d0a653331d65eb1f8394002)
10c3a5702SAndreas Gohr<?php
20c3a5702SAndreas Gohr
30c3a5702SAndreas Gohrnamespace dokuwiki\ChangeLog;
40c3a5702SAndreas Gohr
50c3a5702SAndreas Gohr/**
61d11f1d3SSatoshi Sahara * Class PageChangeLog; handles changelog of a wiki page
70c3a5702SAndreas Gohr */
80c3a5702SAndreas Gohrclass PageChangeLog extends ChangeLog
90c3a5702SAndreas Gohr{
100c3a5702SAndreas Gohr    /**
110c3a5702SAndreas Gohr     * Returns path to changelog
120c3a5702SAndreas Gohr     *
130c3a5702SAndreas Gohr     * @return string path to file
140c3a5702SAndreas Gohr     */
150c3a5702SAndreas Gohr    protected function getChangelogFilename()
160c3a5702SAndreas Gohr    {
170c3a5702SAndreas Gohr        return metaFN($this->id, '.changes');
180c3a5702SAndreas Gohr    }
190c3a5702SAndreas Gohr
200c3a5702SAndreas Gohr    /**
210c3a5702SAndreas Gohr     * Returns path to current page/media
220c3a5702SAndreas Gohr     *
23e49fa56bSSatoshi Sahara     * @param string|int $rev empty string or revision timestamp
240c3a5702SAndreas Gohr     * @return string path to file
250c3a5702SAndreas Gohr     */
26e49fa56bSSatoshi Sahara    protected function getFilename($rev = '')
270c3a5702SAndreas Gohr    {
28e49fa56bSSatoshi Sahara        return wikiFN($this->id, $rev);
290c3a5702SAndreas Gohr    }
30c7192766SSatoshi Sahara
31a835c93aSGerrit Uitslag    /**
32a835c93aSGerrit Uitslag     * Returns mode
33a835c93aSGerrit Uitslag     *
34a835c93aSGerrit Uitslag     * @return string RevisionInfo::MODE_PAGE
35a835c93aSGerrit Uitslag     */
36a835c93aSGerrit Uitslag    protected function getMode()
37a835c93aSGerrit Uitslag    {
38a835c93aSGerrit Uitslag        return RevisionInfo::MODE_PAGE;
39a835c93aSGerrit Uitslag    }
40c7192766SSatoshi Sahara
41c7192766SSatoshi Sahara    /**
42*01e8d739SAndreas Gohr     * Returns path to the global page-changelog file
43c7192766SSatoshi Sahara     *
44*01e8d739SAndreas Gohr     * @return string path to file
45c7192766SSatoshi Sahara     */
46*01e8d739SAndreas Gohr    protected function getGlobalChangelogFilename()
47c7192766SSatoshi Sahara    {
48c7192766SSatoshi Sahara        global $conf;
49*01e8d739SAndreas Gohr        return $conf['changelog'];
50*01e8d739SAndreas Gohr    }
51c7192766SSatoshi Sahara
52*01e8d739SAndreas Gohr    /**
53*01e8d739SAndreas Gohr     * Copy the externally-edited page to the attic at the synthesized revision date.
54*01e8d739SAndreas Gohr     * If the file mtime is older than the last known revision (broken chronology),
55*01e8d739SAndreas Gohr     * touch the file forward so future reads see a consistent state.
56*01e8d739SAndreas Gohr     *
57*01e8d739SAndreas Gohr     * @param array $revInfo synthesized revision info
58*01e8d739SAndreas Gohr     * @return bool true on success (or nothing to copy), false if the attic write failed
59*01e8d739SAndreas Gohr     */
60*01e8d739SAndreas Gohr    protected function saveExternalAttic(array $revInfo)
61*01e8d739SAndreas Gohr    {
62*01e8d739SAndreas Gohr        $file = $this->getFilename();
63*01e8d739SAndreas Gohr        if (!file_exists($file)) return true;
64c7192766SSatoshi Sahara
65*01e8d739SAndreas Gohr        // rescue: file mtime older than last revision — touch forward to the synthesized date
66*01e8d739SAndreas Gohr        if (empty($revInfo['timestamp'])) {
67*01e8d739SAndreas Gohr            if (!@touch($file, $revInfo['date'])) return false;
68*01e8d739SAndreas Gohr            clearstatcache(false, $file);
69*01e8d739SAndreas Gohr        }
70c7192766SSatoshi Sahara
71*01e8d739SAndreas Gohr        $atticfile = $this->getFilename($revInfo['date']);
72*01e8d739SAndreas Gohr        return io_writeWikiPage($atticfile, io_readWikiPage($file, $this->id, ''), $this->id, $revInfo['date']);
73c7192766SSatoshi Sahara    }
740c3a5702SAndreas Gohr}
75