diff --git a/inc/ChangeLog/RevisionInfo.php b/inc/ChangeLog/RevisionInfo.php
new file mode 100644
index 0000000000..4beec053ec
--- /dev/null
+++ b/inc/ChangeLog/RevisionInfo.php
@@ -0,0 +1,285 @@
+info = $info;
+ }
+
+ /**
+ * fileicon of the page or media file
+ * used in [Ui\recent]
+ *
+ * @return string
+ */
+ public function itemIcon()
+ {
+ $id = $this->info['id'];
+ switch ($this->info['item']) {
+ case 'media': // media file revision
+ $html = media_printicon($id);
+ break;
+ case 'page': // page revision
+ $html = '';
+ }
+ return $html;
+ }
+
+ /**
+ * edit date and time of the page or media file
+ * used in [Ui\recent, Ui\Revisions]
+ *
+ * @param bool $checkTimestamp enable timestamp check, alter formatted string when timestamp is false
+ * @return string
+ */
+ public function editDate($checkTimestamp = false)
+ {
+ global $lang;
+ $formatted = dformat($this->info['date']);
+ if ($checkTimestamp && $this->info['timestamp'] === false) {
+ // exact date is unknown for item has externally deleted or older file restored
+ // when unknown, alter formatted string "YYYY-mm-DD HH:MM" to "____-__-__ __:__"
+ $formatted = preg_replace('/[0-9a-zA-Z]/','_', $formatted);
+ }
+ return ''. $formatted .'';
+ }
+
+ /**
+ * edit summary
+ * used in [Ui\recent, Ui\Revisions]
+ *
+ * @return string
+ */
+ public function editSummary()
+ {
+ return ''.' – '. hsc($this->info['sum']).'';
+ }
+
+ /**
+ * editor of the page or media file
+ * used in [Ui\recent, Ui\Revisions]
+ *
+ * @return string
+ */
+ public function editor()
+ {
+ global $lang;
+ $html = '';
+ if ($this->info['user']) {
+ $html.= ''. editorinfo($this->info['user']) .'';
+ if (auth_ismanager()) $html.= ' ('. $this->info['ip'] .')';
+ } else {
+ $html.= ''. $this->info['ip'] .'';
+ }
+ $html.= '';
+ return $html;
+ }
+
+ /**
+ * name of the page or media file
+ * used in [Ui\recent, Ui\Revisions]
+ *
+ * @return string
+ */
+ public function itemName()
+ {
+ $id = $this->info['id'];
+ $rev = ($this->info['current']) ? '' : $this->info['date'];
+
+ switch ($this->info['item']) {
+ case 'media': // media file revision
+ $params = ['tab_details'=> 'view', 'ns'=> getNS($id), 'image'=> $id];
+ if ($rev) $params += ['rev'=> $rev];
+ $href = media_managerURL($params, '&');
+ $class = file_exists(mediaFN($id, $rev)) ? 'wikilink1' : 'wikilink2';
+ return ''.$id.'';
+ case 'page': // page revision
+ $params = ($rev) ? '' : "rev=$rev";
+ $href = wl($id, $params, false, '&');
+ $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
+ if (!$display_name) $display_name = $id;
+ $class = page_exists($id, $rev) ? 'wikilink1' : 'wikilink2';
+ if ($this->info['type'] == DOKU_CHANGE_TYPE_DELETE) {
+ $class = 'wikilink2';
+ }
+ return ''.$display_name.'';
+ }
+ }
+
+ /**
+ * difflink icon in recents list
+ * all items in the recents are "current" revision of the page or media
+ *
+ * @return string
+ */
+ public function difflinkRecent()
+ {
+ global $lang;
+ $id = $this->info['id'];
+
+ $href = '';
+ switch ($this->info['item']) {
+ case 'media': // media file revision
+ $revs = (new MediaChangeLog($id))->getRevisions(0, 1);
+ $showLink = (count($revs) && file_exists(mediaFN($id)));
+ if ($showLink) {
+ $href = media_managerURL(
+ ['tab_details'=>'history', 'mediado'=>'diff', 'image'=> $id, 'ns'=> getNS($id)], '&'
+ );
+ }
+ break;
+ case 'page': // page revision
+ if($this->info['type'] !== DOKU_CHANGE_TYPE_CREATE) {
+ $href = wl($id, "do=diff", false, '&');
+ }
+ }
+
+ if ($href) {
+ $html = ''
+ . ''
+ . '';
+ } else {
+ $html = '';
+ }
+ return $html;
+ }
+
+ /**
+ * difflink icon in revsions list
+ * the icon does not displayed for the current revision
+ *
+ * @return string
+ */
+ public function difflinkRevision()
+ {
+ global $lang;
+ $id = $this->info['id'];
+ $rev = $this->info['date'];
+
+ switch ($this->info['item']) {
+ case 'media': // media file revision
+ if ($this->info['current'] || !file_exists(mediaFN($id, $rev))) {
+ $html = '';
+ } else {
+ $href = media_managerURL(['image'=> $id, 'rev'=> $rev, 'mediado'=>'diff'], '&');
+ $html = ''
+ . ''
+ . ' ';
+ }
+ return $html;
+ case 'page': // page revision
+ if ($this->info['current'] || !page_exists($id, $rev)) {
+ $html = '';
+ } else {
+ $href = wl($id, "rev=$rev,do=diff", false, '&');
+ $html = ''
+ . ''
+ . '';
+ }
+ return $html;
+ }
+ return '';
+ }
+
+ /**
+ * icon revision link
+ * used in [Ui\recent]
+ *
+ * @return string
+ */
+ public function revisionlink()
+ {
+ global $lang, $conf;
+
+ if (!actionOK('revisions')) {
+ return ''; //FIXME check page, media
+ }
+
+ $id = $this->info['id'];
+ switch ($this->info['item']) {
+ case 'media': // media file revision
+ $href = media_managerURL(['tab_details'=>'history', 'image'=> $id, 'ns'=> getNS($id)], '&');
+ break;
+ case 'page': // page revision
+ $href = wl($id, "do=revisions", false, '&');
+ }
+ return ''
+ . ''
+ . '';
+ }
+
+ /**
+ * size change
+ * used in [Ui\recent, Ui\Revisions]
+ *
+ * @return string
+ */
+ public function sizeChange()
+ {
+ $class = 'sizechange';
+ $value = filesize_h(abs($this->info['sizechange']));
+ if ($this->info['sizechange'] > 0) {
+ $class .= ' positive';
+ $value = '+' . $value;
+ } elseif ($this->info['sizechange'] < 0) {
+ $class .= ' negative';
+ $value = '-' . $value;
+ } else {
+ $value = '±' . $value;
+ }
+ return ''.$value.'';
+ }
+
+ /**
+ * current indicator, used in revison list
+ * not used in Ui\Recents because recent items are always current one
+ *
+ * @return string
+ */
+ public function currentIndicator()
+ {
+ global $lang;
+ return ($this->info['current']) ? '('.$lang['current'].')' : '';
+ }
+
+
+}
diff --git a/inc/Ui/MediaDiff.php b/inc/Ui/MediaDiff.php
index 0c9a4f9456..61cd0341f3 100644
--- a/inc/Ui/MediaDiff.php
+++ b/inc/Ui/MediaDiff.php
@@ -3,6 +3,7 @@
namespace dokuwiki\Ui;
use dokuwiki\ChangeLog\MediaChangeLog;
+use dokuwiki\ChangeLog\RevisionInfo;
use dokuwiki\Form\Form;
use InvalidArgumentException;
use JpegMeta;
@@ -340,8 +341,8 @@ protected function revisionTitle(array $info)
// supplement
if (isset($info['date'])) {
- $objRevInfo = (new MediaRevisions($this->id))->getObjRevInfo($info);
- $title .= $objRevInfo->editSummary().' '.$objRevInfo->editor();
+ $RevInfo = new RevisionInfo($info);
+ $title .= $RevInfo->editSummary().' '.$RevInfo->editor();
}
return $title;
}
diff --git a/inc/Ui/MediaRevisions.php b/inc/Ui/MediaRevisions.php
index a5abe7fd62..f4f2f7d6b5 100644
--- a/inc/Ui/MediaRevisions.php
+++ b/inc/Ui/MediaRevisions.php
@@ -3,6 +3,7 @@
namespace dokuwiki\Ui;
use dokuwiki\ChangeLog\MediaChangeLog;
+use dokuwiki\ChangeLog\RevisionInfo;
use dokuwiki\Form\Form;
use InvalidArgumentException;
@@ -84,16 +85,16 @@ public function show($first = 0)
}
$form->addHTML(' ');
- $objRevInfo = $this->getObjRevInfo($info);
+ $RevInfo = new RevisionInfo($info);
$html = implode(' ', [
- $objRevInfo->editDate(), // edit date and time
- $objRevInfo->difflink(), // link to diffview icon
- $objRevInfo->itemName(), // name of page or media
+ $RevInfo->editDate(), // edit date and time
+ $RevInfo->difflink(), // link to diffview icon
+ $RevInfo->itemName(), // name of page or media
'
',
- $objRevInfo->editSummary(), // edit summary
- $objRevInfo->editor(), // editor info
- $objRevInfo->sizechange(), // size change indicator
- $objRevInfo->currentIndicator(), // current indicator (only when k=1)
+ $RevInfo->editSummary(), // edit summary
+ $RevInfo->editor(), // editor info
+ $RevInfo->sizechange(), // size change indicator
+ $RevInfo->currentIndicator(), // current indicator (only when k=1)
'
',
]);
$form->addHTML($html);
diff --git a/inc/Ui/PageDiff.php b/inc/Ui/PageDiff.php
index ec5153517c..08b830e4be 100644
--- a/inc/Ui/PageDiff.php
+++ b/inc/Ui/PageDiff.php
@@ -3,6 +3,7 @@
namespace dokuwiki\Ui;
use dokuwiki\ChangeLog\PageChangeLog;
+use dokuwiki\ChangeLog\RevisionInfo;
use dokuwiki\Form\Form;
use InlineDiffFormatter;
use TableDiffFormatter;
@@ -128,12 +129,34 @@ protected function handle()
*/
protected function preProcess()
{
+ global $lang;
+
$changelog =& $this->changelog;
- // revision info of older file (left side)
- $this->oldRevInfo = $changelog->getRevisionInfo($this->oldRev);
- // revision info of newer file (right side)
- $this->newRevInfo = $changelog->getRevisionInfo($this->newRev);
+ // check validity of $this->{oldRev, newRev}
+ foreach (['oldRev','newRev'] as $rev) {
+ $revInfo = $rev.'Info';
+ $this->$revInfo = $changelog->getRevisionInfo((int)$this->$rev);
+ if (!$this->$revInfo) {
+ // invalid revision number, set dummy revInfo
+ $this->$revInfo = array(
+ 'date' => time(),
+ 'type' => '',
+ 'timestamp' => false,
+ 'rev' => false,
+ 'text' => '',
+ 'navTitle' => '—',
+ );
+ }
+ }
+ if ($this->newRev === false) {
+ msg(sprintf($lang['page_nonexist_rev'],
+ $this->id,
+ wl($this->id, ['do'=>'edit']),
+ $this->id), -1);
+ } elseif ($this->oldRevInfo == $this->newRevInfo) {
+ msg('no way to compare when less than two revisions', -1);
+ }
foreach ([&$this->oldRevInfo, &$this->newRevInfo] as &$revInfo) {
// use timestamp and '' properly as $rev for the current file
@@ -144,7 +167,9 @@ protected function preProcess()
];
// headline in the Diff view navigation
- $revInfo['navTitle'] = $this->revisionTitle($revInfo);
+ if (!isset($revInfo['navTitle'])) {
+ $revInfo['navTitle'] = $this->revisionTitle($revInfo);
+ }
if ($revInfo['type'] == DOKU_CHANGE_TYPE_DELETE) {
//attic stores complete last page version for a deleted page
@@ -288,8 +313,8 @@ protected function revisionTitle(array $info)
// supplement
if (isset($info['date'])) {
- $objRevInfo = (new PageRevisions($this->id))->getObjRevInfo($info);
- $title .= $objRevInfo->editSummary().' '.$objRevInfo->editor();
+ $RevInfo = new RevisionInfo($info);
+ $title .= $RevInfo->editSummary().' '.$RevInfo->editor();
}
return $title;
}
diff --git a/inc/Ui/PageRevisions.php b/inc/Ui/PageRevisions.php
index 3c20cbf470..a702b50e95 100644
--- a/inc/Ui/PageRevisions.php
+++ b/inc/Ui/PageRevisions.php
@@ -3,6 +3,7 @@
namespace dokuwiki\Ui;
use dokuwiki\ChangeLog\PageChangeLog;
+use dokuwiki\ChangeLog\RevisionInfo;
use dokuwiki\Form\Form;
/**
@@ -85,15 +86,15 @@ public function show($first = 0)
}
$form->addHTML(' ');
- $objRevInfo = $this->getObjRevInfo($info);
+ $RevInfo = new RevisionInfo($info);
$html = implode(' ', [
- $objRevInfo->editDate(), // edit date and time
- $objRevInfo->difflink(), // link to diffview icon
- $objRevInfo->itemName(), // name of page or media
- $objRevInfo->editSummary(), // edit summary
- $objRevInfo->editor(), // editor info
- $objRevInfo->sizechange(), // size change indicator
- $objRevInfo->currentIndicator(), // current indicator (only when k=1)
+ $RevInfo->editDate(true), // edit date and time
+ $RevInfo->difflinkRevision(), // link to diffview icon
+ $RevInfo->itemName(), // name of page or media
+ $RevInfo->editSummary(), // edit summary
+ $RevInfo->editor(), // editor info
+ $RevInfo->sizechange(), // size change indicator
+ $RevInfo->currentIndicator(), // current indicator (only when k=1)
]);
$form->addHTML($html);
$form->addTagClose('div');
diff --git a/inc/Ui/Recent.php b/inc/Ui/Recent.php
index 0ecfdb0116..5f6102e987 100644
--- a/inc/Ui/Recent.php
+++ b/inc/Ui/Recent.php
@@ -4,6 +4,7 @@
use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\ChangeLog\MediaChangeLog;
+use dokuwiki\ChangeLog\RevisionInfo;
use dokuwiki\Form\Form;
/**
@@ -77,19 +78,19 @@ public function show()
$this->checkCurrentRevision($recent);
$recent['current'] = true;
- $objRevInfo = $this->getObjRevInfo($recent);
+ $RevInfo = new RevisionInfo($recent);
$class = ($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor': '';
$form->addTagOpen('li')->addClass($class);
$form->addTagOpen('div')->addClass('li');
$html = implode(' ', [
- $objRevInfo->itemIcon(), // filetype icon
- $objRevInfo->editDate(), // edit date and time
- $objRevInfo->difflink(), // link to diffview icon
- $objRevInfo->revisionlink(), // linkto revisions icon
- $objRevInfo->itemName(), // name of page or media
- $objRevInfo->editSummary(), // edit summary
- $objRevInfo->editor(), // editor info
- $objRevInfo->sizechange(), // size change indicator
+ $RevInfo->itemIcon(), // filetype icon
+ $RevInfo->editDate(), // edit date and time
+ $RevInfo->difflinkRecent(), // link to diffview icon
+ $RevInfo->revisionlink(), // linkto revisions icon
+ $RevInfo->itemName(), // name of page or media
+ $RevInfo->editSummary(), // edit summary
+ $RevInfo->editor(), // editor info
+ $RevInfo->sizechange(), // size change indicator
]);
$form->addHTML($html);
$form->addTagClose('div');
@@ -224,148 +225,4 @@ protected function addRecentItemSelector(Form $form)
$form->addTagClose('div');
}
- /**
- * Returns instance of objRevInfo
- * @param array $info Revision info structure of page or media
- * @return objRevInfo object (anonymous class)
- */
- protected function getObjRevInfo(array $info)
- {
- return new class ($info) // anonymous class (objRevInfo)
- {
- protected $info;
-
- public function __construct(array $info)
- {
- $info['item'] = strrpos($info['id'], '.') ? 'media' : 'page';
- $info['current'] = $info['current'] ?? false;
- $this->info = $info;
- }
-
- // fileicon of the page or media file
- public function itemIcon()
- {
- $id = $this->info['id'];
- switch ($this->info['item']) {
- case 'media': // media file revision
- $html = media_printicon($id);
- break;
- case 'page': // page revision
- $html = '';
- }
- return $html;
- }
-
- // edit date and time of the page or media file
- public function editDate()
- {
- return ''. dformat($this->info['date']) .'';
- }
-
- // edit summary
- public function editSummary()
- {
- return ''.' – '. hsc($this->info['sum']).'';
- }
-
- // editor of the page or media file
- public function editor()
- {
- $html = '';
- if ($this->info['user']) {
- $html.= ''. editorinfo($this->info['user']) .'';
- if (auth_ismanager()) $html.= ' ('. $this->info['ip'] .')';
- } else {
- $html.= ''. $this->info['ip'] .'';
- }
- $html.= '';
- return $html;
- }
-
- // name of the page or media file
- public function itemName()
- {
- $id = $this->info['id'];
- switch ($this->info['item']) {
- case 'media': // media file revision
- $href = media_managerURL(['tab_details'=>'view', 'image'=> $id, 'ns'=> getNS($id)], '&');
- $class = file_exists(mediaFN($id)) ? 'wikilink1' : 'wikilink2';
- return ''.$id.'';
- case 'page': // page revision
- return html_wikilink(':'.$id, (useHeading('navigation') ? null : $id));
- }
- return '';
- }
-
- // icon difflink
- public function difflink()
- {
- global $lang;
- $id = $this->info['id'];
-
- $href = '';
- switch ($this->info['item']) {
- case 'media': // media file revision
- $revs = (new MediaChangeLog($id))->getRevisions(0, 1);
- $showLink = (count($revs) && file_exists(mediaFN($id)));
- if ($showLink) {
- $href = media_managerURL(
- ['tab_details'=>'history', 'mediado'=>'diff', 'image'=> $id, 'ns'=> getNS($id)], '&'
- );
- }
- break;
- case 'page': // page revision
- if($this->info['type'] !== DOKU_CHANGE_TYPE_CREATE) {
- $href = wl($id, "do=diff", false, '&');
- }
- }
-
- if ($href) {
- $html = ''
- . ''
- . '';
- } else {
- $html = '';
- }
- return $html;
- }
-
- // icon revision link
- public function revisionlink()
- {
- global $lang;
- $id = $this->info['id'];
- switch ($this->info['item']) {
- case 'media': // media file revision
- $href = media_managerURL(['tab_details'=>'history', 'image'=> $id, 'ns'=> getNS($id)], '&');
- break;
- case 'page': // page revision
- $href = wl($id, "do=revisions", false, '&');
- }
- return ''
- . ''
- . '';
- }
-
- // size change
- public function sizeChange()
- {
- $class = 'sizechange';
- $value = filesize_h(abs($this->info['sizechange']));
- if ($this->info['sizechange'] > 0) {
- $class .= ' positive';
- $value = '+' . $value;
- } elseif ($this->info['sizechange'] < 0) {
- $class .= ' negative';
- $value = '-' . $value;
- } else {
- $value = '±' . $value;
- }
- return ''.$value.'';
- }
- }; // end of anonymous class (objRevInfo)
- }
-
}
diff --git a/inc/Ui/Revisions.php b/inc/Ui/Revisions.php
index e38f78844b..2e8f8d30b0 100644
--- a/inc/Ui/Revisions.php
+++ b/inc/Ui/Revisions.php
@@ -117,158 +117,4 @@ protected function navigation($first, $hasNext, $callback)
return $html;
}
- /**
- * Returns instance of objRevInfo
- *
- * @param array $info Revision info structure of a page or media file
- * @return objRevInfo object (anonymous class)
- */
- public function getObjRevInfo(array $info)
- {
- return new class ($info) // anonymous class (objRevInfo)
- {
- protected $info;
-
- public function __construct(array $info)
- {
- $info['item'] = strrpos($info['id'], '.') ? 'media' : 'page';
- $info['current'] = $info['current'] ?? false;
- // revision info may have timestamp key when external edits occurred
- $info['timestamp'] = $info['timestamp'] ?? true;
- $this->info = $info;
- }
-
- // current indicator
- public function currentIndicator()
- {
- global $lang;
- return ($this->info['current']) ? '('.$lang['current'].')' : '';
- }
-
- // edit date and time of the page or media file
- public function editDate()
- {
- global $lang;
- $date = dformat($this->info['date']);
- if ($this->info['timestamp'] === false) {
- // externally deleted or older file restored
- $date = preg_replace('/[0-9a-zA-Z]/','_', $date);
- }
- return ''. $date .'';
- }
-
- // edit summary
- public function editSummary()
- {
- return ''.' – '. hsc($this->info['sum']).'';
- }
-
- // editor of the page or media file
- public function editor()
- {
- // slightly different with display of Ui\Recent, i.e. external edit
- global $lang;
- $html = '';
- if (!$this->info['user'] && !$this->info['ip']) {
- $html.= '('.$lang['external_edit'].')';
- } elseif ($this->info['user']) {
- $html.= ''. editorinfo($this->info['user']) .'';
- if (auth_ismanager()) $html.= ' ('. $this->info['ip'] .')';
- } else {
- $html.= ''. $this->info['ip'] .'';
- }
- $html.= '';
- return $html;
- }
-
- // name of the page or media file
- public function itemName()
- {
- // slightly different with display of Ui\Recent, i.e. revison may not exists
- $id = $this->info['id'];
- $rev = $this->info['date'];
-
- switch ($this->info['item']) {
- case 'media': // media file revision
- if ($this->info['current']) {
- $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view'], '&');
- $html = ''.$id.'';
- } elseif (file_exists(mediaFN($id, $rev))) {
- $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view', 'rev'=> $rev], '&');
- $html = ''.$id.'';
- } else {
- $html = $id;
- }
- return $html;
- case 'page': // page revision
- $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
- if (!$display_name) $display_name = $id;
- if ($this->info['type'] == DOKU_CHANGE_TYPE_DELETE) {
- // externally deleted or older file restored
- $href = wl($id, "", false, '&');
- $html = ''.$display_name.'';
- } elseif ($this->info['current'] || page_exists($id, $rev)) {
- $href = wl($id, "rev=$rev", false, '&');
- $html = ''.$display_name.'';
- } else {
- $html = $display_name;
- }
- return $html;
- }
- return '';
- }
-
- // icon difflink
- public function difflink()
- {
- global $lang;
- $id = $this->info['id'];
- $rev = $this->info['date'];
-
- switch ($this->info['item']) {
- case 'media': // media file revision
- if ($this->info['current'] || !file_exists(mediaFN($id, $rev))) {
- $html = '';
- } else {
- $href = media_managerURL(['image'=> $id, 'rev'=> $rev, 'mediado'=>'diff'], '&');
- $html = ''
- . ''
- . ' ';
- }
- return $html;
- case 'page': // page revision
- if ($this->info['current'] || !page_exists($id, $rev)) {
- $html = '';
- } else {
- $href = wl($id, "rev=$rev,do=diff", false, '&');
- $html = ''
- . ''
- . '';
- }
- return $html;
- }
- return '';
- }
-
- // size change
- public function sizeChange()
- {
- $class = 'sizechange';
- $value = filesize_h(abs($this->info['sizechange']));
- if ($this->info['sizechange'] > 0) {
- $class .= ' positive';
- $value = '+' . $value;
- } elseif ($this->info['sizechange'] < 0) {
- $class .= ' negative';
- $value = '-' . $value;
- } else {
- $value = '±' . $value;
- }
- return ''.$value.'';
- }
- }; // end of anonymous class (objRevInfo)
- }
-
}