Merge branch '3.3' into 3.4

This commit is contained in:
Daniel Hensby 2016-07-25 14:12:31 +01:00
commit 4f99ced5df
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -12,14 +12,14 @@ class CMSPageHistoryController extends CMSMain {
private static $menu_title = 'History'; private static $menu_title = 'History';
private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
private static $session_namespace = 'CMSMain'; private static $session_namespace = 'CMSMain';
private static $allowed_actions = array( private static $allowed_actions = array(
'VersionsForm', 'VersionsForm',
'CompareVersionsForm', 'CompareVersionsForm',
'show', 'show',
'compare' 'compare'
); );
private static $url_handlers = array( private static $url_handlers = array(
'$Action/$ID/$VersionID/$OtherVersionID' => 'handleAction' '$Action/$ID/$VersionID/$OtherVersionID' => 'handleAction'
); );
@ -37,14 +37,14 @@ class CMSPageHistoryController extends CMSMain {
}); });
return $negotiator; return $negotiator;
} }
/** /**
* @param SS_HTTPRequest $request * @param SS_HTTPRequest $request
* @return array * @return array
*/ */
public function show($request) { public function show($request) {
$form = $this->ShowVersionForm($request->param('VersionID')); $form = $this->ShowVersionForm($request->param('VersionID'));
$negotiator = $this->getResponseNegotiator(); $negotiator = $this->getResponseNegotiator();
$controller = $this; $controller = $this;
$negotiator->setCallback('CurrentForm', function() use(&$controller, &$form) { $negotiator->setCallback('CurrentForm', function() use(&$controller, &$form) {
@ -56,7 +56,7 @@ class CMSPageHistoryController extends CMSMain {
return $negotiator->respond($request); return $negotiator->respond($request);
} }
/** /**
* @param SS_HTTPRequest $request * @param SS_HTTPRequest $request
* @return array * @return array
@ -88,7 +88,7 @@ class CMSPageHistoryController extends CMSMain {
return false; return false;
} }
} }
/** /**
* Returns the read only version of the edit form. Detaches all {@link FormAction} * Returns the read only version of the edit form. Detaches all {@link FormAction}
* instances attached since only action relates to revert. * instances attached since only action relates to revert.
@ -104,10 +104,10 @@ class CMSPageHistoryController extends CMSMain {
*/ */
public function getEditForm($id = null, $fields = null, $versionID = null, $compareID = null) { public function getEditForm($id = null, $fields = null, $versionID = null, $compareID = null) {
if(!$id) $id = $this->currentPageID(); if(!$id) $id = $this->currentPageID();
$record = $this->getRecord($id, $versionID); $record = $this->getRecord($id, $versionID);
$versionID = ($record) ? $record->Version : $versionID; $versionID = ($record) ? $record->Version : $versionID;
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
// Respect permission failures from parent implementation // Respect permission failures from parent implementation
if(!($form instanceof Form)) return $form; if(!($form instanceof Form)) return $form;
@ -118,14 +118,14 @@ class CMSPageHistoryController extends CMSMain {
$form->setActions(new FieldList( $form->setActions(new FieldList(
$revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true) $revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true)
)); ));
$fields = $form->Fields(); $fields = $form->Fields();
$fields->removeByName("Status"); $fields->removeByName("Status");
$fields->push(new HiddenField("ID")); $fields->push(new HiddenField("ID"));
$fields->push(new HiddenField("Version")); $fields->push(new HiddenField("Version"));
$fields = $fields->makeReadonly(); $fields = $fields->makeReadonly();
if($compareID) { if($compareID) {
$link = Controller::join_links( $link = Controller::join_links(
$this->Link('show'), $this->Link('show'),
@ -133,7 +133,7 @@ class CMSPageHistoryController extends CMSMain {
); );
$view = _t('CMSPageHistoryController.VIEW',"view"); $view = _t('CMSPageHistoryController.VIEW',"view");
$message = _t( $message = _t(
'CMSPageHistoryController.COMPARINGVERSION', 'CMSPageHistoryController.COMPARINGVERSION',
"Comparing versions {version1} and {version2}.", "Comparing versions {version1} and {version2}.",
@ -142,7 +142,7 @@ class CMSPageHistoryController extends CMSMain {
'version2' => sprintf('%s (<a href="%s">%s</a>)', $compareID, Controller::join_links($link, $compareID), $view) 'version2' => sprintf('%s (<a href="%s">%s</a>)', $compareID, Controller::join_links($link, $compareID), $view)
) )
); );
$revert->setReadonly(true); $revert->setReadonly(true);
} else { } else {
if($record->isLatestVersion()) { if($record->isLatestVersion()) {
@ -155,7 +155,7 @@ class CMSPageHistoryController extends CMSMain {
); );
} }
} }
$fields->addFieldToTab('Root.Main', $fields->addFieldToTab('Root.Main',
new LiteralField('CurrentlyViewingMessage', $this->customise(array( new LiteralField('CurrentlyViewingMessage', $this->customise(array(
'Content' => $message, 'Content' => $message,
@ -169,17 +169,17 @@ class CMSPageHistoryController extends CMSMain {
"ID" => $id, "ID" => $id,
"Version" => $versionID, "Version" => $versionID,
)); ));
if(($record && $record->isLatestVersion())) { if(($record && $record->isLatestVersion())) {
$revert->setReadonly(true); $revert->setReadonly(true);
} }
$form->removeExtraClass('cms-content'); $form->removeExtraClass('cms-content');
return $form; return $form;
} }
/** /**
* Version select form. Main interface between selecting versions to view * Version select form. Main interface between selecting versions to view
* and comparing multiple versions. * and comparing multiple versions.
@ -197,7 +197,7 @@ class CMSPageHistoryController extends CMSMain {
$action = $this->getRequest()->param('Action'); $action = $this->getRequest()->param('Action');
$versionID = $this->getRequest()->param('VersionID'); $versionID = $this->getRequest()->param('VersionID');
$otherVersionID = $this->getRequest()->param('OtherVersionID'); $otherVersionID = $this->getRequest()->param('OtherVersionID');
$showUnpublishedChecked = 0; $showUnpublishedChecked = 0;
$compareModeChecked = ($action == "compare"); $compareModeChecked = ($action == "compare");
@ -208,19 +208,19 @@ class CMSPageHistoryController extends CMSMain {
if($versions) { if($versions) {
foreach($versions as $k => $version) { foreach($versions as $k => $version) {
$active = false; $active = false;
if($version->Version == $versionID || $version->Version == $otherVersionID) { if($version->Version == $versionID || $version->Version == $otherVersionID) {
$active = true; $active = true;
if(!$version->WasPublished) $showUnpublishedChecked = 1; if(!$version->WasPublished) $showUnpublishedChecked = 1;
} }
$version->Active = ($active); $version->Active = ($active);
} }
} }
$vd = new ViewableData(); $vd = new ViewableData();
$versionsHtml = $vd->customise(array( $versionsHtml = $vd->customise(array(
'Versions' => $versions 'Versions' => $versions
))->renderWith('CMSPageHistoryController_versions'); ))->renderWith('CMSPageHistoryController_versions');
@ -263,15 +263,15 @@ class CMSPageHistoryController extends CMSMain {
$form->loadDataFrom($this->getRequest()->requestVars()); $form->loadDataFrom($this->getRequest()->requestVars());
$hiddenID->setValue($id); $hiddenID->setValue($id);
$form->unsetValidator(); $form->unsetValidator();
$form $form
->addExtraClass('cms-versions-form') // placeholder, necessary for $.metadata() to work ->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-compare', Controller::join_links($this->Link('compare'), '%s', '%s', '%s'))
->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s')); ->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s'));
return $form; return $form;
} }
/** /**
* Process the {@link VersionsForm} compare function between two pages. * Process the {@link VersionsForm} compare function between two pages.
* *
@ -283,7 +283,7 @@ class CMSPageHistoryController extends CMSMain {
public function doCompare($data, $form) { public function doCompare($data, $form) {
$versions = $data['Versions']; $versions = $data['Versions'];
if(count($versions) < 2) return null; if(count($versions) < 2) return null;
$id = $this->currentPageID(); $id = $this->currentPageID();
$version1 = array_shift($versions); $version1 = array_shift($versions);
$version2 = array_shift($versions); $version2 = array_shift($versions);
@ -299,7 +299,7 @@ class CMSPageHistoryController extends CMSMain {
'LeftAndMain_Content' 'LeftAndMain_Content'
)); ));
} }
// non javascript, redirect the user to the page // non javascript, redirect the user to the page
$this->redirect(Controller::join_links( $this->redirect(Controller::join_links(
$this->Link('compare'), $this->Link('compare'),
@ -316,16 +316,16 @@ class CMSPageHistoryController extends CMSMain {
* @param Form * @param Form
* *
* @return html * @return html
*/ */
public function doShowVersion($data, $form) { public function doShowVersion($data, $form) {
$versionID = null; $versionID = null;
if(isset($data['Versions']) && is_array($data['Versions'])) { if(isset($data['Versions']) && is_array($data['Versions'])) {
$versionID = array_shift($data['Versions']); $versionID = array_shift($data['Versions']);
} }
if(!$versionID) return; if(!$versionID) return;
if($request->isAjax()) { if($request->isAjax()) {
return $this->customise(array( return $this->customise(array(
"EditForm" => $this->ShowVersionForm($versionID) "EditForm" => $this->ShowVersionForm($versionID)
@ -354,11 +354,11 @@ class CMSPageHistoryController extends CMSMain {
return $form; return $form;
} }
/** /**
* @param int $versionID * @param int $versionID
* @param int $otherVersionID * @param int $otherVersionID
* @return Form * @return mixed
*/ */
public function CompareVersionsForm($versionID, $otherVersionID) { public function CompareVersionsForm($versionID, $otherVersionID) {
if($versionID > $otherVersionID) { if($versionID > $otherVersionID) {
@ -369,51 +369,57 @@ class CMSPageHistoryController extends CMSMain {
$fromVersion = $versionID; $fromVersion = $versionID;
} }
if(!$toVersion || !$fromVersion) return false; if(!$toVersion || !$toVersion) {
return false;
$id = $this->currentPageID();
$page = DataObject::get_by_id("SiteTree", $id);
if($page && !$page->canView()) {
return Security::permissionFailure($this);
} }
$record = $page->compareVersions($fromVersion, $toVersion); $id = $this->currentPageID();
$page = DataObject::get_by_id("SiteTree", $id);
if($page && $page->exists()) {
if(!$page->canView()) {
return Security::permissionFailure($this);
}
$record = $page->compareVersions($fromVersion, $toVersion);
}
$fromVersionRecord = Versioned::get_version('SiteTree', $id, $fromVersion); $fromVersionRecord = Versioned::get_version('SiteTree', $id, $fromVersion);
$toVersionRecord = Versioned::get_version('SiteTree', $id, $toVersion); $toVersionRecord = Versioned::get_version('SiteTree', $id, $toVersion);
if(!$fromVersionRecord) { if(!$fromVersionRecord) {
user_error("Can't find version $fromVersion of page $id", E_USER_ERROR); user_error("Can't find version $fromVersion of page $id", E_USER_ERROR);
} }
if(!$toVersionRecord) { if(!$toVersionRecord) {
user_error("Can't find version $toVersion of page $id", E_USER_ERROR); user_error("Can't find version $toVersion of page $id", E_USER_ERROR);
} }
if($record) { if(isset($record)) {
$form = $this->getEditForm($id, null, null, true); $form = $this->getEditForm($id, null, null, true);
$form->setActions(new FieldList()); $form->setActions(new FieldList());
$form->addExtraClass('compare'); $form->addExtraClass('compare');
// Comparison views shouldn't be editable. // Comparison views shouldn't be editable.
// Its important to convert fields *before* loading data, // Its important to convert fields *before* loading data,
// as the comparison output is HTML and not valid values for the various field types // as the comparison output is HTML and not valid values for the various field types
$readonlyFields = $form->Fields()->makeReadonly(); $readonlyFields = $form->Fields()->makeReadonly();
$form->setFields($readonlyFields); $form->setFields($readonlyFields);
$form->loadDataFrom($record); $form->loadDataFrom($record);
$form->loadDataFrom(array( $form->loadDataFrom(array(
"ID" => $id, "ID" => $id,
"Version" => $fromVersion, "Version" => $fromVersion,
)); ));
foreach($form->Fields()->dataFields() as $field) { foreach($form->Fields()->dataFields() as $field) {
$field->dontEscape = true; $field->dontEscape = true;
} }
return $form; return $form;
} }
return false;
} }
public function Breadcrumbs($unlinked = false) { public function Breadcrumbs($unlinked = false) {