'handleAction'
);
/**
* @return array
*/
function show($request) {
$form = $this->ShowVersionForm($request->param('VersionID'));
if($this->isAjax()) {
if($form) $content = $form->forTemplate();
else $content = $this->renderWith($this->getTemplatesWithSuffix('_Content'));
} else {
$content = $this->customise(array('EditForm' => $form))->renderWith($this->getViewer('show'));
}
return $content;
}
/**
* @return array
*/
function compare($request) {
$form = $this->CompareVersionsForm(
$request->param('VersionID'),
$request->param('OtherVersionID')
);
if($this->isAjax()) {
$content = $form->forTemplate();
} else {
$content = $this->customise(array('EditForm' => $form))->renderWith($this->getViewer('show'));
}
return $content;
}
/**
* @return array
*/
function rollback() {
return $this->doRollback(array(
'ID' => $this->currentPageID(),
'Version' => $this->request->param('VersionID')
), null);
}
/**
* Returns the read only version of the edit form. Detaches all {@link FormAction}
* instances attached since only action relates to revert.
*
* Permission checking is done at the {@link CMSMain::getEditForm()} level.
*
* @param int $id ID of the record to show
* @param array $fields optional
* @param int $versionID
* @param int $compare Compare mode
*
* @return Form
*/
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);
$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();
foreach($fields->dataFields() as $field) {
$field->dontEscape = true;
$field->reserveNL = true;
}
if($compareID) {
$link = Controller::join_links(
$this->Link('show'),
$id
);
$view = _t('CMSPageHistoryController.VIEW',"view");
$message = sprintf(
_t('CMSPageHistoryController.COMPARINGVERSION',"Comparing versions %s and %s."),
sprintf('%s (%s)', $versionID, Controller::join_links($link, $versionID), $view),
sprintf('%s (%s)', $compareID, Controller::join_links($link, $compareID), $view)
);
$revert->setReadonly(true);
}
else {
$message = sprintf(
_t('CMSPageHistoryController.VIEWINGVERSION',"Currently viewing version %s."), $versionID
);
}
$fields->addFieldToTab('Root.Main',
new LiteralField('CurrentlyViewingMessage', $this->customise(array(
'Content' => $message,
'Classes' => 'notice'
))->renderWith(array('CMSMain_notice'))),
"Title"
);
$form->setFields($fields->makeReadonly());
$form->loadDataFrom(array(
"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.
*
* Because we can reload the page directly to a compare view (history/compare/1/2/3)
* this form has to adapt to those parameters as well.
*
* @return Form
*/
function VersionsForm() {
$id = $this->currentPageID();
$page = $this->getRecord($id);
$versionsHtml = '';
$action = $this->request->param('Action');
$versionID = $this->request->param('VersionID');
$otherVersionID = $this->request->param('OtherVersionID');
$showUnpublishedChecked = 0;
$compareModeChecked = ($action == "compare");
if($page) {
$versions = $page->allVersions();
$versionID = (!$versionID) ? $page->Version : $versionID;
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');
}
$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(
'doShowVersion', _t('CMSPageHistoryController.SHOWVERSION','Show Version')
)
);
// Use