Let ChangeLog set the mode(media/page) for a revision log entry
This commit is contained in:
parent
8cc30c1c61
commit
a835c93a8c
|
@ -45,6 +45,13 @@ abstract class ChangeLog
|
|||
*/
|
||||
abstract protected function getFilename($rev = '');
|
||||
|
||||
/**
|
||||
* Returns mode
|
||||
*
|
||||
* @return string RevisionInfo::MODE_MEDIA or RevisionInfo::MODE_PAGE
|
||||
*/
|
||||
abstract protected function getMode();
|
||||
|
||||
/**
|
||||
* Check whether given revision is the current page
|
||||
*
|
||||
|
@ -99,17 +106,20 @@ abstract class ChangeLog
|
|||
}
|
||||
|
||||
/**
|
||||
* Save revision info to the cache pool
|
||||
* Parses a changelog line into its components and save revision info to the cache pool
|
||||
*
|
||||
* @param array $info Revision info structure
|
||||
* @return bool
|
||||
* @param string $value changelog line
|
||||
* @return array|bool parsed line or false
|
||||
*/
|
||||
protected function cacheRevisionInfo($info)
|
||||
protected function parseAndCacheLogLine($value)
|
||||
{
|
||||
if (!is_array($info)) return false;
|
||||
//$this->cache[$this->id][$info['date']] ??= $info; // since php 7.4
|
||||
$this->cache[$this->id][$info['date']] ??= $info;
|
||||
return true;
|
||||
$info = static::parseLogLine($value);
|
||||
if(is_array($info)) {
|
||||
$info['mode'] = $this->getMode();
|
||||
$this->cache[$this->id][$info['date']] ??= $info;
|
||||
return $info;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,6 +141,8 @@ abstract class ChangeLog
|
|||
* - sum: edit summary (or action reason)
|
||||
* - extra: extra data (varies by line type)
|
||||
* - sizechange: change of filesize
|
||||
* additional:
|
||||
* - mode: page or media
|
||||
*
|
||||
* @author Ben Coburn <btcoburn@silicodon.net>
|
||||
* @author Kate Arzamastseva <pshns@ukr.net>
|
||||
|
@ -158,9 +170,8 @@ abstract class ChangeLog
|
|||
if (empty($lines)) return false;
|
||||
|
||||
// parse and cache changelog lines
|
||||
foreach ($lines as $value) {
|
||||
$info = static::parseLogLine($value);
|
||||
$this->cacheRevisionInfo($info);
|
||||
foreach ($lines as $line) {
|
||||
$this->parseAndCacheLogLine($line);
|
||||
}
|
||||
if (!isset($this->cache[$this->id][$rev])) {
|
||||
return false;
|
||||
|
@ -285,8 +296,8 @@ abstract class ChangeLog
|
|||
|
||||
// handle lines in reverse order
|
||||
for ($i = count($lines) - 1; $i >= 0; $i--) {
|
||||
$info = static::parseLogLine($lines[$i]);
|
||||
if ($this->cacheRevisionInfo($info)) {
|
||||
$info = $this->parseAndCacheLogLine($lines[$i]);
|
||||
if (is_array($info)) {
|
||||
$revs[] = $info['date'];
|
||||
}
|
||||
}
|
||||
|
@ -342,8 +353,8 @@ abstract class ChangeLog
|
|||
$step = -1;
|
||||
}
|
||||
for ($i = $start; $i >= 0 && $i < $count; $i += $step) {
|
||||
$info = static::parseLogLine($lines[$i]);
|
||||
if ($this->cacheRevisionInfo($info)) {
|
||||
$info = $this->parseAndCacheLogLine($lines[$i]);
|
||||
if (is_array($info)) {
|
||||
//look for revs older/earlier then reference $rev and select $direction-th one
|
||||
if (($direction > 0 && $info['date'] > $rev) || ($direction < 0 && $info['date'] < $rev)) {
|
||||
$revCounter++;
|
||||
|
@ -414,8 +425,8 @@ abstract class ChangeLog
|
|||
$revs1 = $allRevs;
|
||||
while ($head > 0) {
|
||||
for ($i = count($lines) - 1; $i >= 0; $i--) {
|
||||
$info = static::parseLogLine($lines[$i]);
|
||||
if ($this->cacheRevisionInfo($info)) {
|
||||
$info = $this->parseAndCacheLogLine($lines[$i]);
|
||||
if (is_array($info)) {
|
||||
$revs1[] = $info['date'];
|
||||
$index++;
|
||||
|
||||
|
@ -490,8 +501,8 @@ abstract class ChangeLog
|
|||
$tail = $startTail;
|
||||
while (count($lines) > 0) {
|
||||
foreach ($lines as $line) {
|
||||
$info = static::parseLogLine($line);
|
||||
if ($this->cacheRevisionInfo($info)) {
|
||||
$info = $this->parseAndCacheLogLine($line);
|
||||
if (is_array($info)) {
|
||||
$revs[] = $info['date'];
|
||||
if ($info['date'] >= $rev) {
|
||||
//count revs after reference $rev
|
||||
|
@ -530,8 +541,8 @@ abstract class ChangeLog
|
|||
[$lines, $head, $tail] = $this->readAdjacentChunk($fp, $head, $tail, -1);
|
||||
|
||||
for ($i = count($lines) - 1; $i >= 0; $i--) {
|
||||
$info = static::parseLogLine($lines[$i]);
|
||||
if ($this->cacheRevisionInfo($info)) {
|
||||
$info = $this->parseAndCacheLogLine($lines[$i]);
|
||||
if (is_array($info)) {
|
||||
$revs[] = $info['date'];
|
||||
$beforeCount++;
|
||||
//enough revs before reference $rev?
|
||||
|
@ -575,6 +586,8 @@ abstract class ChangeLog
|
|||
* - extra: extra data (varies by line type)
|
||||
* - sizechange: change of filesize
|
||||
* - timestamp: unix timestamp or false (key set only for external edit occurred)
|
||||
* additional:
|
||||
* - mode: page or media
|
||||
*
|
||||
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
|
||||
*/
|
||||
|
@ -616,6 +629,7 @@ abstract class ChangeLog
|
|||
'extra' => '',
|
||||
'sizechange' => -io_getSizeFile($this->getFilename($lastRev)),
|
||||
'timestamp' => false,
|
||||
'mode' => $this->getMode()
|
||||
];
|
||||
} else { // item file exists, with timestamp $fileRev
|
||||
// here, file timestamp $fileRev is different with last revision timestamp $lastRev in changelog
|
||||
|
@ -654,6 +668,7 @@ abstract class ChangeLog
|
|||
'extra' => '',
|
||||
'sizechange' => $sizechange,
|
||||
'timestamp' => $timestamp,
|
||||
'mode' => $this->getMode()
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,15 @@ class MediaChangeLog extends ChangeLog
|
|||
return mediaFN($this->id, $rev);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mode
|
||||
*
|
||||
* @return string RevisionInfo::MODE_PAGE
|
||||
*/
|
||||
protected function getMode()
|
||||
{
|
||||
return RevisionInfo::MODE_MEDIA;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -52,6 +61,7 @@ class MediaChangeLog extends ChangeLog
|
|||
|
||||
// update cache
|
||||
$this->currentRevision = $info['date'];
|
||||
$info['mode'] = $this->getMode();
|
||||
$this->cache[$this->id][$this->currentRevision] = $info;
|
||||
return $info;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,15 @@ class PageChangeLog extends ChangeLog
|
|||
return wikiFN($this->id, $rev);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mode
|
||||
*
|
||||
* @return string RevisionInfo::MODE_PAGE
|
||||
*/
|
||||
protected function getMode()
|
||||
{
|
||||
return RevisionInfo::MODE_PAGE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -52,6 +61,7 @@ class PageChangeLog extends ChangeLog
|
|||
|
||||
// update cache
|
||||
$this->currentRevision = $info['date'];
|
||||
$info['mode'] = $this->getMode();
|
||||
$this->cache[$this->id][$this->currentRevision] = $info;
|
||||
return $info;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,14 @@ namespace dokuwiki\ChangeLog;
|
|||
* - Ui\Recent
|
||||
* - Ui\PageRevisions
|
||||
* - Ui\MediaRevisions
|
||||
* - Ui\PageDiff
|
||||
* - Ui\MediaDiff
|
||||
*/
|
||||
class RevisionInfo
|
||||
{
|
||||
public const MODE_PAGE = 'page';
|
||||
public const MODE_MEDIA = 'media';
|
||||
|
||||
/* @var array */
|
||||
protected $info;
|
||||
|
||||
|
@ -34,12 +39,9 @@ class RevisionInfo
|
|||
*/
|
||||
public function __construct($info = null)
|
||||
{
|
||||
if (is_array($info) && isset($info['id'])) {
|
||||
// define strategy context
|
||||
$info['mode'] = $info['media'] ? 'media' : 'page';
|
||||
} else {
|
||||
if (!is_array($info) || !isset($info['id'])) {
|
||||
$info = [
|
||||
'mode' => 'page',
|
||||
'mode' => self::MODE_PAGE,
|
||||
'date' => false,
|
||||
];
|
||||
}
|
||||
|
@ -106,10 +108,10 @@ class RevisionInfo
|
|||
public function showFileIcon()
|
||||
{
|
||||
$id = $this->val('id');
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
return media_printicon($id);
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
return '<img class="icon" src="' . DOKU_BASE . 'lib/images/fileicons/file.png" alt="' . $id . '" />';
|
||||
}
|
||||
|
@ -172,14 +174,14 @@ class RevisionInfo
|
|||
$id = $this->val('id');
|
||||
$rev = $this->isCurrent() ? '' : $this->val('date');
|
||||
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
$params = ['tab_details' => 'view', 'ns' => getNS($id), 'image' => $id];
|
||||
if ($rev) $params += ['rev' => $rev];
|
||||
$href = media_managerURL($params, '&');
|
||||
$display_name = $id;
|
||||
$exists = file_exists(mediaFN($id, $rev));
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
$params = $rev ? ['rev' => $rev] : [];
|
||||
$href = wl($id, $params, false, '&');
|
||||
|
@ -224,11 +226,11 @@ class RevisionInfo
|
|||
: dformat($this->val('date'));
|
||||
|
||||
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
$href = ml($id, $params, false, '&');
|
||||
$exists = file_exists(mediaFN($id, $rev));
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
$href = wl($id, $params, false, '&');
|
||||
$exists = page_exists($id, $rev);
|
||||
|
@ -260,7 +262,7 @@ class RevisionInfo
|
|||
$id = $this->val('id');
|
||||
|
||||
$href = '';
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
// unlike page, media file does not copied to media_attic when uploaded.
|
||||
// diff icon will not be shown when external edit occurred
|
||||
|
@ -271,7 +273,7 @@ class RevisionInfo
|
|||
$param = ['tab_details' => 'history', 'mediado' => 'diff', 'ns' => getNS($id), 'image' => $id];
|
||||
$href = media_managerURL($param, '&');
|
||||
}
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
// when a page just created anyway, it is natural to expect no older revisions
|
||||
// even if it had once existed but deleted before. Simply ignore to check changelog.
|
||||
|
@ -303,13 +305,13 @@ class RevisionInfo
|
|||
$rev = $this->isCurrent() ? '' : $this->val('date');
|
||||
|
||||
$href = '';
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
if (!$this->isCurrent() && file_exists(mediaFN($id, $rev))) {
|
||||
$param = ['mediado' => 'diff', 'image' => $id, 'rev' => $rev];
|
||||
$href = media_managerURL($param, '&');
|
||||
}
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
if (!$this->isCurrent()) {
|
||||
$href = wl($id, ['rev' => $rev, 'do' => 'diff'], false, '&');
|
||||
|
@ -341,11 +343,11 @@ class RevisionInfo
|
|||
}
|
||||
|
||||
$id = $this->val('id');
|
||||
if ($this->val('mode') == 'media') {
|
||||
if ($this->val('mode') == self::MODE_MEDIA) {
|
||||
// media file revision
|
||||
$param = ['tab_details' => 'history', 'ns' => getNS($id), 'image' => $id];
|
||||
$href = media_managerURL($param, '&');
|
||||
} elseif ($this->val('mode') == 'page') {
|
||||
} elseif ($this->val('mode') == self::MODE_PAGE) {
|
||||
// page revision
|
||||
$href = wl($id, ['do' => 'revisions'], false, '&');
|
||||
}
|
||||
|
|
|
@ -82,7 +82,6 @@ class MediaDiff extends Diff
|
|||
|
||||
$changelogRev1 = $changelog->getRevisionInfo($this->rev1);
|
||||
$changelogRev2 = $changelog->getRevisionInfo($this->rev2);
|
||||
$changelogRev1['media'] = $changelogRev2['media'] = true;
|
||||
|
||||
$this->RevInfo1 = new RevisionInfo($changelogRev1);
|
||||
$this->RevInfo2 = new RevisionInfo($changelogRev2);
|
||||
|
|
|
@ -70,7 +70,6 @@ class MediaRevisions extends Revisions
|
|||
$form->addTagOpen('ul');
|
||||
foreach ($revisions as $info) {
|
||||
$rev = $info['date'];
|
||||
$info['media'] = true;
|
||||
$RevInfo = new RevisionInfo($info);
|
||||
$RevInfo->isCurrent($changelog->isCurrentRevision($rev));
|
||||
|
||||
|
|
|
@ -67,7 +67,6 @@ class PageDiff extends Diff
|
|||
|
||||
// revision info object of older file (left side)
|
||||
$info = $changelog->getCurrentRevisionInfo();
|
||||
$info['media'] = false;
|
||||
$this->RevInfo1 = new RevisionInfo($info);
|
||||
$this->RevInfo1->append([
|
||||
'current' => true,
|
||||
|
@ -138,7 +137,6 @@ class PageDiff extends Diff
|
|||
|
||||
$changelogRev1 = $changelog->getRevisionInfo($this->rev1);
|
||||
$changelogRev2 = $changelog->getRevisionInfo($this->rev2);
|
||||
$changelogRev1['media'] = $changelogRev2['media'] = false;
|
||||
|
||||
$this->RevInfo1 = new RevisionInfo($changelogRev1);
|
||||
$this->RevInfo2 = new RevisionInfo($changelogRev2);
|
||||
|
|
|
@ -69,7 +69,7 @@ class PageRevisions extends Revisions
|
|||
$form->addTagOpen('ul');
|
||||
foreach ($revisions as $info) {
|
||||
$rev = $info['date'];
|
||||
$info['media'] = false;
|
||||
|
||||
$RevInfo = new RevisionInfo($info);
|
||||
$RevInfo->isCurrent($changelog->isCurrentRevision($rev));
|
||||
|
||||
|
|
Loading…
Reference in New Issue