From 0ea94510143d3b2f54b52e49fce8538b00c4aced Mon Sep 17 00:00:00 2001
From: Sean Harvey
Date: Tue, 27 Mar 2012 17:05:11 +1300
Subject: [PATCH 01/10] MINOR Fixes to method arguments in cms classes for
E_STRICT support.
---
code/controllers/CMSSettingsController.php | 6 +++---
code/controllers/ContentController.php | 4 ++--
code/controllers/RootURLController.php | 2 +-
code/controllers/SilverStripeNavigator.php | 8 ++++----
code/model/ErrorPage.php | 4 ++--
code/model/RedirectorPage.php | 4 ++--
code/model/SiteConfig.php | 2 +-
code/model/SiteTree.php | 5 +----
code/model/SiteTreeFileExtension.php | 4 ++--
code/model/SiteTreeFolderExtension.php | 11 ++---------
code/reports/Report.php | 8 ++++----
code/widgets/Widget.php | 6 +++---
tests/model/SiteTreeBacklinksTest.php | 4 ++--
tests/model/VirtualPageTest.php | 4 ++--
tests/widgets/WidgetAreaEditorTest.php | 4 ++--
15 files changed, 33 insertions(+), 43 deletions(-)
diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php
index b73dbb7c..b0ab5519 100644
--- a/code/controllers/CMSSettingsController.php
+++ b/code/controllers/CMSSettingsController.php
@@ -9,7 +9,7 @@ class CMSSettingsController extends CMSMain {
/**
* @return Form
*/
- function getEditForm($id = null) {
+ function getEditForm($id = null, $fields = null) {
$siteConfig = SiteConfig::current_site_config();
$fields = $siteConfig->getCMSFields();
@@ -54,7 +54,7 @@ class CMSSettingsController extends CMSMain {
return false;
}
- function Breadcrumbs() {
+ function Breadcrumbs($unlinked = false) {
return new ArrayList(array(
new ArrayData(array(
'Title' => $this->SectionTitle(),
@@ -63,4 +63,4 @@ class CMSSettingsController extends CMSMain {
));
}
-}
\ No newline at end of file
+}
diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php
index 4f0c7bff..e731f9f0 100644
--- a/code/controllers/ContentController.php
+++ b/code/controllers/ContentController.php
@@ -133,7 +133,7 @@ class ContentController extends Controller {
*
* @return SS_HTTPResponse
*/
- public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
+ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
$child = null;
$action = $request->param('Action');
$this->setModel($model);
@@ -526,4 +526,4 @@ HTML
"Content" => $content,
);
}
-}
\ No newline at end of file
+}
diff --git a/code/controllers/RootURLController.php b/code/controllers/RootURLController.php
index 56aef850..c8386ca3 100644
--- a/code/controllers/RootURLController.php
+++ b/code/controllers/RootURLController.php
@@ -101,7 +101,7 @@ class RootURLController extends Controller {
* @param SS_HTTPRequest $request
* @return SS_HTTPResponse
*/
- public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
+ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
self::$is_at_root = true;
$this->setModel($model);
diff --git a/code/controllers/SilverStripeNavigator.php b/code/controllers/SilverStripeNavigator.php
index 1c3acb45..b9bdab1b 100644
--- a/code/controllers/SilverStripeNavigator.php
+++ b/code/controllers/SilverStripeNavigator.php
@@ -193,7 +193,7 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
return (Controller::curr() instanceof CMSMain);
}
- function canView() {
+ function canView($member = null) {
// Don't show in CMS
return !(Controller::curr() instanceof CMSMain);
}
@@ -223,7 +223,7 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
return Controller::join_links($this->record->AbsoluteLink(), '?stage=Stage');
}
- function canView() {
+ function canView($member = null) {
return ($this->record->hasExtension('Versioned') && $this->getDraftPage());
}
@@ -267,7 +267,7 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
return Controller::join_links($this->record->AbsoluteLink(), '?stage=Live');
}
- function canView() {
+ function canView($member = null) {
return ($this->record->hasExtension('Versioned') && $this->getLivePage());
}
@@ -309,7 +309,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
return $this->record->AbsoluteLink() . '?archiveDate=' . $date;
}
- function canView() {
+ function canView($member = null) {
return ($this->record->hasExtension('Versioned') && $this->isArchived());
}
diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php
index 0cd7342d..28af7056 100644
--- a/code/model/ErrorPage.php
+++ b/code/model/ErrorPage.php
@@ -127,8 +127,8 @@ class ErrorPage extends Page {
}
}
- function getCMSFields() {
- $fields = parent::getCMSFields();
+ function getCMSFields($params = null) {
+ $fields = parent::getCMSFields($params);
$fields->addFieldToTab(
"Root.Main",
diff --git a/code/model/RedirectorPage.php b/code/model/RedirectorPage.php
index 1fe2082e..08c267f2 100644
--- a/code/model/RedirectorPage.php
+++ b/code/model/RedirectorPage.php
@@ -115,7 +115,7 @@ class RedirectorPage extends Page {
}
}
- function getCMSFields() {
+ function getCMSFields($params = null) {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/RedirectorPage.js");
$fields = parent::getCMSFields();
@@ -180,4 +180,4 @@ class RedirectorPage_Controller extends Page_Controller {
_t('RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') .
"
";
}
-}
\ No newline at end of file
+}
diff --git a/code/model/SiteConfig.php b/code/model/SiteConfig.php
index 1d9d537b..218c8774 100644
--- a/code/model/SiteConfig.php
+++ b/code/model/SiteConfig.php
@@ -41,7 +41,7 @@ class SiteConfig extends DataObject implements PermissionProvider {
*
* @return FieldList
*/
- function getCMSFields() {
+ function getCMSFields($params = null) {
Requirements::javascript(CMS_DIR . "/javascript/SitetreeAccess.js");
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php
index 3f39d5cc..2c0b2225 100644
--- a/code/model/SiteTree.php
+++ b/code/model/SiteTree.php
@@ -1013,9 +1013,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
static function prepopulate_permission_cache($permission = 'CanEditType', $ids, $batchCallback = null) {
if(!$batchCallback) $batchCallback = "SiteTree::can_{$permission}_multiple";
- //PHP 5.1 requires an array rather than a string for the call_user_func function
- $batchCallback=explode('::', $batchCallback);
-
if(is_callable($batchCallback)) {
call_user_func($batchCallback, $ids, Member::currentUserID(), false);
} else {
@@ -1754,7 +1751,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*
* @return FieldList The fields to be displayed in the CMS.
*/
- function getCMSFields() {
+ function getCMSFields($params = null) {
require_once("forms/Form.php");
// Status / message
// Create a status message for multiple parents
diff --git a/code/model/SiteTreeFileExtension.php b/code/model/SiteTreeFileExtension.php
index 9289c2e7..955bec9f 100644
--- a/code/model/SiteTreeFileExtension.php
+++ b/code/model/SiteTreeFileExtension.php
@@ -5,7 +5,7 @@
*/
class SiteTreeFileExtension extends DataExtension {
- function extraStatics() {
+ function extraStatics($class = null, $extension = null) {
return array(
'belongs_many_many' => array(
"BackLinkTracking" => "SiteTree",
@@ -95,4 +95,4 @@ class SiteTreeFileExtension extends DataExtension {
if(class_exists('Subsite')) Subsite::disable_subsite_filter(false);
}
-}
\ No newline at end of file
+}
diff --git a/code/model/SiteTreeFolderExtension.php b/code/model/SiteTreeFolderExtension.php
index 7ad8233d..2cfac2ed 100644
--- a/code/model/SiteTreeFolderExtension.php
+++ b/code/model/SiteTreeFolderExtension.php
@@ -1,13 +1,6 @@
push(new Tab("UnusedFiles", _t('Folder.UNUSEDFILESTAB', "Unused files"),
- // new Folder_UnusedAssetsField($this)
- // ));
- }
-
+
/**
* Looks for files used in system and create where clause which contains all ID's of files.
*
@@ -52,4 +45,4 @@ class SiteTreeFolderExtension extends DataExtension {
}
return $where;
}
-}
\ No newline at end of file
+}
diff --git a/code/reports/Report.php b/code/reports/Report.php
index 3592869f..57182c4d 100644
--- a/code/reports/Report.php
+++ b/code/reports/Report.php
@@ -378,11 +378,11 @@ class SS_Report_FakeQuery extends SQLQuery {
$this->sortColMethod = $sortColMethod;
}
- function limit($limit) {
+ function limit($limit, $offset = 0) {
$this->limit = $limit;
}
- function unlimitedRowCount() {
+ function unlimitedRowCount($column = null) {
$source = $this->obj->{$this->method}($this->params, null, null);
return $source ? $source->Count() : 0;
}
@@ -511,8 +511,8 @@ abstract class SS_ReportWrapper extends SS_Report {
return $this->baseReport->description();
}
- function canView() {
- return $this->baseReport->canView();
+ function canView($member = null) {
+ return $this->baseReport->canView($member);
}
}
diff --git a/code/widgets/Widget.php b/code/widgets/Widget.php
index e564b6f0..8b174ea3 100644
--- a/code/widgets/Widget.php
+++ b/code/widgets/Widget.php
@@ -34,7 +34,7 @@ class Widget extends DataObject {
static $cmsTitle = "Name of this widget";
static $description = "Description of what this widget does.";
- function getCMSFields() {
+ function getCMSFields($params = null) {
$fields = new FieldList();
$this->extend('updateCMSFields', $fields);
return $fields;
@@ -226,7 +226,7 @@ class Widget_Controller extends Controller {
* @subpackage widgets
*/
class Widget_TreeDropdownField extends TreeDropdownField {
- function FieldHolder() {}
- function Field() {}
+ function FieldHolder($properties = array()) {}
+ function Field($properties = array()) {}
}
diff --git a/tests/model/SiteTreeBacklinksTest.php b/tests/model/SiteTreeBacklinksTest.php
index 69c3a1d9..7835155e 100644
--- a/tests/model/SiteTreeBacklinksTest.php
+++ b/tests/model/SiteTreeBacklinksTest.php
@@ -243,7 +243,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
}
class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly {
- function extraStatics() {
+ function extraStatics($class = null, $extension = null) {
return array(
'db' => array(
'ExtraContent' => 'HTMLText',
@@ -251,7 +251,7 @@ class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly {
);
}
- function updateCMSFields(&$fields) {
+ function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab("Root.Content", new HTMLEditorField("ExtraContent"));
}
}
diff --git a/tests/model/VirtualPageTest.php b/tests/model/VirtualPageTest.php
index de44a1a3..d556b5ef 100644
--- a/tests/model/VirtualPageTest.php
+++ b/tests/model/VirtualPageTest.php
@@ -607,7 +607,7 @@ class VirtualPageTest_VirtualPageSub extends VirtualPage implements TestOnly {
}
class VirtualPageTest_PageExtension extends DataExtension implements TestOnly {
- function extraStatics() {
+ function extraStatics($class = null, $extension = null) {
return array(
'db' => array(
// These fields are just on an extension to simulate shared properties between Page and VirtualPage.
@@ -617,4 +617,4 @@ class VirtualPageTest_PageExtension extends DataExtension implements TestOnly {
)
);
}
-}
\ No newline at end of file
+}
diff --git a/tests/widgets/WidgetAreaEditorTest.php b/tests/widgets/WidgetAreaEditorTest.php
index 2d258f2e..81eb76b5 100644
--- a/tests/widgets/WidgetAreaEditorTest.php
+++ b/tests/widgets/WidgetAreaEditorTest.php
@@ -460,7 +460,7 @@ class WidgetAreaEditorTest_TestWidget extends Widget implements TestOnly {
static $db = array(
'Title' => 'Varchar'
);
- public function getCMSFields() {
+ public function getCMSFields($params = null) {
$fields = new FieldList();
$fields->push(new TextField('Title'));
return $fields;
@@ -468,4 +468,4 @@ class WidgetAreaEditorTest_TestWidget extends Widget implements TestOnly {
function Title() {
return $this->Title ? $this->Title : self::$title;
}
-}
\ No newline at end of file
+}
From 1ab76865eae00d41f63f9dcc71035f683c8f48b1 Mon Sep 17 00:00:00 2001
From: Sean Harvey
Date: Tue, 27 Mar 2012 22:52:33 +1300
Subject: [PATCH 02/10] MINOR Remove use of deprecated ereg_replace() and use
preg_replace() instead.
---
code/staticpublisher/FilesystemPublisher.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/code/staticpublisher/FilesystemPublisher.php b/code/staticpublisher/FilesystemPublisher.php
index 2f1809f9..4de5dcda 100644
--- a/code/staticpublisher/FilesystemPublisher.php
+++ b/code/staticpublisher/FilesystemPublisher.php
@@ -102,8 +102,8 @@ class FilesystemPublisher extends StaticPublisher {
// perform similar transformations to SiteTree::generateURLSegment()
$urlSegment = str_replace('&','-and-',$urlSegment);
$urlSegment = str_replace('&','-and-',$urlSegment);
- $urlSegment = ereg_replace('[^A-Za-z0-9\/-]+','-',$urlSegment);
- $urlSegment = ereg_replace('-+','-',$urlSegment);
+ $urlSegment = preg_replace('/[^A-Za-z0-9\/-]+/', '-', $urlSegment);
+ $urlSegment = preg_replace('/-+/', '-', $urlSegment);
$urlSegment = trim($urlSegment, '/');
$filename = $urlSegment ? "$urlSegment.$this->fileExtension" : "index.$this->fileExtension";
From ded3fd8d68893f3a896ef1398bf1c4cac7b69ee4 Mon Sep 17 00:00:00 2001
From: Sean Harvey
Date: Fri, 30 Mar 2012 16:25:21 +1300
Subject: [PATCH 03/10] MINOR Fixed broken test from json changes
---
tests/controller/CMSMainTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php
index 0a4988af..312fbbb3 100644
--- a/tests/controller/CMSMainTest.php
+++ b/tests/controller/CMSMainTest.php
@@ -47,8 +47,8 @@ class CMSMainTest extends FunctionalTest {
$response = Director::test("admin/cms/batchactions/publish", array('csvIDs' => implode(',', array($page1->ID, $page2->ID)), 'ajax' => 1), $this->session());
$responseData = Convert::json2array($response->getBody());
- $this->assertTrue(property_exists($responseData['modified'], $page1->ID));
- $this->assertTrue(property_exists($responseData['modified'], $page2->ID));
+ $this->assertArrayHasKey($page1->ID, $responseData['modified']);
+ $this->assertArrayHasKey($page2->ID, $responseData['modified']);
}
// Get the latest version of the redirector page
From 070c9c22aa34695e305012d36af1b8198a500e52 Mon Sep 17 00:00:00 2001
From: Sean Harvey
Date: Wed, 4 Apr 2012 12:05:38 +1200
Subject: [PATCH 04/10] BUGFIX Removed used of deprecated Name() method in
AssetAdmin
---
code/controllers/AssetAdmin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php
index 2596e5cb..31be0c69 100644
--- a/code/controllers/AssetAdmin.php
+++ b/code/controllers/AssetAdmin.php
@@ -202,7 +202,7 @@ JS
$tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details')));
$tabDetails->addExtraClass("content-galleryview");
foreach($fields as $field) {
- $fields->removeByName($field->Name());
+ $fields->removeByName($field->getName());
$tabDetails->push($field);
}
}
From de573e087d4a9d05692a0f665e836f489ccaf9a5 Mon Sep 17 00:00:00 2001
From: Ingo Schommer
Date: Wed, 4 Apr 2012 16:59:22 +0200
Subject: [PATCH 05/10] MINOR Using late static binding instead of
Object::create() calls
---
code/controllers/AssetAdmin.php | 6 +++---
code/controllers/CMSFileAddController.php | 2 +-
code/controllers/CMSMain.php | 2 +-
code/controllers/ContentController.php | 2 +-
code/controllers/SilverStripeNavigator.php | 2 +-
code/model/SiteConfig.php | 6 +++---
code/model/SiteTree.php | 10 +++++-----
tasks/RemoveOrphanedPagesTask.php | 2 +-
8 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php
index 31be0c69..64ab3c23 100644
--- a/code/controllers/AssetAdmin.php
+++ b/code/controllers/AssetAdmin.php
@@ -211,8 +211,8 @@ JS
// List view
$fields->addFieldsToTab('Root.ListView', array(
- $actionsComposite = Object::create('CompositeField',
- Object::create('CompositeField',
+ $actionsComposite = CompositeField::create(
+ CompositeField::create(
$uploadBtn,
$addFolderBtn,
$syncButton //TODO: add this into a batch actions menu as in https://github.com/silverstripe/silverstripe-design/raw/master/Design/ss3-ui_files-manager-list-view.jpg
@@ -311,7 +311,7 @@ JS
$fields = $context->getSearchFields();
$actions = new FieldList(
- Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.CLEAR', 'Clear'))
+ ResetFormAction::create('clear', _t('CMSMain_left.ss.CLEAR', 'Clear'))
->addExtraClass('ss-ui-action-minor'),
FormAction::create('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search'))
);
diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php
index 28f2b735..5c2cb143 100644
--- a/code/controllers/CMSFileAddController.php
+++ b/code/controllers/CMSFileAddController.php
@@ -57,7 +57,7 @@ class CMSFileAddController extends LeftAndMain {
$folder = $this->currentPage();
- $uploadField = Object::create('UploadField', 'AssetUploadField', '');
+ $uploadField = UploadField::create('AssetUploadField', '');
$uploadField->setConfig('previewMaxWidth', 40);
$uploadField->setConfig('previewMaxHeight', 30);
$uploadField->addExtraClass('ss-assetuploadfield');
diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php
index 5ab2ae6c..f6faa93a 100644
--- a/code/controllers/CMSMain.php
+++ b/code/controllers/CMSMain.php
@@ -200,7 +200,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$dateTo->setConfig('showcalendar', true);
$actions = new FieldList(
- Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.CLEAR', 'Clear'))
+ ResetFormAction::create('clear', _t('CMSMain_left.ss.CLEAR', 'Clear'))
->addExtraClass('ss-ui-action-minor'),
FormAction::create('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search'))
);
diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php
index e731f9f0..1e0099ae 100644
--- a/code/controllers/ContentController.php
+++ b/code/controllers/ContentController.php
@@ -376,7 +376,7 @@ HTML;
} else {
if($date = Versioned::current_archived_date()) {
Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css');
- $dateObj = Object::create('Datetime', $date, null);
+ $dateObj = Datetime::create($date, null);
// $dateObj->setVal($date);
return "". _t('ContentController.ARCHIVEDSITEFROM') ."
" . $dateObj->Nice() . "
";
}
diff --git a/code/controllers/SilverStripeNavigator.php b/code/controllers/SilverStripeNavigator.php
index b9bdab1b..b3ba5802 100644
--- a/code/controllers/SilverStripeNavigator.php
+++ b/code/controllers/SilverStripeNavigator.php
@@ -299,7 +299,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
function getMessage() {
if($date = Versioned::current_archived_date()) {
- $dateObj = Object::create('Datetime');
+ $dateObj = Datetime::create();
$dateObj->setValue($date);
return "". _t('ContentController.ARCHIVEDSITEFROM', 'Archived site from') ."
" . $dateObj->Nice() . "
";
}
diff --git a/code/model/SiteConfig.php b/code/model/SiteConfig.php
index 218c8774..0a9d2d12 100644
--- a/code/model/SiteConfig.php
+++ b/code/model/SiteConfig.php
@@ -56,13 +56,13 @@ class SiteConfig extends DataObject implements PermissionProvider {
),
$tabAccess = new Tab('Access',
$viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
- $viewerGroupsField = Object::create('ListboxField', "ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
+ $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
->setMultiple(true)->setSource($groupsMap),
$editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
- $editorGroupsField = Object::create('ListboxField', "EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
+ $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
->setMultiple(true)->setSource($groupsMap),
$topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
- $topLevelCreatorsGroupsField = Object::create('ListboxField', "CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
+ $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
->setMultiple(true)->setSource($groupsMap)
)
)
diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php
index 181e2285..4e16cc70 100644
--- a/code/model/SiteTree.php
+++ b/code/model/SiteTree.php
@@ -1374,7 +1374,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if((!$this->URLSegment || $this->URLSegment == 'new-page') && $this->Title) {
$this->URLSegment = $this->generateURLSegment($this->Title);
} else if($this->isChanged('URLSegment')) {
- $filter = Object::create('URLSegmentFilter');
+ $filter = URLSegmentFilter::create();
$this->URLSegment = $filter->filter($this->URLSegment);
// If after sanitising there is no URLSegment, give it a reasonable default
if(!$this->URLSegment) $this->URLSegment = "page-$this->ID";
@@ -1583,7 +1583,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return string Generated url segment
*/
function generateURLSegment($title){
- $filter = Object::create('URLSegmentFilter');
+ $filter = URLSegmentFilter::create();
$t = $filter->filter($title);
// Fallback to generic page name if path is empty (= no valid, convertable characters)
@@ -1906,13 +1906,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
"CanViewType",
_t('SiteTree.ACCESSHEADER', "Who can view this page?")
),
- $viewerGroupsField = Object::create('ListboxField', "ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
+ $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
->setMultiple(true)->setSource($groupsMap),
$editorsOptionsField = new OptionsetField(
"CanEditType",
_t('SiteTree.EDITHEADER', "Who can edit this page?")
),
- $editorGroupsField = Object::create('ListboxField', "EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
+ $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
->setMultiple(true)->setSource($groupsMap)
)
)
@@ -2022,7 +2022,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return FieldList The available actions for this page.
*/
function getCMSActions() {
- $minorActions = Object::create('CompositeField')->setTag('fieldset')->addExtraClass('ss-ui-buttonset');
+ $minorActions = CompositeField::create()->setTag('fieldset')->addExtraClass('ss-ui-buttonset');
$actions = new FieldList($minorActions);
// "readonly"/viewing version that isn't the current version of the record
diff --git a/tasks/RemoveOrphanedPagesTask.php b/tasks/RemoveOrphanedPagesTask.php
index 5790032b..1363490b 100644
--- a/tasks/RemoveOrphanedPagesTask.php
+++ b/tasks/RemoveOrphanedPagesTask.php
@@ -106,7 +106,7 @@ in the other stage:
$orphan->ID,
$orphan->Title,
$orphan->ID,
- DBField::create('Date', $orphan->LastEdited)->Nice(),
+ Date::create($orphan->LastEdited)->Nice(),
($latestAuthor) ? $latestAuthor->Title : 'unknown',
($liveRecord) ? 'is published' : 'not published'
);
From c1b248e2cf52b17c1378f15447399fa524d7f3ba Mon Sep 17 00:00:00 2001
From: Normann Lou
Date: Thu, 29 Mar 2012 11:47:28 +1300
Subject: [PATCH 06/10] ENHANCEMENT SiteTree->getStatusFlags() which makes
SiteTree->getTreeTitle() extensible
---
code/model/SiteTree.php | 66 +++++++++++++++++++++++++-----------
tests/model/SiteTreeTest.php | 17 ++++++++++
2 files changed, 64 insertions(+), 19 deletions(-)
diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php
index 4e16cc70..8f9e1f89 100644
--- a/code/model/SiteTree.php
+++ b/code/model/SiteTree.php
@@ -2438,6 +2438,36 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
}
+ /**
+ * A flag provides the user with additional data about the current page status,
+ * for example a "removed from draft" status. Each page can have more than one status flag.
+ * Returns a map of a unique key to a (localized) title for the flag.
+ * The unique key can be reused as a CSS class.
+ * Use the 'updateStatusFlags' extension point to customize the flags.
+ * Example: "deletedonlive" => "Deleted"
+ *
+ * @return array
+ */
+ function getStatusFlags() {
+ $flags = array();
+ if($this->IsDeletedFromStage) {
+ if($this->ExistsOnLive) {
+ $flags['removedfromdraft'] = _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft');
+ } else {
+ $flags['deletedonlive'] = _t('SiteTree.DELETEDPAGESHORT', 'Deleted');
+ }
+ } else if($this->IsAddedToStage) {
+ $flags['addedtodraft'] = _t('SiteTree.ADDEDTODRAFTSHORT', 'New');
+ } else if($this->IsModifiedOnStage) {
+ $flags['modified'] = _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified');
+ }
+
+ $this->extend('updateStatusFlags', $flags);
+
+ return $flags;
+ }
+
+
/**
* @deprecated 3.0 Use getTreeTitle()
*/
@@ -2447,29 +2477,27 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
/**
- * TitleWithStatus will return the title in an , or
- * tag depending on its publication status.
+ * getTreeTitle will return three html DOM elements, an empty with
+ * the class 'jstree-pageicon' in front, following by a wrapping around its
+ * MenutTitle, then following by a indicating its publication status.
*
- * @return string
+ * @return string a html string ready to be directly used in a template
*/
function getTreeTitle() {
- $text = Convert::raw2xml(str_replace(array("\n","\r"),"",$this->MenuTitle));
- if($this->IsDeletedFromStage) {
- if($this->ExistsOnLive) {
- $tag ="{$text} " . _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft') . "";
- } else {
- $tag ="{$text} ". _t('SiteTree.DELETEDPAGESHORT', 'Deleted') . "";
- }
- } elseif($this->IsAddedToStage) {
- $tag = "{$text} ". _t('SiteTree.ADDEDTODRAFTSHORT', 'New') . "";
- } elseif($this->IsModifiedOnStage) {
- $tag = "{$text} " . _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified') . "";
- } else {
- $tag = '';
+ $flags = $this->getStatusFlags();
+ $treeTitle = sprintf(
+ "%s",
+ Convert::raw2xml(str_replace(array("\n","\r"),"",$this->MenuTitle))
+ );
+ foreach($flags as $class => $title) {
+ $treeTitle .= sprintf(
+ "%s",
+ Convert::raw2xml($class),
+ Convert::raw2xml($title)
+ );
}
-
-
- return ($tag) ? "". $tag : "". $text;
+
+ return $treeTitle;
}
/**
diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php
index 04b446f7..abc65192 100644
--- a/tests/model/SiteTreeTest.php
+++ b/tests/model/SiteTreeTest.php
@@ -17,6 +17,7 @@ class SiteTreeTest extends SapphireTest {
'SiteTreeTest_ClassD',
'SiteTreeTest_ClassCext',
'SiteTreeTest_NotRoot',
+ 'SiteTreeTest_StageStatusInherit',
);
/**
@@ -866,7 +867,15 @@ class SiteTreeTest extends SapphireTest {
}
if(!$isDetected) $this->fail('Fails validation with $can_be_root=false');
+ }
+
+ function testModifyStatusFlagByInheritance(){
+ $node = new SiteTreeTest_StageStatusInherit();
+ $treeTitle = $node->getTreeTitle();
+ $this->assertContains('InheritedTitle', $treeTitle);
+ $this->assertContains('inherited-class', $treeTitle);
}
+
}
/**#@+
@@ -928,4 +937,12 @@ class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly {
class SiteTreeTest_NotRoot extends Page implements TestOnly {
static $can_be_root = false;
+}
+
+class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly {
+ function getStatusFlags(){
+ $flags = parent::getStatusFlags();
+ $flags['inherited-class'] = "InheritedTitle";
+ return $flags;
+ }
}
\ No newline at end of file
From 3341a181c74580f917e2f7fe1c035f58785ae153 Mon Sep 17 00:00:00 2001
From: Ingo Schommer
Date: Thu, 5 Apr 2012 14:45:26 +0200
Subject: [PATCH 07/10] MINOR Using SS_HTTPRequest->isAjax() instead of
deprecated RequestHandler API
---
code/controllers/AssetAdmin.php | 2 +-
code/controllers/CMSFileAddController.php | 2 +-
code/controllers/CMSMain.php | 4 ++--
code/controllers/CMSPageHistoryController.php | 8 ++++----
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php
index 64ab3c23..6cc34ac7 100644
--- a/code/controllers/AssetAdmin.php
+++ b/code/controllers/AssetAdmin.php
@@ -255,7 +255,7 @@ JS
'EditForm' => $this->AddForm()
));
- if($this->isAjax()) {
+ if($request->isAjax()) {
// Rendering is handled by template, which will call EditForm() eventually
$content = $obj->renderWith($this->getTemplatesWithSuffix('_Content'));
} else {
diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php
index 5c2cb143..4d4a6e58 100644
--- a/code/controllers/CMSFileAddController.php
+++ b/code/controllers/CMSFileAddController.php
@@ -9,7 +9,7 @@ class CMSFileAddController extends LeftAndMain {
// public function upload($request) {
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
-// if($this->isAjax()) {
+// if($request->isAjax()) {
// return $formHtml;
// } else {
// return $this->customise(array(
diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php
index f6faa93a..0282350c 100644
--- a/code/controllers/CMSMain.php
+++ b/code/controllers/CMSMain.php
@@ -47,7 +47,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function init() {
// set reading lang
- if(Object::has_extension('SiteTree', 'Translatable') && !$this->isAjax()) {
+ if(Object::has_extension('SiteTree', 'Translatable') && !$this->request->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
}
@@ -139,7 +139,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Include custom CSS for tree icons inline, as the tree might be loaded
// via Ajax, in which case we can't inject it into the HTML header easily through the HTTP response.
$css = $this->generateTreeStylingCSS();
- if($this->isAjax()) {
+ if($this->request->isAjax()) {
$html .= "\n";
} else {
Requirements::customCSS($css);
diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php
index e1306a54..25ad3e9f 100644
--- a/code/controllers/CMSPageHistoryController.php
+++ b/code/controllers/CMSPageHistoryController.php
@@ -27,7 +27,7 @@ class CMSPageHistoryController extends CMSMain {
function show($request) {
$form = $this->ShowVersionForm($request->param('VersionID'));
- if($this->isAjax()) {
+ if($request->isAjax()) {
if($form) $content = $form->forTemplate();
else $content = $this->renderWith($this->getTemplatesWithSuffix('_Content'));
} else {
@@ -44,7 +44,7 @@ class CMSPageHistoryController extends CMSMain {
$request->param('VersionID'),
$request->param('OtherVersionID')
);
- if($this->isAjax()) {
+ if($request->isAjax()) {
$content = $form->forTemplate();
} else {
$content = $this->customise(array('EditForm' => $form))->renderWith($this->getViewer('show'));
@@ -258,7 +258,7 @@ class CMSPageHistoryController extends CMSMain {
$form = $this->CompareVersionsForm($version1, $version2);
// javascript solution, render into template
- if($this->isAjax()) {
+ if($this->request->isAjax()) {
return $this->customise(array(
"EditForm" => $form
))->renderWith(array(
@@ -293,7 +293,7 @@ class CMSPageHistoryController extends CMSMain {
if(!$versionID) return;
- if($this->isAjax()) {
+ if($request->isAjax()) {
return $this->customise(array(
"EditForm" => $this->ShowVersionForm($versionID)
))->renderWith(array(
From a6c586ae203fd0ca01c2c81b8966e01ab2235fd7 Mon Sep 17 00:00:00 2001
From: Ingo Schommer
Date: Thu, 5 Apr 2012 22:27:47 +0200
Subject: [PATCH 08/10] MINOR Using new PjaxResponseNegotiator in CMSMain
---
code/controllers/CMSMain.php | 26 +++++---------------------
1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php
index 0282350c..68e2bd7a 100644
--- a/code/controllers/CMSMain.php
+++ b/code/controllers/CMSMain.php
@@ -591,20 +591,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->Title
)
);
-
- // Reload form, data and actions might have changed
- $form = $this->getEditForm($record->ID);
} else {
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
-
- // Reload form, data and actions might have changed
- $form = $this->getEditForm($record->ID);
}
-
- return $form->forTemplate();
- }
-
+ return $this->getResponseNegotiator()->respond($this->request);
+ }
/**
* @uses LeftAndMainExtension->augmentNewSiteTreeItem()
@@ -742,9 +734,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)
);
- $form = $this->getEditForm($record->ID);
-
- return $form->forTemplate();
+ return $this->getResponseNegotiator()->respond($this->request);
}
/**
@@ -796,10 +786,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
sprintf(_t('CMSMain.REMOVEDPAGE',"Removed '%s' from the published site"),$record->Title)
);
- // Reload form, data and actions might have changed
- $form = $this->getEditForm($record->ID);
-
- return $form->forTemplate();
+ return $this->getResponseNegotiator()->respond($this->request);
}
/**
@@ -948,10 +935,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)
);
- // Reload form, data and actions might have changed
- $form = $this->getEditForm($restoredPage->ID);
-
- return $form->forTemplate();
+ return $this->getResponseNegotiator()->respond($this->request);
}
function duplicate($request) {
From 4524d1c59472122d2dcd6aa85ee8d40a7a6b0e7a Mon Sep 17 00:00:00 2001
From: Ingo Schommer
Date: Thu, 5 Apr 2012 23:00:04 +0200
Subject: [PATCH 09/10] MINOR Fixed usage of deprecated Form->dataFieldByName()
---
code/forms/SiteTreeURLSegmentField.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/forms/SiteTreeURLSegmentField.php b/code/forms/SiteTreeURLSegmentField.php
index d89519bb..9c7329ad 100644
--- a/code/forms/SiteTreeURLSegmentField.php
+++ b/code/forms/SiteTreeURLSegmentField.php
@@ -44,7 +44,7 @@ class SiteTreeURLSegmentField extends TextField {
* @return SiteTree
*/
function getPage() {
- $idField = $this->getForm()->dataFieldByName('ID');
+ $idField = $this->getForm()->Fields()->dataFieldByName('ID');
return ($idField && $idField->Value()) ? DataObject::get_by_id('SiteTree', $idField->Value()) : singleton('SiteTree');
}
From a18b9bd85e78028bf458fc97c5d21e8aecee408d Mon Sep 17 00:00:00 2001
From: Wolf Vollprecht
Date: Mon, 19 Mar 2012 02:05:09 +0100
Subject: [PATCH 10/10] ENHANCEMENT: Flyout menu to directly choose the
pagetype one wants to add.
---
code/controllers/CMSMain.php | 24 ++++++++-
code/controllers/CMSPageAddController.php | 14 ++++-
code/model/ErrorPage.php | 4 +-
code/model/RedirectorPage.php | 2 +
javascript/CMSMain.Tree.js | 62 +++++++++++++++--------
templates/CMSPageEditController_Tools.ss | 2 +-
6 files changed, 83 insertions(+), 25 deletions(-)
diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php
index 68e2bd7a..2a92e07a 100644
--- a/code/controllers/CMSMain.php
+++ b/code/controllers/CMSMain.php
@@ -241,7 +241,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
* @return String Serialized JSON
*/
public function SiteTreeHints() {
- $classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
+ $classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
$def['Root'] = array();
$def['Root']['disallowedParents'] = array();
@@ -255,6 +255,26 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
if($allowedChildren == null) $allowedChildren = array();
+
+ // Exclude SiteTree from possible Children
+ $possibleChildren = array_diff($allowedChildren, array("SiteTree"));
+
+ // Find i18n - names and build allowed children array
+ foreach($possibleChildren as $child) {
+ $instance = singleton($child);
+
+ if($instance instanceof HiddenClass) continue;
+
+ if(!$instance->canCreate()) continue;
+
+ // skip this type if it is restricted
+ if($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) continue;
+
+ $title = $instance->i18n_singular_name();
+
+ $def[$class]['allowedChildren'][] = array("ssclass" => $child, "ssname" => $title);
+ }
+
$allowedChildren = array_keys(array_diff($classes, $allowedChildren));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;
@@ -264,6 +284,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$def[$class]['defaultChild'] = $defaultChild;
$defaultParent = $obj->defaultParent();
+
$parent = SiteTree::get_by_link($defaultParent);
$id = $parent ? $parent->id : null;
@@ -368,7 +389,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
$result->sort('AddAction');
-
return $result;
}
diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php
index 95cdbb03..2caa06a0 100644
--- a/code/controllers/CMSPageAddController.php
+++ b/code/controllers/CMSPageAddController.php
@@ -16,6 +16,18 @@ class CMSPageAddController extends CMSPageEditController {
* @return Form
*/
function AddForm() {
+ // If request send from rightclick-submenu, directly add Page
+ if(($pageType = $this->request->getVar('Type')) && ($parentID = $this->request->getVar('ParentID'))) {
+ $data = array(
+ "PageType" => (string)$pageType,
+ "ParentID" => $parentID,
+ "ParentModeField" => "child"
+ );
+ $this->doAdd($data, null);
+ return;
+ }
+
+
$record = $this->currentPage();
$pageTypes = array();
@@ -89,7 +101,7 @@ class CMSPageAddController extends CMSPageEditController {
if($parentID = $this->request->getVar('ParentID')) {
$form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID);
}
-
+
return $form;
}
diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php
index 28af7056..d8973b92 100644
--- a/code/model/ErrorPage.php
+++ b/code/model/ErrorPage.php
@@ -22,6 +22,8 @@ class ErrorPage extends Page {
"ShowInSearch" => 0
);
+ static $allowed_children = array();
+
static $description = 'Custom content for different error cases (e.g. "Page not found")';
protected static $static_filepath = ASSETS_PATH;
@@ -50,7 +52,7 @@ class ErrorPage extends Page {
$response = new SS_HTTPResponse();
$response->setStatusCode($statusCode);
- $response->setBody(file_get_contents($cachedPath));
+ $response->setBody(file_get_contents($cachedPath));
return $response;
}
diff --git a/code/model/RedirectorPage.php b/code/model/RedirectorPage.php
index 08c267f2..9d5c30fe 100644
--- a/code/model/RedirectorPage.php
+++ b/code/model/RedirectorPage.php
@@ -27,6 +27,8 @@ class RedirectorPage extends Page {
static $many_many = array(
);
+ static $allowed_children = array();
+
/**
* Returns this page if the redirect is external, otherwise
* returns the target page.
diff --git a/javascript/CMSMain.Tree.js b/javascript/CMSMain.Tree.js
index 3ba1fe35..4b352cec 100644
--- a/javascript/CMSMain.Tree.js
+++ b/javascript/CMSMain.Tree.js
@@ -1,35 +1,57 @@
(function($) {
$.entwine('ss', function($){
-
$('.cms-tree').entwine({
getTreeConfig: function() {
var config = this._super();
+ var hints = this.getHints();
config.plugins.push('contextmenu');
config.contextmenu = {
- 'items': {
- 'create': null,
- "rename": null,
- "remove": null,
- "ccp": null,
- 'edit': {
- 'label': ss.i18n._t('Tree.EditPage'),
- 'action': function(obj) {
- // TODO Fix hardcoding of link
- $('.cms-container').loadPanel('admin/page/edit/show/' + obj.data('id'));
+ 'items': function(node) {
+ // Build a list for allowed children as submenu entries
+ var ssclass = node.data('ssclass');
+ var id = node.data('id');
+
+ var allowedChildren = new Object;
+ $(hints[ssclass].allowedChildren).each(
+ function(key, val){
+ allowedChildren["allowedchildren-" + key ] = {
+ 'label': '' + val.ssname,
+ '_class': 'class-' + val.ssclass,
+ 'action': function(obj) {
+ // TODO Fix hardcoding of link
+ $('.cms-container').loadPanel('admin/page/add/?ParentID=' + id + '&Type=' + val.ssclass);
+ }
+ };
}
- },
- 'addsubpage': {
- 'label': ss.i18n._t('Tree.AddSubPage'),
- 'action': function(obj) {
- // TODO Fix hardcoding of link
- $('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id'));
- }
- }
- }
+ );
+ var menuitems =
+ {
+ 'edit': {
+ 'label': ss.i18n._t('Tree.EditPage'),
+ 'action': function(obj) {
+ // TODO Fix hardcoding of link
+ $('.cms-container').loadPanel('admin/page/add/show/' + obj.data('id'));
+ }
+ }
+ };
+ // Test if there are any allowed Children and thus the possibility of adding some
+ if(allowedChildren.hasOwnProperty('allowedchildren-0')) {
+ menuitems['addsubpage'] = {
+ 'label': ss.i18n._t('Tree.AddSubPage'),
+ 'action': function(obj) {
+ // TODO Fix hardcoding of link
+ $('.cms-container').loadPanel('admin/page/add/?ParentID=' + obj.data('id'));
+ },
+ 'submenu': allowedChildren
+ };
+ }
+ return menuitems;
+ }
};
return config;
}
});
});
+
}(jQuery));
\ No newline at end of file
diff --git a/templates/CMSPageEditController_Tools.ss b/templates/CMSPageEditController_Tools.ss
index b3ed137a..524daa59 100644
--- a/templates/CMSPageEditController_Tools.ss
+++ b/templates/CMSPageEditController_Tools.ss
@@ -4,7 +4,7 @@