Skip to content

Commit

Permalink
chore(config): Removes several $CONFIG keys and deprecated APIs
Browse files Browse the repository at this point in the history
Fixes #8524

BREAKING CHANGE:
Several internal data structures are no longer stored within the plugin-
accessible config space; the removed keys are listed in docs/guides/upgrading.rst.
The long-deprecated remove_blacklist() function has also been removed.
  • Loading branch information
mrclay committed Jun 23, 2015
1 parent 8b3ea65 commit 2247ed8
Show file tree
Hide file tree
Showing 28 changed files with 228 additions and 565 deletions.
16 changes: 15 additions & 1 deletion docs/guides/upgrading.rst
Expand Up @@ -224,14 +224,27 @@ Messages will no longer get the metadata 'msg' for newly created messages. This
Removed Classes Removed Classes
--------------- ---------------


- ``ElggInspector``
- ``FilePluginFile``: replace with ``ElggFile`` (or load with ``get_entity()``) - ``FilePluginFile``: replace with ``ElggFile`` (or load with ``get_entity()``)


Removed keys available via ``elgg_get_config()`` Removed keys available via ``elgg_get_config()``
------------------------------------------------ ------------------------------------------------


- ``allowed_ajax_views``
- ``dataroot_in_settings``
- ``externals``
- ``externals_map``
- ``i18n_loaded_from_cache``
- ``language_paths``
- ``pagesetupdone``
- ``registered_tag_metadata_names``
- ``simplecache_enabled_in_settings``
- ``translations``
- ``viewpath``
- ``views`` - ``views``
- ``view_path``
- ``viewtype`` - ``viewtype``
- ``viewpath`` - ``wordblacklist``


Also note that plugins should not be accessing the global ``$CONFIG`` variable except for in ``settings.php``. Also note that plugins should not be accessing the global ``$CONFIG`` variable except for in ``settings.php``.


Expand All @@ -244,6 +257,7 @@ Removed Functions
- ``get_db_link()`` - ``get_db_link()``
- ``load_plugins()`` - ``load_plugins()``
- ``mysql_*()``: Elgg :ref:`no longer uses ext/mysql<migrated-to-pdo>` - ``mysql_*()``: Elgg :ref:`no longer uses ext/mysql<migrated-to-pdo>`
- ``remove_blacklist()``
- ``set_template_handler()`` - ``set_template_handler()``


Removed Plugin Hooks Removed Plugin Hooks
Expand Down
142 changes: 69 additions & 73 deletions docs/info/config.php
Expand Up @@ -8,70 +8,13 @@
* @subpackage Configuration * @subpackage Configuration
*/ */


/**
* Paths to scan for autoloading languages.
*
* Languages are automatically loaded for the site or
* user's default language. Plugins can extend or override strings.
* language_paths is an array of paths to scan for PHP files matching
* the default language. The order of paths is determined by the plugin load order,
* with later entries overriding earlier. Language files within these paths are
* named as the two-letter ISO 639-1 country codes for the language they represent.
*
* Language paths are stored as array keys in the format:
* <code>
* $CONFIG->language_paths[str $language_path] = true
* </code>
*
* @link http://en.wikipedia.org/wiki/ISO_639-1
* @see register_language()
* @global array $CONFIG->language_paths
*/
$CONFIG->language_paths;


/**
* String translations for the current language.
*
* Elgg uses a key-based system for string internationalization, which
* is accessed with {@link elgg_echo()}.
*
* Translations are stored as an array in the following format:
* <code>
* $CONFIG->translations[str $language_code][str $string_key] = str 'Translated Language String';
* </code>
*
* @see register_translation()
* @see elgg_echo()
* @global array $CONFIG->translations
*/
$CONFIG->translations;

/**
* An array of metadata names to be used as tags.
*
* Because tags are simply names of meatdata, This is used
* in search to prevent data exposure by searching on
* arbitrary metadata.
*
* @global array $CONFIG->registered_tag_metadata_names
*/
$CONFIG->registered_tag_metadata_names;

/** /**
* The full path where Elgg is installed. * The full path where Elgg is installed.
* *
* @global string $CONFIG->path; * @global string $CONFIG->path;
*/ */
$CONFIG->path; $CONFIG->path;


/**
* The full path for core views.
*
* @global string $CONFIG->view_path
*/
$CONFIG->view_path;

/** /**
* The full path where plugins are stored. * The full path where plugins are stored.
* *
Expand Down Expand Up @@ -235,13 +178,6 @@
*/ */
$CONFIG->menu_items_custom_items; $CONFIG->menu_items_custom_items;


/**
* A list of valid view types as discovered.
*
* @global array $CONFIG->view_types
*/
$CONFIG->view_types;

/** /**
* A list of plugins and their load order * A list of plugins and their load order
* *
Expand Down Expand Up @@ -278,14 +214,6 @@
*/ */
$CONFIG->servicehandler; $CONFIG->servicehandler;


/**
* A list of stop works for search. Not currently used.
*
* @global array $CONFIG->wordblacklist
* @todo currently unused.
*/
$CONFIG->wordblacklist;

/** /**
* A list of menu contexts for menus registered with {@link add_menu()}. Not currently used. * A list of menu contexts for menus registered with {@link add_menu()}. Not currently used.
* *
Expand Down Expand Up @@ -336,4 +264,72 @@
* *
* @global string $CONFIG->exception_include * @global string $CONFIG->exception_include
*/ */
$CONFIG->exception_include = ''; $CONFIG->exception_include = '';

/**
* Paths to scan for autoloading languages.
*
* Languages are automatically loaded for the site or
* user's default language. Plugins can extend or override strings.
* language_paths is an array of paths to scan for PHP files matching
* the default language. The order of paths is determined by the plugin load order,
* with later entries overriding earlier. Language files within these paths are
* named as the two-letter ISO 639-1 country codes for the language they represent.
*
* Language paths are stored as array keys in the format:
* <code>
* $_ELGG->language_paths[str $language_path] = true
* </code>
*
* @link http://en.wikipedia.org/wiki/ISO_639-1
* @see register_language()
* @global array $_ELGG->language_paths
* @access private
*/
$_ELGG->language_paths;

/**
* String translations for the current language.
*
* Elgg uses a key-based system for string internationalization, which
* is accessed with {@link elgg_echo()}.
*
* Translations are stored as an array in the following format:
* <code>
* $_ELGG->translations[str $language_code][str $string_key] = str 'Translated Language String';
* </code>
*
* @see register_translation()
* @see elgg_echo()
* @global array $_ELGG->translations
* @access private
*/
$_ELGG->translations;

/**
* An array of metadata names to be used as tags.
*
* Because tags are simply names of meatdata, This is used
* in search to prevent data exposure by searching on
* arbitrary metadata.
*
* @global array $_ELGG->registered_tag_metadata_names
* @access private
*/
$_ELGG->registered_tag_metadata_names;

/**
* The full path for core views.
*
* @global string $_ELGG->view_path
* @access private
*/
$_ELGG->view_path;

/**
* A list of valid view types as discovered.
*
* @global array $_ELGG->view_types
* @access private
*/
$_ELGG->view_types;
12 changes: 12 additions & 0 deletions engine/classes/Elgg/Application.php
Expand Up @@ -79,6 +79,18 @@ public function __construct(ServiceProvider $services = null) {
$START_MICROTIME = microtime(true); $START_MICROTIME = microtime(true);
} }


/**
* This was introduced in 2.0 in order to remove all internal non-API state from $CONFIG. This will
* be a breaking change, but frees us to refactor in 2.x without fear of plugins depending on
* $CONFIG.
*
* @access private
*/
global $_ELGG;
if (!isset($_ELGG)) {
$_ELGG = new \stdClass();
}

$this->engine_dir = dirname(dirname(__DIR__)); $this->engine_dir = dirname(dirname(__DIR__));
$this->install_dir = dirname($this->engine_dir); $this->install_dir = dirname($this->engine_dir);
} }
Expand Down
4 changes: 2 additions & 2 deletions engine/classes/Elgg/Application/CacheHandler.php
Expand Up @@ -311,13 +311,13 @@ protected function renderView($view, $viewtype) {
// disable error reporting so we don't cache problems // disable error reporting so we don't cache problems
$this->config->set('debug', null); $this->config->set('debug', null);


// @todo elgg_view() checks if the page set is done (isset($CONFIG->pagesetupdone)) and // @todo elgg_view() checks if the page set is done (isset($GLOBALS['_ELGG']->pagesetupdone)) and
// triggers an event if it's not. Calling elgg_view() here breaks submenus // triggers an event if it's not. Calling elgg_view() here breaks submenus
// (at least) because the page setup hook is called before any // (at least) because the page setup hook is called before any
// contexts can be correctly set (since this is called before page_handler()). // contexts can be correctly set (since this is called before page_handler()).
// To avoid this, lie about $CONFIG->pagehandlerdone to force // To avoid this, lie about $CONFIG->pagehandlerdone to force
// the trigger correctly when the first view is actually being output. // the trigger correctly when the first view is actually being output.
$this->config->set('pagesetupdone', true); $GLOBALS['_ELGG']->pagesetupdone = true;


return elgg_view($view); return elgg_view($view);
} }
Expand Down
54 changes: 27 additions & 27 deletions engine/classes/Elgg/Assets/ExternalFiles.php
Expand Up @@ -64,7 +64,7 @@ public function register($type, $name, $url, $location, $priority = 500) {
// no negative priorities right now. // no negative priorities right now.
$priority = max((int)$priority, 0); $priority = max((int)$priority, 0);


$item = elgg_extract($name, $this->CONFIG->externals_map[$type]); $item = elgg_extract($name, $GLOBALS['_ELGG']->externals_map[$type]);


if ($item) { if ($item) {
// updating a registered item // updating a registered item
Expand All @@ -73,21 +73,21 @@ public function register($type, $name, $url, $location, $priority = 500) {
$item->location = $location; $item->location = $location;


// if loaded before registered, that means it hasn't been added to the list yet // if loaded before registered, that means it hasn't been added to the list yet
if ($this->CONFIG->externals[$type]->contains($item)) { if ($GLOBALS['_ELGG']->externals[$type]->contains($item)) {
$priority = $this->CONFIG->externals[$type]->move($item, $priority); $priority = $GLOBALS['_ELGG']->externals[$type]->move($item, $priority);
} else { } else {
$priority = $this->CONFIG->externals[$type]->add($item, $priority); $priority = $GLOBALS['_ELGG']->externals[$type]->add($item, $priority);
} }
} else { } else {
$item = new \stdClass(); $item = new \stdClass();
$item->loaded = false; $item->loaded = false;
$item->url = $url; $item->url = $url;
$item->location = $location; $item->location = $location;


$priority = $this->CONFIG->externals[$type]->add($item, $priority); $priority = $GLOBALS['_ELGG']->externals[$type]->add($item, $priority);
} }

$this->CONFIG->externals_map[$type][$name] = $item; $GLOBALS['_ELGG']->externals_map[$type][$name] = $item;


return $priority !== false; return $priority !== false;
} }
Expand All @@ -105,11 +105,11 @@ public function unregister($type, $name) {
$this->bootstrap($type); $this->bootstrap($type);


$name = trim(strtolower($name)); $name = trim(strtolower($name));
$item = elgg_extract($name, $this->CONFIG->externals_map[$type]); $item = elgg_extract($name, $GLOBALS['_ELGG']->externals_map[$type]);


if ($item) { if ($item) {
unset($this->CONFIG->externals_map[$type][$name]); unset($GLOBALS['_ELGG']->externals_map[$type][$name]);
return $this->CONFIG->externals[$type]->remove($item); return $GLOBALS['_ELGG']->externals[$type]->remove($item);
} }


return false; return false;
Expand All @@ -130,7 +130,7 @@ public function load($type, $name) {


$name = trim(strtolower($name)); $name = trim(strtolower($name));


$item = elgg_extract($name, $this->CONFIG->externals_map[$type]); $item = elgg_extract($name, $GLOBALS['_ELGG']->externals_map[$type]);


if ($item) { if ($item) {
// update a registered item // update a registered item
Expand All @@ -140,9 +140,9 @@ public function load($type, $name) {
$item->loaded = true; $item->loaded = true;
$item->url = ''; $item->url = '';
$item->location = ''; $item->location = '';

$this->CONFIG->externals[$type]->add($item); $GLOBALS['_ELGG']->externals[$type]->add($item);
$this->CONFIG->externals_map[$type][$name] = $item; $GLOBALS['_ELGG']->externals_map[$type][$name] = $item;
} }
} }


Expand All @@ -158,11 +158,11 @@ public function getLoadedFiles($type, $location) {




if ( if (
isset($this->CONFIG->externals) isset($GLOBALS['_ELGG']->externals)
&& isset($this->CONFIG->externals[$type]) && isset($GLOBALS['_ELGG']->externals[$type])
&& $this->CONFIG->externals[$type] instanceof \ElggPriorityList && $GLOBALS['_ELGG']->externals[$type] instanceof \ElggPriorityList
) { ) {
$items = $this->CONFIG->externals[$type]->getElements(); $items = $GLOBALS['_ELGG']->externals[$type]->getElements();


$items = array_filter($items, function($v) use ($location) { $items = array_filter($items, function($v) use ($location) {
return $v->loaded == true && $v->location == $location; return $v->loaded == true && $v->location == $location;
Expand All @@ -178,27 +178,27 @@ public function getLoadedFiles($type, $location) {
} }


/** /**
* Bootstraps the externals data structure in $CONFIG. * Bootstraps the externals data structure in $_ELGG.
* *
* @param string $type The type of external, js or css. * @param string $type The type of external, js or css.
* @return null * @return null
*/ */
protected function bootstrap($type) { protected function bootstrap($type) {


if (!isset($this->CONFIG->externals)) { if (!isset($GLOBALS['_ELGG']->externals)) {
$this->CONFIG->externals = array(); $GLOBALS['_ELGG']->externals = array();
} }


if (!isset($this->CONFIG->externals[$type]) || !$this->CONFIG->externals[$type] instanceof \ElggPriorityList) { if (!isset($GLOBALS['_ELGG']->externals[$type]) || !$GLOBALS['_ELGG']->externals[$type] instanceof \ElggPriorityList) {
$this->CONFIG->externals[$type] = new \ElggPriorityList(); $GLOBALS['_ELGG']->externals[$type] = new \ElggPriorityList();
} }


if (!isset($this->CONFIG->externals_map)) { if (!isset($GLOBALS['_ELGG']->externals_map)) {
$this->CONFIG->externals_map = array(); $GLOBALS['_ELGG']->externals_map = array();
} }


if (!isset($this->CONFIG->externals_map[$type])) { if (!isset($GLOBALS['_ELGG']->externals_map[$type])) {
$this->CONFIG->externals_map[$type] = array(); $GLOBALS['_ELGG']->externals_map[$type] = array();
} }
} }
} }

0 comments on commit 2247ed8

Please sign in to comment.