Fix regressions from namespacing

Update template locations
Add permission codes to cms sections
Code, phpdoc, and typehint cleanup
Split batch actions into files
This commit is contained in:
Damian Mooyman 2016-08-11 14:10:51 +12:00
parent 2352127fe0
commit 041d12129a
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
33 changed files with 335 additions and 247 deletions

View File

@ -25,5 +25,3 @@ CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageEditControlle
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageSettingsController');
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageHistoryController');
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageAddController');
CMSMenu::remove_menu_item("SiteConfigLeftAndMain");

View File

@ -1,2 +1,2 @@
AdminRootController:
SilverStripe\Admin\AdminRootController:
default_panel: 'SilverStripe\CMS\Controllers\CMSPagesController'

View File

@ -1,4 +1,4 @@
LeftAndMain:
SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\CMS\Controllers\LeftAndMainPageIconsExtension
Controller:

View File

@ -3,4 +3,4 @@ Name: cmslegacy
---
SilverStripe\ORM\DatabaseAdmin:
classname_value_remapping:
SiteTree: 'SilverStripe\CMS\Model\SiteTree'
SiteTree: 'SilverStripe\CMS\Model\SiteTree'

View File

@ -0,0 +1,34 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\ORM\SS_List;
/**
* Archives a page, removing it from both live and stage
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Archive extends CMSBatchAction
{
public function getActionTitle()
{
return _t('CMSBatchActions.ARCHIVE', 'Archive');
}
public function run(SS_List $pages)
{
return $this->batchaction($pages, 'doArchive',
_t('CMSBatchActions.ARCHIVED_PAGES', 'Archived %d pages')
);
}
public function applicablePages($ids)
{
return $this->applicablePagesHelper($ids, 'canArchive', true, true);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Admin\CMSBatchAction;
/**
* Delete items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Delete extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.DELETE_DRAFT_PAGES', 'Delete from draft site');
}
public function run(SS_List $pages) {
$status = array(
'modified'=>array(),
'deleted'=>array(),
'error'=>array()
);
foreach($pages as $page) {
$id = $page->ID;
// Perform the action
if($page->canDelete()) $page->delete();
else $status['error'][$page->ID] = true;
// check to see if the record exists on the live site,
// if it doesn't remove the tree node
$liveRecord = Versioned::get_one_by_stage( 'SilverStripe\\CMS\\Model\\SiteTree', 'Live', array(
'"SiteTree"."ID"' => $id
));
if($liveRecord) {
$status['modified'][$liveRecord->ID] = array(
'TreeTitle' => $liveRecord->TreeTitle,
);
} else {
$status['deleted'][$id] = array();
}
}
return $this->response(_t('CMSBatchActions.DELETED_DRAFT_PAGES', 'Deleted %d pages from draft site, %d failures'), $status);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canDelete', true, false);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\ORM\SS_List;
/**
* Publish items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Publish extends CMSBatchAction
{
public function getActionTitle()
{
return _t('CMSBatchActions.PUBLISH_PAGES', 'Publish');
}
public function run(SS_List $pages)
{
return $this->batchaction($pages, 'publishRecursive',
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
);
}
public function applicablePages($ids)
{
return $this->applicablePagesHelper($ids, 'canPublish', true, false);
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Security\Permission;
/**
* Batch restore of pages
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Restore extends CMSBatchAction
{
public function getActionTitle()
{
return _t('CMSBatchActions.RESTORE', 'Restore');
}
public function run(SS_List $pages)
{
// Sort pages by depth
$pageArray = $pages->toArray();
// because of https://bugs.php.net/bug.php?id=50688
/** @var SiteTree $page */
foreach ($pageArray as $page) {
$page->getPageLevel();
}
usort($pageArray, function (SiteTree $a, SiteTree $b) {
return $a->getPageLevel() - $b->getPageLevel();
});
$pages = new ArrayList($pageArray);
// Restore
return $this->batchaction($pages, 'doRestoreToStage',
_t('CMSBatchActions.RESTORED_PAGES', 'Restored %d pages')
);
}
/**
* {@see SiteTree::canEdit()}
*
* @param array $ids
* @return array
*/
public function applicablePages($ids)
{
// Basic permission check based on SiteTree::canEdit
if (!Permission::check(array("ADMIN", "SITETREE_EDIT_ALL"))) {
return array();
}
// Get pages that exist in stage and remove them from the restore-able set
$stageIDs = Versioned::get_by_stage($this->managedClass, 'Stage')->column('ID');
return array_values(array_diff($ids, $stageIDs));
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\ORM\SS_List;
/**
* Unpublish items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Unpublish extends CMSBatchAction
{
public function getActionTitle()
{
return _t('CMSBatchActions.UNPUBLISH_PAGES', 'Unpublish');
}
public function run(SS_List $pages)
{
return $this->batchaction($pages, 'doUnpublish',
_t('CMSBatchActions.UNPUBLISHED_PAGES', 'Unpublished %d pages')
);
}
public function applicablePages($ids)
{
return $this->applicablePagesHelper($ids, 'canUnpublish', false, true);
}
}

View File

@ -1,175 +0,0 @@
<?php
namespace SilverStripe\CMS\BatchActions;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Security\Permission;
use SilverStripe\Admin\CMSBatchAction;
/**
* Publish items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Publish extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.PUBLISH_PAGES', 'Publish');
}
public function run(SS_List $pages) {
return $this->batchaction($pages, 'publishRecursive',
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canPublish', true, false);
}
}
/**
* Unpublish items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Unpublish extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.UNPUBLISH_PAGES', 'Unpublish');
}
public function run(SS_List $pages) {
return $this->batchaction($pages, 'doUnpublish',
_t('CMSBatchActions.UNPUBLISHED_PAGES', 'Unpublished %d pages')
);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canUnpublish', false, true);
}
}
/**
* Archives a page, removing it from both live and stage
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Archive extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.ARCHIVE', 'Archive');
}
public function run(SS_List $pages) {
return $this->batchaction($pages, 'doArchive',
_t('CMSBatchActions.ARCHIVED_PAGES', 'Archived %d pages')
);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canArchive', true, true);
}
}
/**
* Batch restore of pages
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Restore extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.RESTORE', 'Restore');
}
public function run(SS_List $pages) {
// Sort pages by depth
$pageArray = $pages->toArray();
// because of https://bugs.php.net/bug.php?id=50688
foreach($pageArray as $page) {
$page->getPageLevel();
}
usort($pageArray, function($a, $b) {
return $a->getPageLevel() - $b->getPageLevel();
});
$pages = new ArrayList($pageArray);
// Restore
return $this->batchaction($pages, 'doRestoreToStage',
_t('CMSBatchActions.RESTORED_PAGES', 'Restored %d pages')
);
}
/**
* {@see SiteTree::canEdit()}
*
* @param array $ids
* @return bool
*/
public function applicablePages($ids) {
// Basic permission check based on SiteTree::canEdit
if(!Permission::check(array("ADMIN", "SITETREE_EDIT_ALL"))) {
return array();
}
// Get pages that exist in stage and remove them from the restore-able set
$stageIDs = Versioned::get_by_stage($this->managedClass, 'Stage')->column('ID');
return array_values(array_diff($ids, $stageIDs));
}
}
/**
* Delete items batch action.
*
* @package cms
* @subpackage batchaction
*/
class CMSBatchAction_Delete extends CMSBatchAction {
public function getActionTitle() {
return _t('CMSBatchActions.DELETE_DRAFT_PAGES', 'Delete from draft site');
}
public function run(SS_List $pages) {
$status = array(
'modified'=>array(),
'deleted'=>array(),
'error'=>array()
);
foreach($pages as $page) {
$id = $page->ID;
// Perform the action
if($page->canDelete()) $page->delete();
else $status['error'][$page->ID] = true;
// check to see if the record exists on the live site,
// if it doesn't remove the tree node
$liveRecord = Versioned::get_one_by_stage( 'SilverStripe\\CMS\\Model\\SiteTree', 'Live', array(
'"SiteTree"."ID"' => $id
));
if($liveRecord) {
$status['modified'][$liveRecord->ID] = array(
'TreeTitle' => $liveRecord->TreeTitle,
);
} else {
$status['deleted'][$id] = array();
}
}
return $this->response(_t('CMSBatchActions.DELETED_DRAFT_PAGES', 'Deleted %d pages from draft site, %d failures'), $status);
}
public function applicablePages($ids) {
return $this->applicablePagesHelper($ids, 'canDelete', true, false);
}
}

View File

@ -2,16 +2,22 @@
namespace SilverStripe\CMS\Controllers;
use SearchContext;
use SearchFilter;
use SilverStripe\Filesystem\Storage\AssetNameGenerator;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Security;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Admin\CMSBatchAction;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\LeftAndMain;
use Session;
use Requirements;
use CMSBatchActionHandler;
use File;
use DateField;
use HiddenField;
@ -28,6 +34,7 @@ use GridFieldLevelup;
use GridField;
use Controller;
use LiteralField;
use SS_HTTPRequest;
use TabSet;
use Tab;
use CompositeField;
@ -49,10 +56,6 @@ use Folder;
use Injector;
use Director;
use ArrayData;
use CMSBatchAction;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\CMSBatchAction;
@ -97,6 +100,8 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
'getsubtree'
);
private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
/**
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
*/
@ -139,6 +144,7 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
// Overwrite name filter to search both Name and Title attributes
$context->removeFilterByName('Name');
$params = $this->getRequest()->requestVar('q');
/** @var DataList $list */
$list = $context->getResults($params);
// Don't filter list when a detail view is requested,
@ -219,6 +225,7 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
);
$gridField = GridField::create('File', $title, $this->getList(), $gridFieldConfig);
/** @var GridFieldDataColumns $columns */
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array(
'StripThumbnail' => '',
@ -256,14 +263,14 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
// Move existing fields to a "details" tab, unless they've already been tabbed out through extensions.
// Required to keep Folder->getCMSFields() simple and reuseable,
// without any dependencies into AssetAdmin (e.g. useful for "add folder" views).
if(!$fields->hasTabset()) {
if(!$fields->hasTabSet()) {
$tabs = new TabSet('Root',
$tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')),
$tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))
);
$tabList->addExtraClass("content-listview cms-tabset-icon list");
$tabTree->addExtraClass("content-treeview cms-tabset-icon tree");
if($fields->Count() && $folder && $folder->isInDB()) {
if($fields->count() && $folder && $folder->isInDB()) {
$tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details')));
$tabDetails->addExtraClass("content-galleryview cms-tabset-icon edit");
foreach($fields as $field) {
@ -373,6 +380,10 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
return $form;
}
/**
* @param SS_HTTPRequest $request
* @return DBHTMLText
*/
public function addfolder($request) {
$obj = $this->customise(array(
'EditForm' => $this->AddForm()
@ -413,12 +424,14 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
* @return SearchContext
*/
public function getSearchContext() {
$context = singleton('File')->getDefaultSearchContext();
$context = File::singleton()->getDefaultSearchContext();
// Namespace fields, for easier detection if a search is present
/** @var FormField $field */
foreach($context->getFields() as $field) {
$field->setName(sprintf('q[%s]', $field->getName()));
}
/** @var SearchFilter $filter */
foreach($context->getFilters() as $filter) {
$filter->setFullName(sprintf('q[%s]', $filter->getFullName()));
}
@ -529,6 +542,10 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
* Add a new group and return its details suitable for ajax.
*
* @todo Move logic into Folder class, and use LeftAndMain->doAdd() default implementation.
*
* @param array $data
* @param Form $form
* @return SS_HTTPResponse|string
*/
public function doAdd($data, $form) {
$class = $this->stat('tree_class');
@ -539,6 +556,7 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
}
// check addchildren permissions
/** @var File $parentRecord */
if(
singleton($class)->hasExtension('SilverStripe\ORM\Hierarchy\Hierarchy')
&& isset($data['ParentID'])

View File

@ -2,8 +2,9 @@
namespace SilverStripe\CMS\Controllers;
use FormField;
use Injector;
use ResetFormAction;
use SilverStripe\Admin\CMSPreviewable;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\Versioning\Versioned;
@ -17,36 +18,33 @@ use SilverStripe\Security\Security;
use SilverStripe\Security\SecurityToken;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\AddToCampaignHandler;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\CMSPreviewable;
use SilverStripe\Admin\AddToCampaignHandler;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\CurrentPageIdentifier;
use SS_HTTPRequest;
use TabSet;
use Translatable;
use Requirements;
use CMSBatchActionHandler;
use Controller;
use AdminRootController;
use Director;
use Page;
use TextField;
use HeaderField;
use DateField;
use DropdownField;
use FieldGroup;
use FieldList;
use FormAction;
use Object;
use Form;
use SS_Cache;
use Zend_Cache;
use Convert;
use ArrayData;
use HiddenField;
use CMSPreviewable;
use LiteralField;
use RequiredFields;
use LabelField;
@ -59,16 +57,7 @@ use GridFieldLevelup;
use GridField;
use SS_HTTPResponse_Exception;
use Session;
use AddToCampaignHandler;
use HTMLEditorField;
use SS_HTTPResponse;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\CurrentPageIdentifier;
/**
* The main "content" area of the CMS.
@ -79,6 +68,8 @@ use SilverStripe\CMS\Model\CurrentPageIdentifier;
* @package cms
* @subpackage controller
* @todo Create some base classes to contain the generic functionality that will be replicated.
*
* @mixin LeftAndMainPageIconsExtension
*/
class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionProvider {
@ -100,6 +91,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
private static $session_namespace = 'SilverStripe\\CMS\\Controllers\\CMSMain';
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
/**
* Amount of results showing on a single page.
*
@ -176,7 +169,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function index($request) {
// In case we're not showing a specific record, explicitly remove any session state,
// to avoid it being highlighted in the tree, and causing an edit form to show.
if(!$request->param('Action')) $this->setCurrentPageId(null);
if(!$request->param('Action')) {
$this->setCurrentPageID(null);
}
return parent::index($request);
}
@ -203,6 +198,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
/**
* Overloads the LeftAndMain::ShowView. Allows to pass a page as a parameter, so we are able
* to switch view also for archived versions.
*
* @param SiteTree $page
* @return array
*/
public function SwitchView($page = null) {
if(!$page) {
@ -230,7 +228,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function Link($action = null) {
$link = Controller::join_links(
AdminRootController::admin_url(),
$this->stat('url_segment', true), // in case we want to change the segment
$this->stat('url_segment'), // in case we want to change the segment
'/', // trailing slash needed if $action is null!
"$action"
);
@ -404,7 +402,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$dateFrom,
$dateTo
);
$dateGroup->setTitle('Last Edited', _t('CMSSearch.PAGEFILTERDATEHEADING', 'Last edited'));
$dateGroup->setTitle(_t('CMSSearch.PAGEFILTERDATEHEADING', 'Last edited'));
// Create the Field list
$fields = new FieldList(
@ -422,6 +420,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
// Use <button> to allow full jQuery UI styling on the all of the Actions
/** @var FormAction $action */
foreach($actions->dataFields() as $action) {
/** @var FormAction $action */
$action->setUseButtonTag(true);
@ -486,7 +485,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
* @return string Serialized JSON
*/
public function SiteTreeHints() {
$json = '';
$classes = SiteTree::page_type_classes();
$cacheCanCreate = array();
@ -495,7 +493,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Generate basic cache key. Too complex to encompass all variations
$cache = SS_Cache::factory('CMSMain_SiteTreeHints');
$cacheKey = md5(implode('_', array(Member::currentUserID(), implode(',', $cacheCanCreate), implode(',', $classes))));
if($this->getRequest()->getVar('flush')) $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
if($this->getRequest()->getVar('flush')) {
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
}
$json = $cache->load($cacheKey);
if(!$json) {
$def['Root'] = array();
@ -710,7 +710,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$actions = $record->getCMSActions();
// Find and remove action menus that have no actions.
if ($actions && $actions->Count()) {
if ($actions && $actions->count()) {
/** @var TabSet $tabset */
$tabset = $actions->fieldByName('ActionMenus');
if ($tabset) {
foreach ($tabset->getChildren() as $tab) {
@ -724,7 +725,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Use <button> to allow full jQuery UI styling
$actionsFlattened = $actions->dataFields();
if($actionsFlattened) foreach($actionsFlattened as $action) $action->setUseButtonTag(true);
if($actionsFlattened) {
/** @var FormAction $action */
foreach($actionsFlattened as $action) {
$action->setUseButtonTag(true);
}
}
if($record->hasMethod('getCMSValidator')) {
$validator = $record->getCMSValidator();
@ -844,6 +850,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
}
/**
* @return Form
*/
public function ListViewForm() {
$params = $this->getRequest()->requestVar('q');
$list = $this->getList($params, $parentID = $this->getRequest()->requestVar('ParentID'));
@ -860,6 +869,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
}
$gridField = new GridField('Page','Pages', $list, $gridFieldConfig);
/** @var GridFieldDataColumns $columns */
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
// Don't allow navigating into children nodes on filtered lists
@ -868,7 +878,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'singular_name' => _t('SiteTree.PAGETYPE'),
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
);
$gridField->getConfig()->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title'));
/** @var GridFieldSortableHeader $sortableHeader */
$sortableHeader = $gridField->getConfig()->getComponentByType('GridFieldSortableHeader');
$sortableHeader->setFieldSorting(array('getTreeTitle' => 'Title'));
$gridField->getState()->ParentID = $parentID;
if(!$params) {
@ -885,6 +897,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$controller = $this;
$columns->setFieldFormatting(array(
'listChildrenLink' => function($value, &$item) use($controller) {
/** @var SiteTree $item */
$num = $item ? $item->numChildren() : null;
if($num) {
return sprintf(
@ -1029,12 +1042,17 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
/**
* @uses LeftAndMainExtension->augmentNewSiteTreeItem()
*
* @param int|string $id
* @param bool $setID
* @return mixed|DataObject
* @throws SS_HTTPResponse_Exception
*/
public function getNewItem($id, $setID = true) {
$parentClass = $this->stat('tree_class');
list($dummy, $className, $parentID, $suffix) = array_pad(explode('-',$id),4,null);
if(!is_subclass_of($className, $parentClass) && strcasecmp($className, $parentClass) != 0) {
if (!is_a($className, $parentClass, true)) {
$response = Security::permissionFailure($this);
if (!$response) {
$response = $this->getResponse();
@ -1042,8 +1060,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
throw new SS_HTTPResponse_Exception($response);
}
$newItem = new $className();
/** @var SiteTree $newItem */
$newItem = Injector::inst()->create($className);
if( !$suffix ) {
$sessionTag = "NewItems." . $parentID . "." . $className;
if(Session::get($sessionTag)) {
@ -1236,7 +1254,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
/**
* @return array
* @return SS_HTTPResponse
*/
public function rollback() {
return $this->doRollback(array(
@ -1318,6 +1336,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$SNG_action = singleton($batchAction);
if ($SNG_action->canView() && $fieldset = $SNG_action->getParameterFields()) {
$formHtml = '';
/** @var FormField $field */
foreach($fieldset as $field) {
$formHtml .= $field->Field();
}
@ -1353,6 +1372,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$pages = SiteTree::get()->limit("$start,30");
$count = 0;
while($pages) {
/** @var SiteTree $page */
foreach($pages as $page) {
if($page && !$page->canPublish()) {
return Security::permissionFailure($this);
@ -1377,7 +1397,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$token = SecurityToken::inst();
$fields = new FieldList();
$token->updateFieldSet($fields);
$tokenField = $fields->First();
$tokenField = $fields->first();
$tokenHtml = ($tokenField) ? $tokenField->FieldHolder() : '';
$response .= '<h1>' . _t('CMSMain.PUBALLFUN','"Publish All" functionality') . '</h1>
<p>' . _t('CMSMain.PUBALLFUN2', 'Pressing this button will do the equivalent of going to every page and pressing "publish". It\'s
@ -1395,6 +1415,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
/**
* Restore a completely deleted page from the SiteTree_versions table.
*
* @param array $data
* @param Form $form
* @return SS_HTTPResponse
*/
public function restore($data, $form) {
if(!isset($data['ID']) || !is_numeric($data['ID'])) {
@ -1402,8 +1426,11 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
$id = (int)$data['ID'];
/** @var SiteTree $restoredPage */
$restoredPage = Versioned::get_latest_version("SilverStripe\\CMS\\Model\\SiteTree", $id);
if(!$restoredPage) return new SS_HTTPResponse("SiteTree #$id not found", 400);
if(!$restoredPage) {
return new SS_HTTPResponse("SiteTree #$id not found", 400);
}
$restoredPage = $restoredPage->doRestoreToStage();
@ -1424,6 +1451,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
if(($id = $this->urlParams['ID']) && is_numeric($id)) {
/** @var SiteTree $page */
$page = SiteTree::get()->byID($id);
if($page && (!$page->canEdit() || !$page->canCreate(null, array('Parent' => $page->Parent())))) {
return Security::permissionFailure($this);
@ -1462,6 +1490,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
increase_time_limit_to();
if(($id = $this->urlParams['ID']) && is_numeric($id)) {
/** @var SiteTree $page */
$page = SiteTree::get()->byID($id);
if($page && (!$page->canEdit() || !$page->canCreate(null, array('Parent' => $page->Parent())))) {
return Security::permissionFailure($this);

View File

@ -11,11 +11,11 @@ use FieldList;
use LiteralField;
use SelectionGroup;
use SelectionGroup_Item;
use SS_HTTPResponse;
use TreeDropdownField;
use OptionsetField;
use FormAction;
use Form;
use Session;
use Controller;
use SilverStripe\CMS\Model\SiteTree;
@ -151,8 +151,8 @@ class CMSPageAddController extends CMSPageEditController {
$form->setValidationResponseCallback(function() use ($negotiator, $form) {
$request = $this->getRequest();
if($request->isAjax() && $negotiator) {
$this->setupFormErrors();
$result = $this->forTemplate();
$form->setupFormErrors();
$result = $form->forTemplate();
return $negotiator->respond($request, array(
'CurrentForm' => function() use($result) {
@ -167,6 +167,11 @@ class CMSPageAddController extends CMSPageEditController {
return $form;
}
/**
* @param array $data
* @param Form $form
* @return SS_HTTPResponse
*/
public function doAdd($data, $form) {
$className = isset($data['PageType']) ? $data['PageType'] : "Page";
$parentID = isset($data['ParentID']) ? (int)$data['ParentID'] : 0;

View File

@ -403,6 +403,7 @@ class CMSPageHistoryController extends CMSMain {
/** @var SiteTree $page */
$page = SiteTree::get()->byID($id);
$record = null;
if($page && $page->exists()) {
if(!$page->canView()) {
return Security::permissionFailure($this);

View File

@ -19,7 +19,6 @@ use Controller;
use Page;
use SiteConfig;
use Config;
use SS_HTTPRequest;
use Translatable;
use i18n;

View File

@ -4,10 +4,8 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\CMS\Model\ErrorPage;
/**
* Decorates {@see File} with ErrorPage support
*/

View File

@ -7,7 +7,6 @@ use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
use Controller;
use ClassInfo;
use Injector;
use SS_HTTPRequest;

View File

@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\FieldType\DBField;
@ -13,8 +14,6 @@ use ClassInfo;
use Controller;
use SilverStripe\Admin\CMSPreviewable;
use SilverStripe\Admin\LeftAndMain;
use SiteTreeFutureState;
use SilverStripe\CMS\Model\RedirectorPage;
@ -393,6 +392,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
public function getMessage() {
if($date = Versioned::current_archived_date()) {
/** @var DBDatetime $dateObj */
$dateObj = DBField::create_field('Datetime', $date);
return "<div id=\"SilverStripeNavigatorMessage\" title=\"". _t('ContentControl.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors') ."\">". _t('ContentController.ARCHIVEDSITEFROM', 'Archived site from') ."<br>" . $dateObj->Nice() . "</div>";
}

View File

@ -82,8 +82,8 @@ use SilverStripe\Admin\CMSPreviewable;
* @property string CanViewType Type of restriction for viewing this object.
* @property string CanEditType Type of restriction for editing this object.
*
* @method ManyManyList ViewerGroups List of groups that can view this object.
* @method ManyManyList EditorGroups List of groups that can edit this object.
* @method ManyManyList ViewerGroups() List of groups that can view this object.
* @method ManyManyList EditorGroups() List of groups that can edit this object.
* @method SiteTree Parent()
*
* @mixin Hierarchy
@ -403,8 +403,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
public static function page_type_classes() {
$classes = ClassInfo::getValidSubClasses();
$baseClassIndex = array_search('SilverStripe\\CMS\\Model\\SiteTree', $classes);
if($baseClassIndex !== FALSE) unset($classes[$baseClassIndex]);
$baseClassIndex = array_search(__CLASS__, $classes);
if($baseClassIndex !== false) {
unset($classes[$baseClassIndex]);
}
$kill_ancestors = array();
@ -448,6 +450,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return null;
}
/** @var SiteTree $page */
if (
!($page = DataObject::get_by_id(__CLASS__, $arguments['id'])) // Get the current page by ID.
&& !($page = Versioned::get_latest_version(__CLASS__, $arguments['id'])) // Attempt link to old version.
@ -1925,9 +1928,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$dependentPages
);
/** @var GridFieldDataColumns $dataColumns */
$dataColumns = $dependentTable
->getConfig()
->getComponentByType('GridFieldDataColumns');
$dataColumns = $dependentTable->getConfig()->getComponentByType('GridFieldDataColumns');
$dataColumns
->setDisplayFields($dependentColumns)
->setFieldFormatting(array(

View File

@ -4,7 +4,7 @@
<div class="cms-content-header north">
<div class="cms-content-header-info">
<% with $Controller %>
<% include CMSBreadcrumbs %>
<% include SilverStripe\\Admin\\CMSBreadcrumbs %>
<% end_with %>
</div>

View File

@ -1,24 +1,24 @@
<div id="pages-controller-cms-content" class="has-panel cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content" data-ignore-tab-state="true">
<div class="cms-content-header north">
<div class="cms-content-header-nav">
<% include CMSBreadcrumbs %>
<% include SilverStripe\\Admin\\CMSBreadcrumbs %>
<div class="cms-content-header-tabs">
<ul class="cms-tabset-nav-primary">
<li class="content-treeview<% if class == 'CMSPageEditController' %> ui-tabs-active<% end_if %>">
<li class="content-treeview<% if $class == 'SilverStripe\\CMS\\Controllers\\CMSPageEditController' %> ui-tabs-active<% end_if %>">
<a href="$LinkPageEdit" class="cms-panel-link" title="Form_EditForm" data-href="$LinkPageEdit">
<% _t('CMSMain.TabContent', 'Content') %>
</a>
</li>
<li class="content-listview<% if class == 'CMSPageSettingsController' %> ui-tabs-active<% end_if %>">
<li class="content-listview<% if $class == 'SilverStripe\\CMS\\Controllers\\CMSPageSettingsController' %> ui-tabs-active<% end_if %>">
<a href="$LinkPageSettings" class="cms-panel-link" title="Form_EditForm" data-href="$LinkPageSettings">
<% _t('CMSMain.TabSettings', 'Settings') %>
</a>
</li>
<li class="content-listview<% if class == 'CMSPageHistoryController' %> ui-tabs-active<% end_if %>">
<li class="content-listview<% if $class == 'SilverStripe\\CMS\\Controllers\\CMSPageHistoryController' %> ui-tabs-active<% end_if %>">
<a href="$LinkPageHistory" class="cms-panel-link" title="Form_EditForm" data-href="$LinkPageHistory">
<% _t('CMSMain.TabHistory', 'History') %>
</a>
@ -29,7 +29,7 @@
<div class="cms-content-header-info">
<div class="section-heading">
<% include CMSSectionIcon %>
<% include SilverStripe\\Admin\\CMSSectionIcon %>
<span class="section-label"><a href="$LinkPages">{$MenuCurrentItem.Title}</a></span>
</div>

View File

@ -28,7 +28,7 @@
</a>
<% end_if %>
<% include LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content" %>
<% include SilverStripe\\Admin\\LeftAndMain_ViewModeSelector SelectID="preview-mode-dropdown-in-content" %>
</div>
<% end_if %>
</div>

View File

@ -2,7 +2,7 @@
<div class="cms-content-header north">
<div class="cms-content-header-info">
<% include CMSBreadcrumbs %>
<% include SilverStripe\\Admin\\CMSBreadcrumbs %>
</div>
<div class="cms-content-header-tabs">