diff --git a/core/Config.php b/core/Config.php index 847c482d4..ad92f1cfc 100644 --- a/core/Config.php +++ b/core/Config.php @@ -623,6 +623,20 @@ class Config_LRU { $this->indexing = array(); } + public function __clone() { + if (version_compare(PHP_VERSION, '5.3.7', '<')) { + // SplFixedArray causes seg faults before PHP 5.3.7 + $cloned = array(); + } + else { + $cloned = new SplFixedArray(self::SIZE); + } + for ($i = 0; $i < self::SIZE; $i++) { + $cloned[$i] = clone $this->cache[$i]; + } + $this->cache = $cloned; + } + public function set($key, $val, $tags = array()) { // Find an index to set at $replacing = null; diff --git a/docs/en/changelogs/3.1.0.md b/docs/en/changelogs/3.1.0.md index e760b0448..2d08c92d0 100644 --- a/docs/en/changelogs/3.1.0.md +++ b/docs/en/changelogs/3.1.0.md @@ -33,7 +33,7 @@ ## Upgrading -### Static configuration properties are now immutable, you must use Config API. +### Static properties are immutable and private, you must use Config API. A common SilverStripe pattern is to use a static variable on a class to define a configuration parameter. The configuration system added in SilverStripe 3.0 builds on this by using this static variable as a way @@ -75,6 +75,8 @@ Here's an example on how to rewrite a common `_config.php` configuration: SSViewer::set_theme('basic'); } + Object::add_extension('Member', 'MyMemberExtension'); + The ugpraded `_config.php`: :::php @@ -106,6 +108,9 @@ The upgraded `config.yml`: --- SSViewer: theme: 'simple' + Member: + extensions: + MyMemberExtension --- Only: environment: 'live' @@ -121,18 +126,54 @@ Some examples of changed notations (not exhaustive, there's over a hundred in to * `Director::setBaseURL`: Use `Director.alternate_base_url` instead * `SSViewer::setOption('rewriteHashlinks', ...)`: Use `SSViewer.rewrite_hashlinks` instead -**Important**: Please remember to upgrade the installer project as well, particularly +
+Please remember to upgrade the installer project as well, particularly your `.htaccess` or `web.config` files. Web access to these sensitive YAML configuration files needs to be explicitly denied through these configuration files (see the [3.0.5 security release](/changelogs/3.0.4)) for details. - -This change will also affect any visibility modifiers on `SiteTree` subclasses -in your own codebase, since those are further extended by SilverStripe core, -e.g. `ErrorPage extends Page`. Please change all "core statics" like `$db`, `$has_one`, -`$has_many`, `$many_many`, `$defaults`, etc to `private` visibility. +
For more information about how to use the config system, see the ["Configuration" topic](/topic/configuration). +### Statics in custom Page classes need to be "private" + +Related to the configuration change described above, many statics in core are now +marked with `private` visibility. While PHP allows making variables more visible +(e.g. from "private" to "public"), it complains if you try to restrict visibility in subclasses. +The core framework extends from the `Page` class in your own codebase (`mysite/`), +which means you need to change those statics to `private` yourself. +The same rules apply to controllers subclassd from `Page_Controller`. + +Before: + + :::php + 'Text'); + } + class Page_Controller extends ContentController { + static $allowed_actions = array('myaction'); + } + +After: + + :::php + 'Text'); + } + class Page_Controller extends ContentController { + private static $allowed_actions = array('myaction'); + } + +Most statics defined in `SiteTree` and `DataObject` are affected, for example: +`$db`, `$has_one`, `$has_many`, `$many_many`, `$defaults`, `$allowed_children`. +The same goes for statics defined in `ContentController`, e.g. `$allowed_actions`. + +Classes which are not further extended by the core (e.g. all custom `DataObject` subclasses) +are not affected by this change, although we recommend to mark those inherited statics +as `private` as well, to make it clear that they should be accessed through the Config API. + ### default_cast is now Text In order to reduce the chance of accidentally allowing XSS attacks, the value of default_cast diff --git a/docs/en/howto/customize-cms-pages-list.md b/docs/en/howto/customize-cms-pages-list.md index ce7cde39c..d3bb79cd9 100644 --- a/docs/en/howto/customize-cms-pages-list.md +++ b/docs/en/howto/customize-cms-pages-list.md @@ -62,7 +62,11 @@ or across page types with common characteristics. } } +Now you just need to enable the extension in your [configuration file](/topics/configuration). + // mysite/_config/config.yml LeftAndMain: extensions: - - NewsPageHolderCMSMainExtension \ No newline at end of file + - NewsPageHolderCMSMainExtension + +You're all set! Don't forget to flush the caches by appending `?flush=all` to the URL. \ No newline at end of file diff --git a/docs/en/howto/extend-cms-interface.md b/docs/en/howto/extend-cms-interface.md index 827191b1d..58a0ef4bd 100644 --- a/docs/en/howto/extend-cms-interface.md +++ b/docs/en/howto/extend-cms-interface.md @@ -82,10 +82,12 @@ Create a new file called `mysite/code/BookmarkedPageExtension.php` and insert th } } -Enable the extension with the following line in `mysite/_config.php`: +Enable the extension in your [configuration file](/topics/configuration) - :::php - SiteTree::add_extension('BookmarkedPageExtension'); + :::yml + SiteTree: + extensions: + - BookmarkedPageExtension In order to add the field to the database, run a `dev/build/?flush=all`. Refresh the CMS, open a page for editing and you should see the new checkbox. @@ -106,10 +108,12 @@ Add the following code to a new file `mysite/code/BookmarkedLeftAndMainExtension } } -Enable the extension with the following line in `mysite/_config.php`: +Enable the extension in your [configuration file](/topics/configuration) - :::php - LeftAndMain::add_extension('BookmarkedPagesLeftAndMainExtension'); + :::yml + LeftAndMain: + extensions: + - BookmarkedPagesLeftAndMainExtension As the last step, replace the hardcoded links with our list from the database. Find the `