xref: /dokuwiki/inc/ChangeLog/MediaChangeLog.php (revision 6547cfc7454f26cc353587c1314f9fde93a0a056)
1<?php
2
3namespace dokuwiki\ChangeLog;
4
5/**
6 * Class MediaChangeLog; handles changelog of a media file
7 */
8class MediaChangeLog extends ChangeLog
9{
10    /**
11     * Returns path to changelog
12     *
13     * @return string path to file
14     */
15    protected function getChangelogFilename()
16    {
17        return mediaMetaFN($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 mediaFN($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 media file
37     * @param int $timestamp log line date (optional)
38     * @return array revision info of added log line
39     *
40     * @see also addMediaLogEntry() 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(mediaMetaFN($this->id, '.changes'), $logline, $append = true);
51        io_saveFile($conf['media_changelog'], $logline, $append = 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