function compareversions() { $id = $this->request->param('ID') ? $this->request->param('ID') : $this->request->requestVar('ID'); $versions = $this->request->requestVar('Versions'); $version1 = $versions && isset($versions[0]) ? $versions[0] : $this->request->getVar('From'); $version2 = $versions && isset($versions[1]) ? $versions[1] : $this->request->getVar('To'); if ($version1 > $version2) { $toVersion = $version1; $fromVersion = $version2; } else { $toVersion = $version2; $fromVersion = $version1; } if (!$toVersion || !$toVersion) { return false; } $page = DataObject::get_by_id("SiteTree", $id); if ($page && !$page->canView()) { return Security::permissionFailure($this); } $record = $page->compareVersions($fromVersion, $toVersion); $fromVersionRecord = Versioned::get_version('SiteTree', $id, $fromVersion); $toVersionRecord = Versioned::get_version('SiteTree', $id, $toVersion); if (!$fromVersionRecord) { user_error("Can't find version {$fromVersion} of page {$id}", E_USER_ERROR); } if (!$toVersionRecord) { user_error("Can't find version {$toVersion} of page {$id}", E_USER_ERROR); } if ($record) { $fromDateNice = $fromVersionRecord->obj('LastEdited')->Ago(); $toDateNice = $toVersionRecord->obj('LastEdited')->Ago(); $fromAuthor = DataObject::get_by_id('Member', $fromVersionRecord->AuthorID); if (!$fromAuthor) { $fromAuthor = new ArrayData(array('Title' => 'Unknown author')); } $toAuthor = DataObject::get_by_id('Member', $toVersionRecord->AuthorID); if (!$toAuthor) { $toAuthor = new ArrayData(array('Title' => 'Unknown author')); } $fields = $record->getCMSFields($this); $fields->push(new HiddenField("ID")); $fields->push(new HiddenField("Version")); $fields->insertBefore(new LiteralField('YouAreComparingHeader', '<p class="message notice">' . sprintf(_t('CMSMain.COMPARINGV', "Comparing versions %s and %s"), "<a href=\"admin/getversion/{$id}/{$fromVersionRecord->Version}\" title=\"{$fromAuthor->Title}\">{$fromVersionRecord->Version}</a> <small>({$fromDateNice})</small>", "<a href=\"admin/getversion/{$id}/{$toVersionRecord->Version}\" title=\"{$toAuthor->Title}\">{$toVersionRecord->Version}</a> <small>({$toDateNice})</small>") . '</p>'), "Root"); $actions = new FieldSet(); $form = new Form($this, "EditForm", $fields, $actions); $form->loadDataFrom($record); $form->loadDataFrom(array("ID" => $id, "Version" => $fromVersion)); // comparison views shouldn't be editable $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); foreach ($form->Fields()->dataFields() as $field) { $field->dontEscape = true; } if ($this->isAjax()) { return $form->formHtmlContent(); } else { $templateData = $this->customise(array("EditForm" => $form)); return $templateData->renderWith('LeftAndMain'); } } }