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 /** 4201e8d739SAndreas Gohr * Returns path to the global page-changelog file 43c7192766SSatoshi Sahara * 4401e8d739SAndreas Gohr * @return string path to file 45c7192766SSatoshi Sahara */ 4601e8d739SAndreas Gohr protected function getGlobalChangelogFilename() 47c7192766SSatoshi Sahara { 48c7192766SSatoshi Sahara global $conf; 4901e8d739SAndreas Gohr return $conf['changelog']; 5001e8d739SAndreas Gohr } 51c7192766SSatoshi Sahara 5201e8d739SAndreas Gohr /** 53*5a285debSAndreas Gohr * Snapshot the externally-edited page to the attic at the synthesized revision date. Pages 54*5a285debSAndreas Gohr * archive every revision, so the current (externally-changed) content is copied too. 5501e8d739SAndreas Gohr * 5601e8d739SAndreas Gohr * @param array $revInfo synthesized revision info 5701e8d739SAndreas Gohr * @return bool true on success (or nothing to copy), false if the attic write failed 5801e8d739SAndreas Gohr */ 5901e8d739SAndreas Gohr protected function saveExternalAttic(array $revInfo) 6001e8d739SAndreas Gohr { 6101e8d739SAndreas Gohr $file = $this->getFilename(); 6201e8d739SAndreas Gohr if (!file_exists($file)) return true; 63c7192766SSatoshi Sahara 6401e8d739SAndreas Gohr $atticfile = $this->getFilename($revInfo['date']); 6501e8d739SAndreas Gohr return io_writeWikiPage($atticfile, io_readWikiPage($file, $this->id, ''), $this->id, $revInfo['date']); 66c7192766SSatoshi Sahara } 670a245329SAndreas Gohr 680a245329SAndreas Gohr /** 690a245329SAndreas Gohr * Compare the current page content against the (gzip-aware) attic copy of a revision. 700a245329SAndreas Gohr * 710a245329SAndreas Gohr * Both sides are already loaded (and decompressed) into memory by io_readWikiPage, so 720a245329SAndreas Gohr * they are compared directly rather than via a hash: the string comparison stops at the 730a245329SAndreas Gohr * first differing byte and avoids hashing the full contents. 740a245329SAndreas Gohr * 750a245329SAndreas Gohr * @param int $rev revision timestamp to compare the current page against 760a245329SAndreas Gohr * @return bool true if the decompressed content is identical 770a245329SAndreas Gohr */ 780a245329SAndreas Gohr protected function currentContentMatchesRevision($rev) 790a245329SAndreas Gohr { 800a245329SAndreas Gohr $current = $this->getFilename(); 810a245329SAndreas Gohr $attic = $this->getFilename($rev); 820a245329SAndreas Gohr if (!file_exists($current) || !file_exists($attic)) return false; 830a245329SAndreas Gohr 840a245329SAndreas Gohr return io_readWikiPage($current, $this->id, '') === io_readWikiPage($attic, $this->id, $rev); 850a245329SAndreas Gohr } 860c3a5702SAndreas Gohr} 87