Skip to content

Commit aaa4d58

Browse files
authored
Merge branch 'backdrop:1.x' into 1.x
2 parents 40ad731 + d38a9b8 commit aaa4d58

File tree

263 files changed

+4719
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+4719
-631
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Backdrop aims to provide:
99

1010
Requirements
1111
------------
12-
- PHP 5.6.0 or higher. Even if Backdrop can run on older versions of PHP, we
12+
- PHP 7.1.0 or higher. Even if Backdrop can run on older versions of PHP, we
1313
strongly recommend that you use a
1414
[supported version of PHP](https://secure.php.net/supported-versions.php).
1515
- MySQL 5.5.0 or higher with PDO enabled

core/includes/bootstrap.inc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* The current system version.
99
*/
10-
define('BACKDROP_VERSION', '1.32.x-dev');
10+
define('BACKDROP_VERSION', '1.33.x-dev');
1111

1212
/**
1313
* Core API compatibility.
@@ -1016,8 +1016,8 @@ function backdrop_settings_initialize() {
10161016
// Otherwise use $base_url as session name, without the protocol
10171017
// to use the same session identifiers across HTTP and HTTPS.
10181018
list( , $session_name) = explode('://', $base_url, 2);
1019-
// HTTP_HOST can be modified by a visitor, but we already sanitized it
1020-
// in backdrop_settings_initialize().
1019+
// HTTP_HOST can be modified by a visitor, but we already sanitized it in
1020+
// backdrop_environment_initialize().
10211021
if (!empty($_SERVER['HTTP_HOST'])) {
10221022
$cookie_domain = $_SERVER['HTTP_HOST'];
10231023
// Strip leading periods, www., and port numbers from cookie domain.
@@ -3123,9 +3123,13 @@ function _backdrop_bootstrap_configuration() {
31233123
install_goto('core/install.php');
31243124
}
31253125

3126-
// Untrusted host names, throw an exception for the end-user.
3126+
// Untrusted host names, return 400 Bad Request to the end-user.
31273127
if (!defined('MAINTENANCE_MODE') && !backdrop_check_trusted_hosts($_SERVER['HTTP_HOST'])) {
3128-
throw new Exception(format_string('The HTTP Host "@hostname" is not white-listed for this site. Check the trusted_host_patterns setting in settings.php.', array('@hostname' => $_SERVER['HTTP_HOST'])));
3128+
http_response_code(400);
3129+
print format_string('HTTP Host "@hostname" is not included in the "trusted_host_patterns" setting of this site.', array(
3130+
'@hostname' => $_SERVER['HTTP_HOST'],
3131+
));
3132+
exit;
31293133
}
31303134

31313135
// Bootstrap the database if it is needed but not yet available.

core/includes/config.inc

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,28 +288,57 @@ function config_install_default_config($project, $config_name = NULL) {
288288
}
289289
}
290290
$project_config_dir = $project_path . '/config';
291+
$storage = new ConfigFileStorage($project_config_dir);
292+
293+
$default_config_names = config_get_default_config_names($project);
294+
foreach ($default_config_names as $default_config_name) {
295+
// Load config data into the active store and write it out to the
296+
// file system in the Backdrop config directory. Note the config name
297+
// needs to be the same as the file name WITHOUT the extension.
298+
if (is_null($config_name) || $default_config_name === $config_name) {
299+
$data = $storage->read($default_config_name);
300+
$config = config($default_config_name);
301+
// We only create new configs, and do not overwrite existing ones.
302+
if ($config->isNew()) {
303+
$config->setData($data);
304+
module_invoke_all('config_create', $config);
305+
$config->save();
306+
}
307+
}
308+
}
309+
}
310+
311+
/**
312+
* Gets the name of config files provided by a module or theme.
313+
*
314+
* @param $project
315+
* The name of the project for which config names should be returned.
316+
*
317+
* @return string[]
318+
* An unindexed array of config names, without the .json extension.
319+
*
320+
* @since 1.31.0 Function added.
321+
*/
322+
function config_get_default_config_names($project) {
323+
$project_path = NULL;
324+
foreach (array('module', 'theme') as $project_type) {
325+
if ($project_path = backdrop_get_path($project_type, $project)) {
326+
break;
327+
}
328+
}
329+
330+
$config_names = array();
331+
$project_config_dir = $project_path . '/config';
291332
if (is_dir($project_config_dir)) {
292-
$storage = new ConfigFileStorage($project_config_dir);
293333
$files = glob($project_config_dir . '/*.json');
294334
foreach ($files as $file) {
295-
// Load config data into the active store and write it out to the
296-
// file system in the Backdrop config directory. Note the config name
297-
// needs to be the same as the file name WITHOUT the extension.
298335
$parts = explode('/', $file);
299336
$file = array_pop($parts);
300-
$file_config_name = str_replace('.json', '', $file);
301-
if (is_null($config_name) || $file_config_name === $config_name) {
302-
$data = $storage->read($file_config_name);
303-
$config = config($file_config_name);
304-
// We only create new configs, and do not overwrite existing ones.
305-
if ($config->isNew()) {
306-
$config->setData($data);
307-
module_invoke_all('config_create', $config);
308-
$config->save();
309-
}
310-
}
337+
$config_names[] = str_replace('.json', '', $file);
311338
}
312339
}
340+
341+
return $config_names;
313342
}
314343

315344
/**
@@ -583,7 +612,12 @@ class Config {
583612
*/
584613
public function validateData() {
585614
if (!$this->validated) {
615+
// Get config info if available. This may not be present if the providing
616+
// module is being enabled at the same time.
586617
$config_info = config_get_info($this->getName());
618+
if (!$config_info) {
619+
$config_info = NULL;
620+
}
587621
module_invoke_all('config_data_validate', $this, $config_info);
588622
$this->validated = TRUE;
589623
}

core/includes/file.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,8 @@ function file_save_upload($form_field_name, $validators = array(), $destination
15611561
'filesize' => $_FILES['files']['size'][$form_field_name],
15621562
);
15631563
$values['filemime'] = file_get_mimetype($values['filename']);
1564-
$file = new File($values);
1564+
/** @var File $file */
1565+
$file = entity_create('file', $values);
15651566

15661567
$extensions = '';
15671568
if (isset($validators['file_validate_extensions'])) {
@@ -2123,7 +2124,8 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
21232124

21242125
if ($uri = file_unmanaged_save_data($data, $destination, $replace)) {
21252126
// Create a file entity.
2126-
$file = new File(array(
2127+
/** @var File $file */
2128+
$file = entity_create('file', array(
21272129
'uri' => $uri,
21282130
'uid' => $user->uid,
21292131
'status' => FILE_STATUS_PERMANENT,

core/includes/install.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,17 +1082,24 @@ function backdrop_uninstall_modules($module_list = array(), $uninstall_dependent
10821082
$module_list = array_keys($module_list);
10831083
}
10841084

1085+
$system_extensions_config = config('system.extensions');
10851086
foreach ($module_list as $module) {
10861087
// Uninstall the module.
10871088
module_load_install($module);
10881089
module_invoke($module, 'uninstall');
10891090
config_uninstall_config($module);
10901091
backdrop_uninstall_schema($module);
10911092

1093+
// Remove the module from the system.extensions config.
1094+
$system_extensions_config->clear('modules.' . $module);
1095+
10921096
watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
10931097
backdrop_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
10941098
}
10951099

1100+
// Save the new list of extensions with the modules removed.
1101+
$system_extensions_config->save();
1102+
10961103
if (!empty($module_list)) {
10971104
// Let other modules react.
10981105
module_invoke_all('modules_uninstalled', $module_list);

core/includes/locale.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,12 @@ function locale_language_url_rewrite_url(&$path, &$options) {
486486
case LANGUAGE_NEGOTIATION_URL_PREFIX:
487487
$prefixes = locale_language_negotiation_url_prefixes();
488488
if (!empty($prefixes[$options['language']->langcode])) {
489-
$options['prefix'] = $prefixes[$options['language']->langcode] . '/';
489+
$path = ltrim((string) $path, '/');
490+
$prefix = $prefixes[$options['language']->langcode] . '/';
491+
$options['prefix'] = $prefix;
492+
if (substr($path, 0, strlen($prefix)) == $prefix) {
493+
$path = substr($path, strlen($prefix));
494+
}
490495
}
491496
break;
492497
}

core/includes/module.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
523523

524524
// Record the fact that it was enabled.
525525
$modules_enabled[] = $module;
526+
527+
// Update the status of the module in the system.extensions config.
528+
$config = config('system.extensions');
529+
$modules_in_config = $config->get('modules') != NULL ? $config->get('modules') : array();
530+
$modules_in_config[$module] = TRUE;
531+
$config->set('modules', $modules_in_config);
532+
$config->save();
533+
526534
watchdog('system', '%module module enabled.', array('%module' => $module), WATCHDOG_INFO);
527535
}
528536
}
@@ -608,6 +616,14 @@ function module_disable($module_list, $disable_dependents = TRUE) {
608616
->condition('name', $module)
609617
->execute();
610618
$invoke_modules[] = $module;
619+
620+
// Update the status of the module in the system.extensions config.
621+
$config = config('system.extensions');
622+
$modules_in_config = $config->get('modules') != NULL ? $config->get('modules') : array();
623+
$modules_in_config[$module] = FALSE;
624+
$config->set('modules', $modules_in_config);
625+
$config->save();
626+
611627
watchdog('system', '%module module disabled.', array('%module' => $module), WATCHDOG_INFO);
612628
}
613629
}
@@ -1010,6 +1026,7 @@ function backdrop_merged_modules() {
10101026
'field_formatter_settings', // Backdrop 1.13.0.
10111027
'imagecache_token', // Backdrop 1.17.0.
10121028
'fast_token_browser', // Backdrop 1.30.0.
1029+
'book_cache', // Backdrop 1.32.0.
10131030
);
10141031
}
10151032

core/includes/password.inc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ function user_hash_password($password, $count_log2 = 0) {
232232
*/
233233
function user_check_password($password, $account) {
234234
if (substr($account->pass, 0, 2) == 'U$') {
235+
// This may be an updated password from user_update_7000(). Such hashes
236+
// have 'U' added as the first character and need an extra md5() (see the
237+
// Drupal 7 documentation).
235238
$stored_hash = substr($account->pass, 1);
236239
$password = md5($password);
237240
}
@@ -243,19 +246,21 @@ function user_check_password($password, $account) {
243246
switch ($type) {
244247
case '$S$':
245248
// A normal Backdrop password using sha512.
246-
$hash = _password_crypt('sha512', $password, $stored_hash);
249+
$computed_hash = _password_crypt('sha512', $password, $stored_hash);
247250
break;
248251
case '$H$':
249252
// phpBB3 uses "$H$" for the same thing as "$P$".
250253
case '$P$':
251-
// A phpass password generated using md5. This is an
252-
// imported password or from an earlier Backdrop version.
253-
$hash = _password_crypt('md5', $password, $stored_hash);
254+
// A phpass password generated using md5. This is an imported password or
255+
// from an earlier Backdrop version.
256+
$computed_hash = _password_crypt('md5', $password, $stored_hash);
254257
break;
255258
default:
256259
return FALSE;
257260
}
258-
return ($hash && $stored_hash == $hash);
261+
262+
// To mitigate timing attacks, compare using hash_equals() instead of ===.
263+
return $computed_hash && hash_equals($stored_hash, $computed_hash);
259264
}
260265

261266
/**

core/includes/theme.inc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,15 +1662,28 @@ function _theme_render_template_debug($template_function, $template_file, $varia
16621662
function theme_enable($theme_list) {
16631663
backdrop_clear_css_cache();
16641664

1665-
foreach ($theme_list as $key) {
1665+
foreach ($theme_list as $theme) {
16661666
db_update('system')
16671667
->fields(array('status' => 1))
16681668
->condition('type', 'theme')
1669-
->condition('name', $key)
1669+
->condition('name', $theme)
16701670
->execute();
16711671

16721672
// Copy any default configuration data to the system config directory.
1673-
config_install_default_config($key);
1673+
config_install_default_config($theme);
1674+
1675+
// Update the theme status in the system.extensions config.
1676+
$config = config('system.extensions');
1677+
$themes_in_config = $config->get('themes') != NULL ? $config->get('themes') : array();
1678+
$themes_in_config[$theme] = TRUE;
1679+
1680+
watchdog('system', '%theme theme enabled.', array('%theme' => $theme), WATCHDOG_INFO);
1681+
}
1682+
1683+
// Save the updated config.
1684+
if (isset($config) && isset($themes_in_config)) {
1685+
$config->set('themes', $themes_in_config);
1686+
$config->save();
16741687
}
16751688

16761689
list_themes(TRUE);
@@ -1698,14 +1711,19 @@ function theme_disable($theme_list) {
16981711

16991712
backdrop_clear_css_cache();
17001713

1701-
foreach ($theme_list as $key) {
1714+
foreach ($theme_list as $theme) {
17021715
db_update('system')
17031716
->fields(array('status' => 0))
17041717
->condition('type', 'theme')
1705-
->condition('name', $key)
1718+
->condition('name', $theme)
17061719
->execute();
17071720

1708-
config_uninstall_config($key);
1721+
config_uninstall_config($theme);
1722+
1723+
// Remove the theme from the system.extensions config.
1724+
config_clear('system.extensions', 'themes.' . $theme);
1725+
1726+
watchdog('system', '%theme theme disabled.', array('%theme' => $theme), WATCHDOG_INFO);
17091727
}
17101728

17111729
list_themes(TRUE);

core/modules/admin_bar/css/admin_bar.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@
326326
padding: 0.5em 2em 0.5em 1em; /* LTR */
327327
width: 100%;
328328
box-sizing: border-box;
329+
/* Reinforce the admin bar font so the search input is unaffected by the
330+
theme. */
331+
font: inherit;
332+
line-height: 1.15;
329333
}
330334
[dir="rtl"] #admin-bar .admin-bar-search input {
331335
background-position: left 0.5em center;

0 commit comments

Comments
 (0)