mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Merge branch '3.3' into 3.4
This commit is contained in:
commit
4f99ced5df
@ -12,14 +12,14 @@ class CMSPageHistoryController extends CMSMain {
|
||||
private static $menu_title = 'History';
|
||||
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
||||
private static $session_namespace = 'CMSMain';
|
||||
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'VersionsForm',
|
||||
'CompareVersionsForm',
|
||||
'show',
|
||||
'compare'
|
||||
);
|
||||
|
||||
|
||||
private static $url_handlers = array(
|
||||
'$Action/$ID/$VersionID/$OtherVersionID' => 'handleAction'
|
||||
);
|
||||
@ -37,14 +37,14 @@ class CMSPageHistoryController extends CMSMain {
|
||||
});
|
||||
return $negotiator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return array
|
||||
*/
|
||||
public function show($request) {
|
||||
$form = $this->ShowVersionForm($request->param('VersionID'));
|
||||
|
||||
|
||||
$negotiator = $this->getResponseNegotiator();
|
||||
$controller = $this;
|
||||
$negotiator->setCallback('CurrentForm', function() use(&$controller, &$form) {
|
||||
@ -56,7 +56,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
|
||||
return $negotiator->respond($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return array
|
||||
@ -88,7 +88,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the read only version of the edit form. Detaches all {@link FormAction}
|
||||
* 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) {
|
||||
if(!$id) $id = $this->currentPageID();
|
||||
|
||||
|
||||
$record = $this->getRecord($id, $versionID);
|
||||
$versionID = ($record) ? $record->Version : $versionID;
|
||||
|
||||
|
||||
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
|
||||
// Respect permission failures from parent implementation
|
||||
if(!($form instanceof Form)) return $form;
|
||||
@ -118,14 +118,14 @@ class CMSPageHistoryController extends CMSMain {
|
||||
$form->setActions(new FieldList(
|
||||
$revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true)
|
||||
));
|
||||
|
||||
|
||||
$fields = $form->Fields();
|
||||
$fields->removeByName("Status");
|
||||
$fields->push(new HiddenField("ID"));
|
||||
$fields->push(new HiddenField("Version"));
|
||||
|
||||
$fields = $fields->makeReadonly();
|
||||
|
||||
|
||||
$fields = $fields->makeReadonly();
|
||||
|
||||
if($compareID) {
|
||||
$link = Controller::join_links(
|
||||
$this->Link('show'),
|
||||
@ -133,7 +133,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
);
|
||||
|
||||
$view = _t('CMSPageHistoryController.VIEW',"view");
|
||||
|
||||
|
||||
$message = _t(
|
||||
'CMSPageHistoryController.COMPARINGVERSION',
|
||||
"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)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$revert->setReadonly(true);
|
||||
} else {
|
||||
if($record->isLatestVersion()) {
|
||||
@ -155,7 +155,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$fields->addFieldToTab('Root.Main',
|
||||
new LiteralField('CurrentlyViewingMessage', $this->customise(array(
|
||||
'Content' => $message,
|
||||
@ -169,17 +169,17 @@ class CMSPageHistoryController extends CMSMain {
|
||||
"ID" => $id,
|
||||
"Version" => $versionID,
|
||||
));
|
||||
|
||||
|
||||
if(($record && $record->isLatestVersion())) {
|
||||
$revert->setReadonly(true);
|
||||
}
|
||||
|
||||
|
||||
$form->removeExtraClass('cms-content');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Version select form. Main interface between selecting versions to view
|
||||
* and comparing multiple versions.
|
||||
@ -197,7 +197,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
$action = $this->getRequest()->param('Action');
|
||||
$versionID = $this->getRequest()->param('VersionID');
|
||||
$otherVersionID = $this->getRequest()->param('OtherVersionID');
|
||||
|
||||
|
||||
$showUnpublishedChecked = 0;
|
||||
$compareModeChecked = ($action == "compare");
|
||||
|
||||
@ -208,19 +208,19 @@ class CMSPageHistoryController extends CMSMain {
|
||||
if($versions) {
|
||||
foreach($versions as $k => $version) {
|
||||
$active = false;
|
||||
|
||||
|
||||
if($version->Version == $versionID || $version->Version == $otherVersionID) {
|
||||
$active = true;
|
||||
|
||||
|
||||
if(!$version->WasPublished) $showUnpublishedChecked = 1;
|
||||
}
|
||||
|
||||
$version->Active = ($active);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$vd = new ViewableData();
|
||||
|
||||
|
||||
$versionsHtml = $vd->customise(array(
|
||||
'Versions' => $versions
|
||||
))->renderWith('CMSPageHistoryController_versions');
|
||||
@ -263,15 +263,15 @@ class CMSPageHistoryController extends CMSMain {
|
||||
$form->loadDataFrom($this->getRequest()->requestVars());
|
||||
$hiddenID->setValue($id);
|
||||
$form->unsetValidator();
|
||||
|
||||
|
||||
$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'));
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the {@link VersionsForm} compare function between two pages.
|
||||
*
|
||||
@ -283,7 +283,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
public function doCompare($data, $form) {
|
||||
$versions = $data['Versions'];
|
||||
if(count($versions) < 2) return null;
|
||||
|
||||
|
||||
$id = $this->currentPageID();
|
||||
$version1 = array_shift($versions);
|
||||
$version2 = array_shift($versions);
|
||||
@ -299,7 +299,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
'LeftAndMain_Content'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
// non javascript, redirect the user to the page
|
||||
$this->redirect(Controller::join_links(
|
||||
$this->Link('compare'),
|
||||
@ -316,16 +316,16 @@ class CMSPageHistoryController extends CMSMain {
|
||||
* @param Form
|
||||
*
|
||||
* @return html
|
||||
*/
|
||||
*/
|
||||
public function doShowVersion($data, $form) {
|
||||
$versionID = null;
|
||||
|
||||
|
||||
if(isset($data['Versions']) && is_array($data['Versions'])) {
|
||||
$versionID = array_shift($data['Versions']);
|
||||
}
|
||||
|
||||
|
||||
if(!$versionID) return;
|
||||
|
||||
|
||||
if($request->isAjax()) {
|
||||
return $this->customise(array(
|
||||
"EditForm" => $this->ShowVersionForm($versionID)
|
||||
@ -354,11 +354,11 @@ class CMSPageHistoryController extends CMSMain {
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $versionID
|
||||
* @param int $otherVersionID
|
||||
* @return Form
|
||||
* @return mixed
|
||||
*/
|
||||
public function CompareVersionsForm($versionID, $otherVersionID) {
|
||||
if($versionID > $otherVersionID) {
|
||||
@ -369,51 +369,57 @@ class CMSPageHistoryController extends CMSMain {
|
||||
$fromVersion = $versionID;
|
||||
}
|
||||
|
||||
if(!$toVersion || !$fromVersion) return false;
|
||||
|
||||
$id = $this->currentPageID();
|
||||
$page = DataObject::get_by_id("SiteTree", $id);
|
||||
|
||||
if($page && !$page->canView()) {
|
||||
return Security::permissionFailure($this);
|
||||
if(!$toVersion || !$toVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$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);
|
||||
$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) {
|
||||
if(isset($record)) {
|
||||
$form = $this->getEditForm($id, null, null, true);
|
||||
$form->setActions(new FieldList());
|
||||
$form->addExtraClass('compare');
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
$form->loadDataFrom($record);
|
||||
$form->loadDataFrom(array(
|
||||
"ID" => $id,
|
||||
"Version" => $fromVersion,
|
||||
));
|
||||
|
||||
|
||||
foreach($form->Fields()->dataFields() as $field) {
|
||||
$field->dontEscape = true;
|
||||
}
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function Breadcrumbs($unlinked = false) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user