xref: /dokuwiki/inc/ChangeLog/PageChangeLog.php (revision 63b227866ea0b85ebdda774ff73181e683443a0d)
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     * Snapshot the externally-edited page to the attic at the synthesized revision date. Pages
54     * archive every revision, so the current (externally-changed) content is copied too.
55     *
56     * @param array $revInfo synthesized revision info
57     * @return bool true on success (or nothing to copy), false if the attic write failed
58     */
59    protected function saveExternalAttic(array $revInfo)
60    {
61        $file = $this->getFilename();
62        if (!file_exists($file)) return true;
63
64        $atticfile = $this->getFilename($revInfo['date']);
65        return io_writeWikiPage($atticfile, io_readWikiPage($file, $this->id, ''), $this->id, $revInfo['date']);
66    }
67
68    /**
69     * Compare the current page content against the (gzip-aware) attic copy of a revision.
70     *
71     * Both sides are already loaded (and decompressed) into memory by io_readWikiPage, so
72     * they are compared directly rather than via a hash: the string comparison stops at the
73     * first differing byte and avoids hashing the full contents.
74     *
75     * @param int $rev revision timestamp to compare the current page against
76     * @return bool true if the decompressed content is identical
77     */
78    protected function currentContentMatchesRevision($rev)
79    {
80        $current = $this->getFilename();
81        $attic = $this->getFilename($rev);
82        if (!file_exists($current) || !file_exists($attic)) return false;
83
84        return io_readWikiPage($current, $this->id, '') === io_readWikiPage($attic, $this->id, $rev);
85    }
86}
87