Add basic edit history page
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 23 Jun 2014 15:16:14 +0000 (17:16 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 9 Jul 2014 19:51:08 +0000 (21:51 +0200)
com.woltlab.wcf/templates/editHistory.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/page/EditHistoryPage.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/editHistory.tpl b/com.woltlab.wcf/templates/editHistory.tpl
new file mode 100644 (file)
index 0000000..49fdedb
--- /dev/null
@@ -0,0 +1,24 @@
+{include file='documentHeader'}
+
+<head>
+       <title>{$object->getTitle()} - {lang}wcf.edit.versions{/lang} - {PAGE_TITLE|language}</title>
+       
+       {include file='headInclude'}
+</head>
+
+<body id="tpl{$templateName|ucfirst}">
+
+{include file='header'}
+
+<header class="boxHeadline">
+       <h1>{$object->getTitle()}</h1>
+</header>
+
+{include file='userNotice'}
+
+<pre>{$diff}</pre>
+
+{include file='footer'}
+
+</body>
+</html>
diff --git a/wcfsetup/install/files/lib/page/EditHistoryPage.class.php b/wcfsetup/install/files/lib/page/EditHistoryPage.class.php
new file mode 100644 (file)
index 0000000..ee623a3
--- /dev/null
@@ -0,0 +1,152 @@
+<?php
+namespace wcf\page;
+use wcf\data\edit\history\entry\EditHistoryEntry;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\page\AbstractPage;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\WCF;
+use wcf\util\Diff;
+use wcf\util\StringUtil;
+
+/**
+ * Compares two templates.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
+               ));
+       }
+}