10c3a5702SAndreas Gohr<?php 20c3a5702SAndreas Gohr 30c3a5702SAndreas Gohrnamespace dokuwiki\ChangeLog; 40c3a5702SAndreas Gohr 50c3a5702SAndreas Gohr/** 607869ee7SSatoshi Sahara * Class MediaChangeLog; handles changelog of a media file 70c3a5702SAndreas Gohr */ 80c3a5702SAndreas Gohrclass MediaChangeLog 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 mediaMetaFN($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 mediaFN($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_MEDIA; 39a835c93aSGerrit Uitslag } 40c7192766SSatoshi Sahara 41*01e8d739SAndreas Gohr /** 42*01e8d739SAndreas Gohr * Returns path to the global media-changelog file 43*01e8d739SAndreas Gohr * 44*01e8d739SAndreas Gohr * @return string path to file 45*01e8d739SAndreas Gohr */ 46*01e8d739SAndreas Gohr protected function getGlobalChangelogFilename() 47*01e8d739SAndreas Gohr { 48*01e8d739SAndreas Gohr global $conf; 49*01e8d739SAndreas Gohr return $conf['media_changelog']; 50*01e8d739SAndreas Gohr } 51c7192766SSatoshi Sahara 52c7192766SSatoshi Sahara /** 53*01e8d739SAndreas Gohr * Copy the externally-modified media file 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. 56c7192766SSatoshi Sahara * 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 copy failed 59c7192766SSatoshi Sahara */ 60*01e8d739SAndreas Gohr protected function saveExternalAttic(array $revInfo) 61c7192766SSatoshi Sahara { 62c7192766SSatoshi Sahara global $conf; 63c7192766SSatoshi Sahara 64*01e8d739SAndreas Gohr $file = $this->getFilename(); 65*01e8d739SAndreas Gohr if (!file_exists($file)) return true; 66c7192766SSatoshi Sahara 67*01e8d739SAndreas Gohr // rescue: file mtime older than last revision — touch forward to the synthesized date 68*01e8d739SAndreas Gohr if (empty($revInfo['timestamp'])) { 69*01e8d739SAndreas Gohr if (!@touch($file, $revInfo['date'])) return false; 70*01e8d739SAndreas Gohr clearstatcache(false, $file); 71*01e8d739SAndreas Gohr } 72c7192766SSatoshi Sahara 73*01e8d739SAndreas Gohr $atticfile = $this->getFilename($revInfo['date']); 74*01e8d739SAndreas Gohr io_makeFileDir($atticfile); 75*01e8d739SAndreas Gohr if (!@copy($file, $atticfile)) return false; 76*01e8d739SAndreas Gohr if (!empty($conf['fmode'])) @chmod($atticfile, $conf['fmode']); 77*01e8d739SAndreas Gohr return true; 78c7192766SSatoshi Sahara } 790c3a5702SAndreas Gohr} 80