From c1c06a6a4682d3ea6778757b1cbf7982d0a416fc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 23 Jun 2014 17:16:14 +0200 Subject: [PATCH] Add basic edit history page --- com.woltlab.wcf/templates/editHistory.tpl | 24 +++ .../files/lib/page/EditHistoryPage.class.php | 152 ++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 com.woltlab.wcf/templates/editHistory.tpl create mode 100644 wcfsetup/install/files/lib/page/EditHistoryPage.class.php diff --git a/com.woltlab.wcf/templates/editHistory.tpl b/com.woltlab.wcf/templates/editHistory.tpl new file mode 100644 index 0000000000..49fdedbdee --- /dev/null +++ b/com.woltlab.wcf/templates/editHistory.tpl @@ -0,0 +1,24 @@ +{include file='documentHeader'} + + + {$object->getTitle()} - {lang}wcf.edit.versions{/lang} - {PAGE_TITLE|language} + + {include file='headInclude'} + + + + +{include file='header'} + +
+

{$object->getTitle()}

+
+ +{include file='userNotice'} + +
{$diff}
+ +{include file='footer'} + + + diff --git a/wcfsetup/install/files/lib/page/EditHistoryPage.class.php b/wcfsetup/install/files/lib/page/EditHistoryPage.class.php new file mode 100644 index 0000000000..ee623a32ba --- /dev/null +++ b/wcfsetup/install/files/lib/page/EditHistoryPage.class.php @@ -0,0 +1,152 @@ + + * @package com.woltlab.wcf + * @subpackage page + * @category Community Framework + */ +class EditHistoryPage extends AbstractPage { + /** + * left / old version id + * @var integer + */ + public $oldID = 0; + + /** + * left / old version + * @var \wcf\data\edit\history\entry\EditHistoryEntry + */ + public $old = null; + + /** + * right / new version id + * @var integer + */ + public $newID = 0; + + /** + * right / new version + * @var \wcf\data\edit\history\entry\EditHistoryEntry + */ + public $new = null; + + /** + * differences between both versions + * @var \wcf\util\Diff + */ + public $diff = null; + + /** + * object type id of the requested object + * @var integer + */ + public $objectTypeID = 0; + + /** + * object type of the requested object + * @var \wcf\data\object\type\ObjectType + */ + public $objectType = null; + + /** + * id of the requested object + * @var integer + */ + public $objectID = 0; + + /** + * requested object + * @var \wcf\system\edit\IHistorySavingObject + */ + public $object = null; + + /** + * @see \wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['oldID']) && isset($_REQUEST['newID'])) { + $this->oldID = intval($_REQUEST['oldID']); + $this->old = new EditHistoryEntry($this->oldID); + if (!$this->old->entryID) throw new IllegalLinkException(); + + if ($_REQUEST['newID'] !== 'current') { + $this->newID = intval($_REQUEST['newID']); + $this->new = new EditHistoryEntry($this->newID); + if (!$this->new->entryID) throw new IllegalLinkException(); + } + + // if new version isn't 'current' check whether they are comparable + if ($this->new) { + // different objectTypes cannot be compared + if ($this->old->objectTypeID != $this->new->objectTypeID) throw new IllegalLinkException(); + // different items cannot be compared + if ($this->old->objectID != $this->new->objectID) throw new IllegalLinkException(); + } + + $this->objectID = $this->old->objectID; + $this->objectTypeID = $this->old->objectTypeID; + } + else if (isset($_REQUEST['objectID']) && isset($_REQUEST['objectTypeID'])) { + $this->objectID = intval($_REQUEST['objectID']); + $this->objectTypeID = intval($_REQUEST['objectTypeID']); + } + else { + throw new IllegalLinkException(); + } + + $this->objectType = ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); + $processor = $this->objectType->getProcessor(); + $this->object = $processor->getObjectByID($this->objectID); + $processor->checkPermissions($this->object); + $this->activeMenuItem = $processor->getActivePageMenuItem(); + + if (!$this->new) { + $this->new = $this->object; + } + } + + /** + * @see \wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + // valid IDs were given, calculate diff + if ($this->old) { + $a = explode("\n", StringUtil::unifyNewlines($this->old->getMessage())); + $b = explode("\n", StringUtil::unifyNewlines($this->new->getMessage())); + $this->diff = new Diff($a, $b); + } + } + + /** + * @see \wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'oldID' => $this->oldID, + 'old' => $this->old, + 'newID' => $this->newID, + 'new' => $this->new, + 'object' => $this->object, + 'diff' => $this->diff + )); + } +} -- 2.20.1