2011-08-19 02:32:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage controllers
|
|
|
|
*/
|
|
|
|
class CMSPageHistoryController extends CMSMain {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_segment = 'pages/history';
|
|
|
|
private static $url_rule = '/$Action/$ID/$VersionID/$OtherVersionID';
|
|
|
|
private static $url_priority = 42;
|
|
|
|
private static $menu_title = 'History';
|
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
|
|
|
private static $session_namespace = 'CMSMain';
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_actions = array(
|
2011-08-19 02:32:31 +02:00
|
|
|
'VersionsForm',
|
2013-02-07 21:44:07 +01:00
|
|
|
'CompareVersionsForm',
|
|
|
|
'show',
|
2011-08-19 02:32:31 +02:00
|
|
|
'compare'
|
|
|
|
);
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_handlers = array(
|
2011-08-19 02:32:31 +02:00
|
|
|
'$Action/$ID/$VersionID/$OtherVersionID' => 'handleAction'
|
|
|
|
);
|
2012-06-15 12:50:54 +02:00
|
|
|
|
|
|
|
public function getResponseNegotiator() {
|
|
|
|
$negotiator = parent::getResponseNegotiator();
|
|
|
|
$controller = $this;
|
|
|
|
$negotiator->setCallback('CurrentForm', function() use(&$controller) {
|
|
|
|
$form = $controller->ShowVersionForm($controller->getRequest()->param('VersionID'));
|
|
|
|
if($form) return $form->forTemplate();
|
|
|
|
else return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
|
|
|
});
|
|
|
|
$negotiator->setCallback('default', function() use(&$controller) {
|
|
|
|
return $controller->renderWith($controller->getViewer('show'));
|
|
|
|
});
|
|
|
|
return $negotiator;
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param SS_HTTPRequest $request
|
2011-08-26 04:03:21 +02:00
|
|
|
* @return array
|
2011-08-19 02:32:31 +02:00
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function show($request) {
|
2011-10-29 20:45:37 +02:00
|
|
|
$form = $this->ShowVersionForm($request->param('VersionID'));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2012-06-15 12:50:54 +02:00
|
|
|
$negotiator = $this->getResponseNegotiator();
|
|
|
|
$controller = $this;
|
|
|
|
$negotiator->setCallback('CurrentForm', function() use(&$controller, &$form) {
|
|
|
|
return $form ? $form->forTemplate() : $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
|
|
|
});
|
|
|
|
$negotiator->setCallback('default', function() use(&$controller, &$form) {
|
|
|
|
return $controller->customise(array('EditForm' => $form))->renderWith($controller->getViewer('show'));
|
|
|
|
});
|
|
|
|
|
|
|
|
return $negotiator->respond($request);
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param SS_HTTPRequest $request
|
2011-08-26 04:03:21 +02:00
|
|
|
* @return array
|
2011-08-19 02:32:31 +02:00
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function compare($request) {
|
2011-09-19 21:06:39 +02:00
|
|
|
$form = $this->CompareVersionsForm(
|
2015-09-29 06:18:03 +02:00
|
|
|
$request->param('VersionID'),
|
2011-09-19 21:06:39 +02:00
|
|
|
$request->param('OtherVersionID')
|
2011-08-19 02:32:31 +02:00
|
|
|
);
|
2012-06-15 12:50:54 +02:00
|
|
|
|
|
|
|
$negotiator = $this->getResponseNegotiator();
|
|
|
|
$controller = $this;
|
|
|
|
$negotiator->setCallback('CurrentForm', function() use(&$controller, &$form) {
|
|
|
|
return $form ? $form->forTemplate() : $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
|
|
|
});
|
|
|
|
$negotiator->setCallback('default', function() use(&$controller, &$form) {
|
|
|
|
return $controller->customise(array('EditForm' => $form))->renderWith($controller->getViewer('show'));
|
|
|
|
});
|
|
|
|
|
|
|
|
return $negotiator->respond($request);
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
2013-01-25 11:35:48 +01:00
|
|
|
|
|
|
|
public function getSilverStripeNavigator() {
|
2015-04-30 01:04:02 +02:00
|
|
|
$record = $this->getRecord($this->currentPageID(), $this->getRequest()->param('VersionID'));
|
2013-01-25 11:35:48 +01:00
|
|
|
if($record) {
|
|
|
|
$navigator = new SilverStripeNavigator($record);
|
|
|
|
return $navigator->renderWith($this->getTemplatesWithSuffix('_SilverStripeNavigator'));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
2015-09-29 06:18:03 +02:00
|
|
|
* Returns the read only version of the edit form. Detaches all {@link FormAction}
|
2011-08-19 02:32:31 +02:00
|
|
|
* instances attached since only action relates to revert.
|
|
|
|
*
|
|
|
|
* Permission checking is done at the {@link CMSMain::getEditForm()} level.
|
2015-09-29 06:18:03 +02:00
|
|
|
*
|
2011-08-19 02:32:31 +02:00
|
|
|
* @param int $id ID of the record to show
|
|
|
|
* @param array $fields optional
|
|
|
|
* @param int $versionID
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param int $compareID Compare mode
|
2011-08-26 04:03:21 +02:00
|
|
|
*
|
|
|
|
* @return Form
|
2011-08-19 02:32:31 +02:00
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function getEditForm($id = null, $fields = null, $versionID = null, $compareID = null) {
|
2011-08-26 04:03:21 +02:00
|
|
|
if(!$id) $id = $this->currentPageID();
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$record = $this->getRecord($id, $versionID);
|
2011-08-26 04:03:21 +02:00
|
|
|
$versionID = ($record) ? $record->Version : $versionID;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
|
2012-03-08 20:02:15 +01:00
|
|
|
// Respect permission failures from parent implementation
|
|
|
|
if(!($form instanceof Form)) return $form;
|
2011-08-19 02:32:31 +02:00
|
|
|
|
2012-12-04 05:02:54 +01:00
|
|
|
// TODO: move to the SilverStripeNavigator structure so the new preview can pick it up.
|
|
|
|
//$nav = new SilverStripeNavigatorItem_ArchiveLink($record);
|
2012-07-31 07:49:59 +02:00
|
|
|
|
2011-10-26 07:35:51 +02:00
|
|
|
$form->setActions(new FieldList(
|
2012-12-04 05:02:54 +01:00
|
|
|
$revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true)
|
2011-08-26 04:03:21 +02:00
|
|
|
));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$fields = $form->Fields();
|
|
|
|
$fields->removeByName("Status");
|
|
|
|
$fields->push(new HiddenField("ID"));
|
|
|
|
$fields->push(new HiddenField("Version"));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
|
|
|
$fields = $fields->makeReadonly();
|
|
|
|
|
2011-08-26 04:03:21 +02:00
|
|
|
if($compareID) {
|
2011-08-30 00:26:40 +02:00
|
|
|
$link = Controller::join_links(
|
2011-09-19 21:06:39 +02:00
|
|
|
$this->Link('show'),
|
2011-08-30 00:26:40 +02:00
|
|
|
$id
|
|
|
|
);
|
|
|
|
|
|
|
|
$view = _t('CMSPageHistoryController.VIEW',"view");
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2012-05-01 21:43:43 +02:00
|
|
|
$message = _t(
|
|
|
|
'CMSPageHistoryController.COMPARINGVERSION',
|
|
|
|
"Comparing versions {version1} and {version2}.",
|
|
|
|
array(
|
|
|
|
'version1' => sprintf('%s (<a href="%s">%s</a>)', $versionID, Controller::join_links($link, $versionID), $view),
|
|
|
|
'version2' => sprintf('%s (<a href="%s">%s</a>)', $compareID, Controller::join_links($link, $compareID), $view)
|
|
|
|
)
|
2011-08-26 04:03:21 +02:00
|
|
|
);
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-26 04:03:21 +02:00
|
|
|
$revert->setReadonly(true);
|
2013-05-07 06:04:24 +02:00
|
|
|
} else {
|
|
|
|
if($record->isLatestVersion()) {
|
|
|
|
$message = _t('CMSPageHistoryController.VIEWINGLATEST', 'Currently viewing the latest version.');
|
|
|
|
} else {
|
|
|
|
$message = _t(
|
|
|
|
'CMSPageHistoryController.VIEWINGVERSION',
|
|
|
|
"Currently viewing version {version}.",
|
|
|
|
array('version' => $versionID)
|
|
|
|
);
|
|
|
|
}
|
2011-08-26 04:03:21 +02:00
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Main',
|
2011-08-26 04:03:21 +02:00
|
|
|
new LiteralField('CurrentlyViewingMessage', $this->customise(array(
|
|
|
|
'Content' => $message,
|
|
|
|
'Classes' => 'notice'
|
|
|
|
))->renderWith(array('CMSMain_notice'))),
|
|
|
|
"Title"
|
|
|
|
);
|
|
|
|
|
|
|
|
$form->setFields($fields->makeReadonly());
|
2011-08-19 02:32:31 +02:00
|
|
|
$form->loadDataFrom(array(
|
|
|
|
"ID" => $id,
|
|
|
|
"Version" => $versionID,
|
|
|
|
));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-26 04:03:21 +02:00
|
|
|
if(($record && $record->isLatestVersion())) {
|
|
|
|
$revert->setReadonly(true);
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$form->removeExtraClass('cms-content');
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
2015-09-29 06:18:03 +02:00
|
|
|
* Version select form. Main interface between selecting versions to view
|
2011-08-26 04:03:21 +02:00
|
|
|
* and comparing multiple versions.
|
2015-09-29 06:18:03 +02:00
|
|
|
*
|
2011-08-26 04:03:21 +02:00
|
|
|
* Because we can reload the page directly to a compare view (history/compare/1/2/3)
|
2015-09-29 06:18:03 +02:00
|
|
|
* this form has to adapt to those parameters as well.
|
2011-08-26 04:03:21 +02:00
|
|
|
*
|
2011-08-19 02:32:31 +02:00
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function VersionsForm() {
|
2011-08-19 02:32:31 +02:00
|
|
|
$id = $this->currentPageID();
|
|
|
|
$page = $this->getRecord($id);
|
|
|
|
$versionsHtml = '';
|
|
|
|
|
2015-04-30 01:04:02 +02:00
|
|
|
$action = $this->getRequest()->param('Action');
|
|
|
|
$versionID = $this->getRequest()->param('VersionID');
|
|
|
|
$otherVersionID = $this->getRequest()->param('OtherVersionID');
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-26 04:03:21 +02:00
|
|
|
$showUnpublishedChecked = 0;
|
|
|
|
$compareModeChecked = ($action == "compare");
|
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if($page) {
|
|
|
|
$versions = $page->allVersions();
|
2011-08-30 02:36:02 +02:00
|
|
|
$versionID = (!$versionID) ? $page->Version : $versionID;
|
2011-08-30 04:33:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if($versions) {
|
|
|
|
foreach($versions as $k => $version) {
|
2011-08-26 04:03:21 +02:00
|
|
|
$active = false;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-26 04:03:21 +02:00
|
|
|
if($version->Version == $versionID || $version->Version == $otherVersionID) {
|
|
|
|
$active = true;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-30 04:33:03 +02:00
|
|
|
if(!$version->WasPublished) $showUnpublishedChecked = 1;
|
2011-08-26 04:03:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$version->Active = ($active);
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$vd = new ViewableData();
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$versionsHtml = $vd->customise(array(
|
|
|
|
'Versions' => $versions
|
|
|
|
))->renderWith('CMSPageHistoryController_versions');
|
|
|
|
}
|
2011-08-26 04:03:21 +02:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$fields = new FieldList(
|
|
|
|
new CheckboxField(
|
|
|
|
'ShowUnpublished',
|
|
|
|
_t('CMSPageHistoryController.SHOWUNPUBLISHED','Show unpublished versions'),
|
|
|
|
$showUnpublishedChecked
|
|
|
|
),
|
|
|
|
new CheckboxField(
|
|
|
|
'CompareMode',
|
|
|
|
_t('CMSPageHistoryController.COMPAREMODE', 'Compare mode (select two)'),
|
|
|
|
$compareModeChecked
|
|
|
|
),
|
|
|
|
new LiteralField('VersionsHtml', $versionsHtml),
|
|
|
|
$hiddenID = new HiddenField('ID', false, "")
|
|
|
|
);
|
|
|
|
|
|
|
|
$actions = new FieldList(
|
|
|
|
new FormAction(
|
|
|
|
'doCompare', _t('CMSPageHistoryController.COMPAREVERSIONS','Compare Versions')
|
|
|
|
),
|
|
|
|
new FormAction(
|
2015-09-29 06:18:03 +02:00
|
|
|
'doShowVersion', _t('CMSPageHistoryController.SHOWVERSION','Show Version')
|
2012-02-16 22:59:47 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Use <button> to allow full jQuery UI styling
|
|
|
|
foreach($actions->dataFields() as $action) $action->setUseButtonTag(true);
|
|
|
|
|
2015-09-29 06:18:03 +02:00
|
|
|
$form = CMSForm::create(
|
2011-08-19 02:32:31 +02:00
|
|
|
$this,
|
|
|
|
'VersionsForm',
|
2012-02-16 22:59:47 +01:00
|
|
|
$fields,
|
|
|
|
$actions
|
2013-05-10 15:00:57 +02:00
|
|
|
)->setHTMLID('Form_VersionsForm');
|
|
|
|
$form->setResponseNegotiator($this->getResponseNegotiator());
|
2015-04-30 01:04:02 +02:00
|
|
|
$form->loadDataFrom($this->getRequest()->requestVars());
|
2011-08-30 00:26:40 +02:00
|
|
|
$hiddenID->setValue($id);
|
2011-08-19 02:32:31 +02:00
|
|
|
$form->unsetValidator();
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2012-02-16 18:06:48 +01:00
|
|
|
$form
|
|
|
|
->addExtraClass('cms-versions-form') // placeholder, necessary for $.metadata() to work
|
|
|
|
->setAttribute('data-link-tmpl-compare', Controller::join_links($this->Link('compare'), '%s', '%s', '%s'))
|
|
|
|
->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s'));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
return $form;
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
|
|
|
* Process the {@link VersionsForm} compare function between two pages.
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
* @param Form
|
|
|
|
*
|
|
|
|
* @return html
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function doCompare($data, $form) {
|
2011-08-19 02:32:31 +02:00
|
|
|
$versions = $data['Versions'];
|
|
|
|
if(count($versions) < 2) return null;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$id = $this->currentPageID();
|
|
|
|
$version1 = array_shift($versions);
|
|
|
|
$version2 = array_shift($versions);
|
|
|
|
|
|
|
|
$form = $this->CompareVersionsForm($version1, $version2);
|
|
|
|
|
|
|
|
// javascript solution, render into template
|
2015-04-30 01:04:02 +02:00
|
|
|
if($this->getRequest()->isAjax()) {
|
2011-08-19 02:32:31 +02:00
|
|
|
return $this->customise(array(
|
|
|
|
"EditForm" => $form
|
|
|
|
))->renderWith(array(
|
2015-09-29 06:18:03 +02:00
|
|
|
$this->class . '_EditForm',
|
2011-08-19 02:32:31 +02:00
|
|
|
'LeftAndMain_Content'
|
|
|
|
));
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
// non javascript, redirect the user to the page
|
|
|
|
$this->redirect(Controller::join_links(
|
|
|
|
$this->Link('compare'),
|
|
|
|
$version1,
|
|
|
|
$version2
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the {@link VersionsForm} show version function. Only requires
|
|
|
|
* one page to be selected.
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
* @param Form
|
|
|
|
*
|
|
|
|
* @return html
|
2015-09-29 06:18:03 +02:00
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function doShowVersion($data, $form) {
|
2011-08-19 02:32:31 +02:00
|
|
|
$versionID = null;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
|
|
|
if(isset($data['Versions']) && is_array($data['Versions'])) {
|
2011-08-19 02:32:31 +02:00
|
|
|
$versionID = array_shift($data['Versions']);
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if(!$versionID) return;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2012-04-05 14:45:26 +02:00
|
|
|
if($request->isAjax()) {
|
2011-08-19 02:32:31 +02:00
|
|
|
return $this->customise(array(
|
|
|
|
"EditForm" => $this->ShowVersionForm($versionID)
|
|
|
|
))->renderWith(array(
|
2015-09-29 06:18:03 +02:00
|
|
|
$this->class . '_EditForm',
|
2011-08-19 02:32:31 +02:00
|
|
|
'LeftAndMain_Content'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// non javascript, redirect the user to the page
|
|
|
|
$this->redirect(Controller::join_links(
|
|
|
|
$this->Link('version'),
|
|
|
|
$versionID
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param int|null $versionID
|
2011-08-19 02:32:31 +02:00
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function ShowVersionForm($versionID = null) {
|
2011-08-19 02:32:31 +02:00
|
|
|
if(!$versionID) return null;
|
2011-08-26 04:03:21 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$id = $this->currentPageID();
|
|
|
|
$form = $this->getEditForm($id, null, $versionID);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param int $versionID
|
|
|
|
* @param int $otherVersionID
|
2011-08-19 02:32:31 +02:00
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function CompareVersionsForm($versionID, $otherVersionID) {
|
2011-08-19 02:32:31 +02:00
|
|
|
if($versionID > $otherVersionID) {
|
|
|
|
$toVersion = $versionID;
|
|
|
|
$fromVersion = $otherVersionID;
|
|
|
|
} else {
|
|
|
|
$toVersion = $otherVersionID;
|
|
|
|
$fromVersion = $versionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$toVersion || !$toVersion) return false;
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
$id = $this->currentPageID();
|
|
|
|
$page = DataObject::get_by_id("SiteTree", $id);
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
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);
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if(!$fromVersionRecord) {
|
|
|
|
user_error("Can't find version $fromVersion of page $id", E_USER_ERROR);
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if(!$toVersionRecord) {
|
|
|
|
user_error("Can't find version $toVersion of page $id", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($record) {
|
2011-08-26 04:03:21 +02:00
|
|
|
$form = $this->getEditForm($id, null, null, true);
|
2011-10-26 07:35:51 +02:00
|
|
|
$form->setActions(new FieldList());
|
2011-10-07 12:07:46 +02:00
|
|
|
$form->addExtraClass('compare');
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-10-07 12:07:46 +02:00
|
|
|
// Comparison views shouldn't be editable.
|
|
|
|
// Its important to convert fields *before* loading data,
|
|
|
|
// as the comparison output is HTML and not valid values for the various field types
|
|
|
|
$readonlyFields = $form->Fields()->makeReadonly();
|
|
|
|
$form->setFields($readonlyFields);
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-10-07 12:07:46 +02:00
|
|
|
$form->loadDataFrom($record);
|
2011-08-19 02:32:31 +02:00
|
|
|
$form->loadDataFrom(array(
|
|
|
|
"ID" => $id,
|
|
|
|
"Version" => $fromVersion,
|
|
|
|
));
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-10-07 12:07:46 +02:00
|
|
|
foreach($form->Fields()->dataFields() as $field) {
|
|
|
|
$field->dontEscape = true;
|
|
|
|
}
|
2015-09-29 06:18:03 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 11:52:39 +01:00
|
|
|
|
2012-11-29 14:43:05 +01:00
|
|
|
public function Breadcrumbs($unlinked = false) {
|
|
|
|
$crumbs = parent::Breadcrumbs($unlinked);
|
|
|
|
$crumbs[0]->Title = _t('CMSPagesController.MENUTITLE');
|
|
|
|
return $crumbs;
|
|
|
|
}
|
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|