From 2c92123ca59d044c33de3d8e04b02451b008670d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 25 Sep 2013 15:59:50 +0200 Subject: [PATCH 01/23] [ticket/11862] Correct var names in user_delete() events due to prune-users The prune-users feature modified the names of the used variables in this function. However, the variable names for the two events in this function were not changed to reflect that. This patch will take care of it. PHPBB3-11862 --- phpBB/includes/functions_user.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 4fcce67801..383a0b9d97 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -388,12 +388,13 @@ function user_delete($mode, $user_ids, $retain_username = true) * Event before a user is deleted * * @event core.delete_user_before - * @var string mode Mode of deletion (retain/delete posts) - * @var int user_id ID of the deleted user - * @var mixed post_username Guest username that is being used or false + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_ids IDs of the deleted user + * @var mixed retain_username True if username should be retained + * or false if not * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'post_username'); + $vars = array('mode', 'user_ids', 'retain_username'); extract($phpbb_dispatcher->trigger_event('core.delete_user_before', compact($vars))); // Before we begin, we will remove the reports the user issued. @@ -616,12 +617,13 @@ function user_delete($mode, $user_ids, $retain_username = true) * Event after a user is deleted * * @event core.delete_user_after - * @var string mode Mode of deletion (retain/delete posts) - * @var int user_id ID of the deleted user - * @var mixed post_username Guest username that is being used or false + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_id IDs of the deleted user + * @var mixed retain_username True if username should be retained + * or false if not * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'post_username'); + $vars = array('mode', 'user_ids', 'retain_username'); extract($phpbb_dispatcher->trigger_event('core.delete_user_after', compact($vars))); // Reset newest user info if appropriate From a7af736b9776d724fd2ca77b84b6623eba3edaef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 14 Jul 2013 10:35:19 -0400 Subject: [PATCH 02/23] [ticket/11691] Stagger the convertion of soft delete updates PHPBB3-11691 --- .../db/migration/data/v310/softdelete_p1.php | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index 0418d5cc2b..27bf5b6a57 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -101,7 +101,8 @@ class softdelete_p1 extends \phpbb\db\migration\migration return array( array('custom', array(array($this, 'update_post_visibility'))), array('custom', array(array($this, 'update_topic_visibility'))), - array('custom', array(array($this, 'update_topic_forum_counts'))), + array('custom', array(array($this, 'update_topics_post_counts'))), + array('custom', array(array($this, 'update_forums_topic_and_post_counts'))), array('permission.add', array('f_softdelete', false)), array('permission.add', array('m_softdelete', false)), @@ -122,7 +123,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration $this->sql_query($sql); } - public function update_topic_forum_counts() + public function update_topics_post_counts() { $sql = 'UPDATE ' . $this->table_prefix . 'topics SET topic_posts_approved = topic_replies + 1, @@ -135,15 +136,24 @@ class softdelete_p1 extends \phpbb\db\migration\migration topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 WHERE topic_visibility = ' . ITEM_UNAPPROVED; $this->sql_query($sql); + } + + public function update_forums_topic_and_post_counts($start) + { + $start = (int) $start; + $limit = 2; + $i = 0; $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics GROUP BY forum_id, topic_visibility'; - $result = $this->db->sql_query($sql); + $result = $this->db->sql_query_limit($sql, $start, $limit); $update_forums = array(); while ($row = $this->db->sql_fetchrow($result)) { + $i++; + $forum_id = (int) $row['forum_id']; if (!isset($update_forums[$forum_id])) { @@ -169,5 +179,15 @@ class softdelete_p1 extends \phpbb\db\migration\migration WHERE forum_id = ' . $forum_id; $this->sql_query($sql); } + + + if ($i < $limit) + { + // There are no more topics, we are done + return; + } + + // There are still more topics to query, return the next start value + return $start + $limit; } } From 29c84be40a8c60fe98ba6bd2e817fcef14b491ba Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 4 Aug 2013 23:44:41 +0200 Subject: [PATCH 03/23] [ticket/11691] Stagger user notification reconversion even more PHPBB3-11691 --- .../v310/notification_options_reconvert.php | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index bd7614e1c2..16509d7833 100644 --- a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -23,12 +23,19 @@ class notification_options_reconvert extends \phpbb\db\migration\migration ); } - public function convert_notifications() + public function convert_notifications($start) { $insert_table = $this->table_prefix . 'user_notifications'; $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $insert_table); - $this->perform_conversion($insert_buffer, $insert_table); + $start = (int) $start; + if ($start == 0) + { + $sql = 'DELETE FROM ' . $insert_table; + $this->db->sql_query($sql); + } + + return $this->perform_conversion($insert_buffer, $insert_table, $start); } /** @@ -37,17 +44,19 @@ class notification_options_reconvert extends \phpbb\db\migration\migration * @param \phpbb\db\sql_insert_buffer $insert_buffer * @param string $insert_table */ - public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $insert_table) + public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $insert_table, $start) { - $sql = 'DELETE FROM ' . $insert_table; - $this->db->sql_query($sql); + $limit = 250; + $converted_users = 0; $sql = 'SELECT user_id, user_notify_type, user_notify_pm - FROM ' . USERS_TABLE; - $result = $this->db->sql_query($sql); + FROM ' . USERS_TABLE . ' + ORDER BY user_id'; + $result = $this->db->sql_query_limit($sql, $limit, $start); while ($row = $this->db->sql_fetchrow($result)) { + $converted_users++; $notification_methods = array(); // In-board notification @@ -91,6 +100,14 @@ class notification_options_reconvert extends \phpbb\db\migration\migration $this->db->sql_freeresult($result); $insert_buffer->flush(); + + if ($converted_users < $limit) + { + // No more users left, we are done... + return; + } + + return $start + $limit; } /** From f8d6f0ef08f96c55c6934e60349aa5ff5ea00528 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Aug 2013 17:05:52 +0200 Subject: [PATCH 04/23] [ticket/11691] Change detection of effectively_installed() When start is set for a migration, it is not yet effectively installed. So we just continue doing it... PHPBB3-11691 --- phpBB/phpbb/db/migrator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index d7d2b3df59..7efb23a230 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -208,7 +208,7 @@ class migrator if (!isset($this->migration_state[$name])) { - if ($migration->effectively_installed()) + if ($state['migration_start_time'] == 0 && $migration->effectively_installed()) { $state = array( 'migration_depends_on' => $migration->depends_on(), @@ -227,6 +227,8 @@ class migrator } } + $this->set_migration_state($name, $state); + if (!$state['migration_schema_done']) { $this->apply_schema_changes($migration->update_schema()); From a7cf62decf4e4e4d2c73ad7b4f91d40c681784fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Aug 2013 17:07:31 +0200 Subject: [PATCH 05/23] [ticket/11691] Fix some more problems with softdelete update * wrong order of arguments on sql_query_limit * avoid "BIGINT UNSIGNED value is out of range" errors * increase limit for the loop PHPBB3-11691 --- .../phpbb/db/migration/data/v310/softdelete_p1.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index 27bf5b6a57..cdf61569b8 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -125,15 +125,20 @@ class softdelete_p1 extends \phpbb\db\migration\migration public function update_topics_post_counts() { + /* + * Using sql_case here, to avoid "BIGINT UNSIGNED value is out of range" errors. + * As we update all topics in 2 queries, one broken topic would stop the conversion + * for all topics and the surpressed error will cause the admin to not even notice it. + */ $sql = 'UPDATE ' . $this->table_prefix . 'topics SET topic_posts_approved = topic_replies + 1, - topic_posts_unapproved = topic_replies_real - topic_replies + topic_posts_unapproved = ' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ' WHERE topic_visibility = ' . ITEM_APPROVED; $this->sql_query($sql); $sql = 'UPDATE ' . $this->table_prefix . 'topics SET topic_posts_approved = 0, - topic_posts_unapproved = (topic_replies_real - topic_replies) + 1 + topic_posts_unapproved = (' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ') + 1 WHERE topic_visibility = ' . ITEM_UNAPPROVED; $this->sql_query($sql); } @@ -141,13 +146,13 @@ class softdelete_p1 extends \phpbb\db\migration\migration public function update_forums_topic_and_post_counts($start) { $start = (int) $start; - $limit = 2; + $limit = 10; $i = 0; $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics GROUP BY forum_id, topic_visibility'; - $result = $this->db->sql_query_limit($sql, $start, $limit); + $result = $this->db->sql_query_limit($sql, $limit, $start); $update_forums = array(); while ($row = $this->db->sql_fetchrow($result)) From e7c43dbb6796d75445b50b0062d6e32cf650b3cd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Aug 2013 18:53:05 +0200 Subject: [PATCH 06/23] [ticket/11691] Fix some minor comments PHPBB3-11691 --- phpBB/phpbb/db/migration/data/v310/softdelete_p1.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index cdf61569b8..a93171d931 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -147,7 +147,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration { $start = (int) $start; $limit = 10; - $i = 0; + $converted_forums = 0; $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics @@ -157,7 +157,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration $update_forums = array(); while ($row = $this->db->sql_fetchrow($result)) { - $i++; + $converted_forums++; $forum_id = (int) $row['forum_id']; if (!isset($update_forums[$forum_id])) @@ -185,8 +185,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration $this->sql_query($sql); } - - if ($i < $limit) + if ($converted_forums < $limit) { // There are no more topics, we are done return; From eace91af203e21fa82d054d42fc2117fa1230763 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Aug 2013 10:30:23 +0200 Subject: [PATCH 07/23] [ticket/11691] Add order by to the query PHPBB3-11691 --- phpBB/phpbb/db/migration/data/v310/softdelete_p1.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index a93171d931..14bd5f52fb 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -151,7 +151,8 @@ class softdelete_p1 extends \phpbb\db\migration\migration $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved FROM ' . $this->table_prefix . 'topics - GROUP BY forum_id, topic_visibility'; + GROUP BY forum_id, topic_visibility + ORDER BY forum_id, topic_visibility'; $result = $this->db->sql_query_limit($sql, $limit, $start); $update_forums = array(); From 3b7abb98e1178733054d91d260e8a6329ddaecca Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Aug 2013 10:31:05 +0200 Subject: [PATCH 08/23] [ticket/11691] Fix typo in comment PHPBB3-11691 --- phpBB/phpbb/db/migration/data/v310/softdelete_p1.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php index 14bd5f52fb..f080c78c50 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_p1.php @@ -126,7 +126,7 @@ class softdelete_p1 extends \phpbb\db\migration\migration public function update_topics_post_counts() { /* - * Using sql_case here, to avoid "BIGINT UNSIGNED value is out of range" errors. + * Using sql_case here to avoid "BIGINT UNSIGNED value is out of range" errors. * As we update all topics in 2 queries, one broken topic would stop the conversion * for all topics and the surpressed error will cause the admin to not even notice it. */ From 8aa9f1d3abe4ec2ad7d7692d70d19c4accb6ec43 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Aug 2013 10:34:26 +0200 Subject: [PATCH 09/23] [ticket/11691] Move purge code into new function PHPBB3-11691 --- .../data/v310/notification_options_reconvert.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index 16509d7833..a4962b177d 100644 --- a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -19,22 +19,22 @@ class notification_options_reconvert extends \phpbb\db\migration\migration public function update_data() { return array( + array('custom', array(array($this, 'purge_notifications'))), array('custom', array(array($this, 'convert_notifications'))), ); } + public function purge_notifications() + { + $sql = 'DELETE FROM ' . $insert_table; + $this->sql_query($sql); + } + public function convert_notifications($start) { $insert_table = $this->table_prefix . 'user_notifications'; $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $insert_table); - $start = (int) $start; - if ($start == 0) - { - $sql = 'DELETE FROM ' . $insert_table; - $this->db->sql_query($sql); - } - return $this->perform_conversion($insert_buffer, $insert_table, $start); } From 07186656c8ea73a3e303998d465f08cc9f4598c4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 20 Aug 2013 00:35:34 +0200 Subject: [PATCH 10/23] [ticket/11691] Fix table names and arguments/docs PHPBB3-11691 --- .../data/v310/notification_options_reconvert.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index a4962b177d..4195623618 100644 --- a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -26,31 +26,31 @@ class notification_options_reconvert extends \phpbb\db\migration\migration public function purge_notifications() { - $sql = 'DELETE FROM ' . $insert_table; + $sql = 'DELETE FROM ' . $this->table_prefix . 'user_notifications'; $this->sql_query($sql); } public function convert_notifications($start) { - $insert_table = $this->table_prefix . 'user_notifications'; - $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $insert_table); + $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications'); - return $this->perform_conversion($insert_buffer, $insert_table, $start); + return $this->perform_conversion($insert_buffer, $start); } /** * Perform the conversion (separate for testability) * - * @param \phpbb\db\sql_insert_buffer $insert_buffer - * @param string $insert_table + * @param \phpbb\db\sql_insert_buffer $insert_buffer + * @param int $start Start of staggering step + * @return mixed int start of the next step, null if the end was reached */ - public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $insert_table, $start) + public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $start) { $limit = 250; $converted_users = 0; $sql = 'SELECT user_id, user_notify_type, user_notify_pm - FROM ' . USERS_TABLE . ' + FROM ' . $this->table_prefix . 'users ORDER BY user_id'; $result = $this->db->sql_query_limit($sql, $limit, $start); From 7525c49d454e1ff4a156709ea9ecc1dc0b28dd6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2013 15:34:44 +0200 Subject: [PATCH 11/23] [ticket/11852] Split filesystem and path_helper into 2 classes PHPBB3-11852 --- phpBB/app.php | 1 + phpBB/common.php | 19 +-- phpBB/config/services.yml | 16 +- phpBB/includes/bbcode.php | 4 +- phpBB/includes/functions.php | 27 ++-- phpBB/includes/functions_content.php | 4 +- phpBB/includes/functions_messenger.php | 4 +- phpBB/install/index.php | 4 +- phpBB/phpbb/filesystem.php | 145 ------------------ phpBB/phpbb/template/asset.php | 10 +- phpBB/phpbb/template/twig/environment.php | 22 +-- .../phpbb/template/twig/node/includeasset.php | 2 +- phpBB/phpbb/template/twig/twig.php | 22 +-- tests/controller/helper_url_test.php | 10 +- tests/dbal/migrator_test.php | 8 +- tests/extension/manager_test.php | 8 +- tests/extension/metadata_manager_test.php | 11 +- tests/filesystem/clean_path_test.php | 8 +- tests/filesystem/web_root_path_test.php | 12 +- tests/mock/extension_manager.php | 8 +- tests/template/template_events_test.php | 5 +- tests/template/template_includecss_test.php | 4 +- tests/template/template_includejs_test.php | 26 ++-- tests/template/template_test_case.php | 5 +- .../template/template_test_case_with_tree.php | 5 +- .../phpbb_functional_test_case.php | 8 +- 26 files changed, 108 insertions(+), 290 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index f1023ff1b5..7dc778e3a8 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -25,6 +25,7 @@ $auth->acl($user->data); $user->setup('app'); $http_kernel = $phpbb_container->get('http_kernel'); +$symfony_request = $phpbb_container->get('symfony_request'); $response = $http_kernel->handle($symfony_request); $response->send(); $http_kernel->terminate($symfony_request, $response); diff --git a/phpBB/common.php b/phpBB/common.php index 80375f7a9c..6bb3509ea1 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -47,19 +47,7 @@ if (!defined('PHPBB_INSTALLED')) // Eliminate . and .. from the path require($phpbb_root_path . 'phpbb/filesystem.' . $phpEx); - require($phpbb_root_path . 'phpbb/symfony_request.' . $phpEx); - require($phpbb_root_path . 'phpbb/request/deactivated_super_global.' . $phpEx); - require($phpbb_root_path . 'phpbb/request/type_cast_helper_interface.' . $phpEx); - require($phpbb_root_path . 'phpbb/request/type_cast_helper.' . $phpEx); - require($phpbb_root_path . 'phpbb/request/request_interface.' . $phpEx); - require($phpbb_root_path . 'phpbb/request/request.' . $phpEx); - $phpbb_filesystem = new phpbb\filesystem( - new phpbb\symfony_request( - new phpbb\request\request() - ), - $phpbb_root_path, - $phpEx - ); + $phpbb_filesystem = new phpbb\filesystem(); $script_path = $phpbb_filesystem->clean_path($script_path); $url = (($secure) ? 'https://' : 'http://') . $server_name; @@ -121,16 +109,13 @@ $db = $phpbb_container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function -// Create a Symfony Request object from our phpbb_request object -$symfony_request = $phpbb_container->get('symfony_request'); -$phpbb_filesystem = $phpbb_container->get('filesystem'); - // Grab global variables, re-cache if necessary $config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); $phpbb_log = $phpbb_container->get('log'); +$phpbb_path_helper = $phpbb_container->get('path_helper'); // load extensions $phpbb_extension_manager = $phpbb_container->get('ext.manager'); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index e33db0c2bc..51ae5c454d 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -169,11 +169,6 @@ services: filesystem: class: phpbb\filesystem - arguments: - - @symfony_request - - %core.root_path% - - %core.php_ext% - - %core.adm_relative_path% groupposition.legend: class: phpbb\groupposition\legend @@ -251,6 +246,15 @@ services: - %tables.notifications% - %tables.user_notifications% + path_helper: + class: phpbb\path_helper + arguments: + - @symfony_request + - @filesystem + - %core.root_path% + - %core.php_ext% + - %core.adm_relative_path% + php_ini: class: phpbb\php\ini @@ -265,7 +269,7 @@ services: template: class: phpbb\template\twig\twig arguments: - - @filesystem + - @path_helper - @config - @user - @template_context diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index cd2ca7ffce..c4076a0120 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -126,13 +126,13 @@ class bbcode */ function bbcode_cache_init() { - global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager, $phpbb_filesystem; + global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager, $phpbb_path_helper; if (empty($this->template_filename)) { $this->template_bitfield = new bitfield($user->style['bbcode_bitfield']); - $template = new phpbb\template\twig\twig($phpbb_filesystem, $config, $user, new phpbb\template\context(), $phpbb_extension_manager); + $template = new phpbb\template\twig\twig($phpbb_path_helper, $config, $user, new phpbb\template\context(), $phpbb_extension_manager); $template->set_style(); $template->set_filenames(array('bbcode.html' => 'bbcode.html')); $this->template_filename = $template->get_source_file_for_handle('bbcode.html'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b3e50847fd..28c03534ea 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1056,31 +1056,32 @@ else */ function phpbb_clean_path($path) { - global $phpbb_container; + global $phpbb_path_helper, $phpbb_container; - if ($phpbb_container) + if (!$phpbb_path_helper && $phpbb_container) { - $phpbb_filesystem = $phpbb_container->get('filesystem'); + $phpbb_path_helper = $phpbb_container->get('path_helper'); } - else + else if (!$phpbb_path_helper) { // The container is not yet loaded, use a new instance - if (!class_exists('\phpbb\filesystem')) + if (!class_exists('\phpbb\path_helper')) { global $phpbb_root_path, $phpEx; - require($phpbb_root_path . 'includes/filesystem.' . $phpEx); + require($phpbb_root_path . 'phpbb/path_helper.' . $phpEx); } - $phpbb_filesystem = new phpbb\filesystem( + $phpbb_path_helper = new phpbb\path_helper( new phpbb\symfony_request( new phpbb\request\request() ), + new phpbb\filesystem(), $phpbb_root_path, $phpEx ); } - return $phpbb_filesystem->clean_path($path); + return $phpbb_path_helper->clean_path($path); } // functions used for building option fields @@ -2445,7 +2446,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star */ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { - global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_filesystem; + global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_path_helper; global $phpbb_dispatcher; if ($params === '' || (is_array($params) && empty($params))) @@ -2455,9 +2456,9 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) } // Update the root path with the correct relative web path - if ($phpbb_filesystem instanceof \phpbb\filesystem) + if ($phpbb_path_helper instanceof \phpbb\path_helper) { - $url = $phpbb_filesystem->update_web_root_path($url); + $url = $phpbb_path_helper->update_web_root_path($url); } $append_sid_overwrite = false; @@ -5276,8 +5277,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // This path is sent with the base template paths in the assign_vars() // call below. We need to correct it in case we are accessing from a // controller because the web paths will be incorrect otherwise. - $phpbb_filesystem = $phpbb_container->get('filesystem'); - $corrected_path = $phpbb_filesystem->get_web_root_path(); + $phpbb_path_helper = $phpbb_container->get('path_helper'); + $corrected_path = $phpbb_path_helper->get_web_root_path(); $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; // Send a proper content-language to the output diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 7ecc99b39c..863450a4b2 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -834,7 +834,7 @@ function bbcode_nl2br($text) */ function smiley_text($text, $force_option = false) { - global $config, $user, $phpbb_filesystem; + global $config, $user, $phpbb_path_helper; if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) { @@ -842,7 +842,7 @@ function smiley_text($text, $force_option = false) } else { - $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_filesystem->get_web_root_path(); + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_path_helper->get_web_root_path(); return preg_replace('#write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_filesystem());\n") + ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n") ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") ->indent() ->write("\$asset_path = \$asset->get_path();") diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 2da7405743..9df9310427 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -33,10 +33,10 @@ class twig extends \phpbb\template\base private $cachepath = ''; /** - * phpBB filesystem - * @var \phpbb\filesystem + * phpBB path helper + * @var \phpbb\path_helper */ - protected $phpbb_filesystem; + protected $path_helper; /** * phpBB root path @@ -79,17 +79,17 @@ class twig extends \phpbb\template\base /** * Constructor. * - * @param \phpbb\filesystem $phpbb_filesystem + * @param \phpbb\path_helper $path_helper * @param \phpbb\config\config $config * @param \phpbb\user $user * @param \phpbb\template\context $context template context * @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked */ - public function __construct(\phpbb\filesystem $phpbb_filesystem, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null) + public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null) { - $this->phpbb_filesystem = $phpbb_filesystem; - $this->phpbb_root_path = $phpbb_filesystem->get_phpbb_root_path(); - $this->php_ext = $phpbb_filesystem->get_php_ext(); + $this->path_helper = $path_helper; + $this->phpbb_root_path = $path_helper->get_phpbb_root_path(); + $this->php_ext = $path_helper->get_php_ext(); $this->config = $config; $this->user = $user; $this->context = $context; @@ -103,7 +103,7 @@ class twig extends \phpbb\template\base $this->twig = new \phpbb\template\twig\environment( $this->config, ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(), - $this->phpbb_filesystem, + $this->path_helper, $loader, array( 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath, @@ -125,9 +125,9 @@ class twig extends \phpbb\template\base $this->twig->setLexer($lexer); // Add admin namespace - if ($this->phpbb_filesystem->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/')) + if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) { - $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/', 'admin'); + $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/', 'admin'); } } diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 4ea177074f..33fc6c4f1b 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -49,14 +49,15 @@ class phpbb_controller_helper_url_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->user = $this->getMock('\phpbb\user'); - $phpbb_filesystem = new \phpbb\filesystem( + $phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $phpbb_root_path, $phpEx ); - $this->template = new phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $config, $this->user, new \phpbb\template\context()); // We don't use mod_rewrite in these tests $config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); @@ -101,14 +102,15 @@ class phpbb_controller_helper_url_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->user = $this->getMock('\phpbb\user'); - $phpbb_filesystem = new \phpbb\filesystem( + $phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $phpbb_root_path, $phpEx ); - $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + $this->template = new \phpbb\template\twig\twig($phpbb_path_helper, $config, $this->user, new \phpbb\template\context()); $config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $helper = new \phpbb\controller\helper($this->template, $this->user, $config, '', 'php'); diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index ef5d167fc2..c6b4c289d3 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -59,13 +59,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb\filesystem( - new phpbb\symfony_request( - new phpbb_mock_request() - ), - dirname(__FILE__) . '/../../phpBB/', - 'php' - ), + new phpbb\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index c4a32f53ab..b127daf2ed 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -114,13 +114,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $container, $db, $config, - new \phpbb\filesystem( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - $phpbb_root_path, - $php_ext - ), + new \phpbb\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 2b27a1bae2..242ec38908 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -41,10 +41,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->table_prefix = 'phpbb_'; $this->template = new \phpbb\template\twig\twig( - new \phpbb\filesystem( + new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $this->phpbb_root_path, $this->phpEx ), @@ -70,13 +71,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, - new \phpbb\filesystem( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - $this->phpbb_root_path, - $this->phpEx - ), + new \phpbb\filesystem(), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 5b9857ef2c..fedadc103b 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -14,13 +14,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new \phpbb\filesystem( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - dirname(__FILE__) . './../../phpBB/', - 'php' - ); + $this->filesystem = new \phpbb\filesystem(); } public function clean_path_data() diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index e0f716cdae..ebc99669ce 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,10 +18,11 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $this->filesystem = new \phpbb\filesystem( + $this->path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $this->phpbb_root_path, 'php' ); @@ -43,7 +44,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case public function test_get_web_root_path() { // Symfony Request = null, so always should return phpbb_root_path - $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); + $this->assertEquals($this->phpbb_root_path, $this->path_helper->get_web_root_path()); } public function basic_update_web_root_path_data() @@ -71,7 +72,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case */ public function test_basic_update_web_root_path($input, $expected) { - $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $this->path_helper->update_web_root_path($input, $symfony_request)); } public function update_web_root_path_data() @@ -131,12 +132,13 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ->method('getScriptName') ->will($this->returnValue($getScriptName)); - $filesystem = new \phpbb\filesystem( + $path_helper = new \phpbb\path_helper( $symfony_request, + new \phpbb\filesystem(), $this->phpbb_root_path, 'php' ); - $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $path_helper->update_web_root_path($input, $symfony_request)); } } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 0c6b8447f1..7049cbdc50 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -14,12 +14,6 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; - $this->filesystem = new \phpbb\filesystem( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - $this->phpbb_root_path, - $this->php_ext - ); + $this->filesystem = new \phpbb\filesystem(); } } diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 4155d5fd83..41e00e86a7 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -116,14 +116,15 @@ Zeta test event in all', $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" ); - $phpbb_filesystem = new \phpbb\filesystem( + $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $phpbb_root_path, $phpEx ); - $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $user, new \phpbb\template\context, $this->extension_manager); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, new \phpbb\template\context, $this->extension_manager); $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); } } diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index c00aa8e9bb..7424af0c93 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -18,8 +18,8 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te // Prepare correct result $scripts = array( - '', - '', + '', + '', ); // Run test diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 2faeb5fcaa..ab0f4b9ca1 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -24,51 +24,51 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes */ array( array('TEST' => 1), - '', + '', ), array( array('TEST' => 2), - '', + '', ), array( array('TEST' => 3), - '', + '', ), array( array('TEST' => 4), - '', + '', ), array( array('TEST' => 6), - '', + '', ), array( array('TEST' => 7), - '', + '', ), array( array('TEST' => 8), - '', + '', ), array( array('TEST' => 9), - '', + '', ), array( array('TEST' => 10), - '', + '', ), array( array('TEST' => 11), - '', + '', ), array( array('TEST' => 12), - '', + '', ), array( array('TEST' => 14), - '', + '', ), array( array('TEST' => 15), @@ -84,7 +84,7 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes ), array( array('TEST' => 18), - '', + '', ), ); } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index e9cbdec1d9..c75b1e5065 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -63,16 +63,17 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new \phpbb\config\config(array_merge($defaults, $new_config)); $this->user = new \phpbb\user; - $phpbb_filesystem = new \phpbb\filesystem( + $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $phpbb_root_path, $phpEx ); $this->template_path = $this->test_path . '/templates'; - $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $this->user, new \phpbb\template\context()); + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context()); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 232331d37c..e614c42d73 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -18,17 +18,18 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $this->phpbb_filesystem = new \phpbb\filesystem( + $this->phpbb_path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( new phpbb_mock_request() ), + new \phpbb\filesystem(), $phpbb_root_path, $phpEx ); $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; - $this->template = new phpbb\template\twig\twig($this->phpbb_filesystem, $config, $user, new phpbb\template\context()); + $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, new phpbb\template\context()); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f87b3538a1..a0d186e0f2 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -203,13 +203,7 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, - new phpbb\filesystem( - new phpbb\symfony_request( - new phpbb_mock_request() - ), - $phpbb_root_path, - $php_ext - ), + new phpbb\filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', $php_ext, From c7a9d5e34a27794b93cc3a1c248a49af2b8488ee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2013 15:35:53 +0200 Subject: [PATCH 12/23] [ticket/11852] Move tests to folder with new class name PHPBB3-11852 --- tests/{filesystem => path_helper}/web_root_path_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{filesystem => path_helper}/web_root_path_test.php (97%) diff --git a/tests/filesystem/web_root_path_test.php b/tests/path_helper/web_root_path_test.php similarity index 97% rename from tests/filesystem/web_root_path_test.php rename to tests/path_helper/web_root_path_test.php index ebc99669ce..938b58892b 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/path_helper/web_root_path_test.php @@ -7,9 +7,9 @@ * */ -class phpbb_filesystem_web_root_path_test extends phpbb_test_case +class phpbb_path_helper_web_root_path_test extends phpbb_test_case { - protected $filesystem; + protected $path_helper; protected $phpbb_root_path = ''; public function setUp() From 213e7563ad4565b322680ce2f3526a7130d2a90e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 Sep 2013 00:08:54 +0200 Subject: [PATCH 13/23] [ticket/11852] Add class file PHPBB3-11852 --- phpBB/phpbb/path_helper.php | 175 ++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 phpBB/phpbb/path_helper.php diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php new file mode 100644 index 0000000000..b2ed11a927 --- /dev/null +++ b/phpBB/phpbb/path_helper.php @@ -0,0 +1,175 @@ +symfony_request = $symfony_request; + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->adm_relative_path = $adm_relative_path; + } + + /** + * Get the phpBB root path + * + * @return string + */ + public function get_phpbb_root_path() + { + return $this->phpbb_root_path; + } + + /** + * Get the adm root path + * + * @return string + */ + public function get_adm_relative_path() + { + return $this->adm_relative_path; + } + + /** + * Get the php extension + * + * @return string + */ + public function get_php_ext() + { + return $this->php_ext; + } + + /** + * Update a path to the correct relative root path + * + * This replaces $phpbb_root_path . some_url with + * get_web_root_path() . some_url OR if $phpbb_root_path + * is not at the beginning of $path, just prepends the + * web root path + * + * @param string $path The path to be updated + * @return string + */ + public function update_web_root_path($path) + { + $web_root_path = $this->get_web_root_path($this->symfony_request); + + if (strpos($path, $this->phpbb_root_path) === 0) + { + $path = substr($path, strlen($this->phpbb_root_path)); + } + + return $web_root_path . $path; + } + + /** + * Get a relative root path from the current URL + * + * @return string + */ + public function get_web_root_path() + { + if ($this->symfony_request === null) + { + return $this->phpbb_root_path; + } + + if (null !== $this->web_root_path) + { + return $this->web_root_path; + } + + // Path info (e.g. /foo/bar) + $path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo()); + + // Full request URI (e.g. phpBB/app.php/foo/bar) + $request_uri = $this->symfony_request->getRequestUri(); + + // Script name URI (e.g. phpBB/app.php) + $script_name = $this->symfony_request->getScriptName(); + + /* + * If the path info is empty (single /), then we're not using + * a route like app.php/foo/bar + */ + if ($path_info === '/') + { + return $this->web_root_path = $this->phpbb_root_path; + } + + // How many corrections might we need? + $corrections = substr_count($path_info, '/'); + + /* + * If the script name (e.g. phpBB/app.php) exists in the + * requestUri (e.g. phpBB/app.php/foo/template), then we + * are have a non-rewritten URL. + */ + if (strpos($request_uri, $script_name) === 0) + { + /* + * Append ../ to the end of the phpbb_root_path as many times + * as / exists in path_info + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); + } + + /* + * If we're here it means we're at a re-written path, so we must + * correct the relative path for web URLs. We must append ../ + * to the end of the root path as many times as / exists in path_info + * less one time (because the script, e.g. /app.php, doesn't exist in + * the URL) + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); + } +} From 9dc9214ebb2d671d8b02208ea64362705064a405 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 27 Sep 2013 13:32:37 +0200 Subject: [PATCH 14/23] [ticket/11862] Correct var names in user_delete() events due to prune-users Fix comments after incorrect merge of previous PR. PHPBB3-11862 --- phpBB/includes/functions_user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index fc04d57fa0..0a0656377c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -389,7 +389,7 @@ function user_delete($mode, $user_ids, $retain_username = true) * * @event core.delete_user_before * @var string mode Mode of deletion (retain/delete posts) - * @var int user_ids IDs of the deleted user + * @var array user_ids IDs of the deleted user * @var mixed retain_username True if username should be retained * or false if not * @since 3.1-A1 @@ -618,7 +618,7 @@ function user_delete($mode, $user_ids, $retain_username = true) * * @event core.delete_user_after * @var string mode Mode of deletion (retain/delete posts) - * @var int user_id IDs of the deleted user + * @var array user_ids IDs of the deleted user * @var mixed retain_username True if username should be retained * or false if not * @since 3.1-A1 From cba28c39ad63920c05241f59ce7e1ad6b47039df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 Sep 2013 01:18:28 +0200 Subject: [PATCH 15/23] [ticket/11873] Do not hash very large passwords in order to safe resources. PHPBB3-11873 --- phpBB/includes/functions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b2b12c1445..eef4ade4e7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -502,6 +502,13 @@ function phpbb_hash($password) */ function phpbb_check_hash($password, $hash) { + if (strlen($password) > 4096) + { + // If the password is too huge, we will simply reject it + // and not let the server try to hash it. + return false; + } + $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; if (strlen($hash) == 34) { From c6aefcf555b51e7bcf00332290c9d94beddec02c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 Sep 2013 01:19:55 +0200 Subject: [PATCH 16/23] [ticket/11873] Add unit test for large password input. The password should be rejected quite fast. PHPBB3-11873 --- tests/security/hash_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php index 0c2580c19b..e226365ef3 100644 --- a/tests/security/hash_test.php +++ b/tests/security/hash_test.php @@ -17,5 +17,13 @@ class phpbb_security_hash_test extends phpbb_test_case $this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); $this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); } + + public function test_check_hash_with_large_input() + { + // 16 MB password, should be rejected quite fast + $start_time = time(); + $this->assertFalse(phpbb_check_hash(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); + $this->assertLessThanOrEqual(5, time() - $start_time); + } } From 446ea9928d8373cf7695d3adda6d5ee30d5f94b4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 28 Sep 2013 03:20:51 +0200 Subject: [PATCH 17/23] [prep-release-3.0.12] Update changelog for 3.0.12 release. --- phpBB/docs/CHANGELOG.html | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 6d8b39d524..71795f83ac 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -218,6 +218,7 @@
  • [PHPBB3-11368] - Latest pm reports row count
  • [PHPBB3-11583] - InnoDB supports FULLTEXT index since MySQL 5.6.4.
  • [PHPBB3-11740] - Update link in FAQ to Ideas Centre
  • +
  • [PHPBB3-11873] - Prevent expensive hash computation in phpbb_check_hash() by rejecting very long passwords
  • Sub-task

      From ac4736db0887e986a322f7f92429430333525a24 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 30 Sep 2013 17:04:14 +0200 Subject: [PATCH 18/23] [develop-olympus] Build against 3.0.12 instead of 3.0.12-RC3. Tag exists now. --- build/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.xml b/build/build.xml index 7b87830da3..40d875cb95 100644 --- a/build/build.xml +++ b/build/build.xml @@ -3,7 +3,7 @@ - + From da9756ba2553abdcc87130ec892e589ded1c1256 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 30 Sep 2013 18:04:38 +0200 Subject: [PATCH 19/23] [ticket/11876] Move checksum generation from build PHP files to phing build.xml This also removes paths from the checksum files. PHPBB3-11876 --- build/build.xml | 18 ++++++++++++++++++ build/build_diff.php | 3 --- build/package.php | 12 ------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/build/build.xml b/build/build.xml index 40d875cb95..a861ebc205 100644 --- a/build/build.xml +++ b/build/build.xml @@ -149,6 +149,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/build/build_diff.php b/build/build_diff.php index 0824b53caa..d264ecf493 100755 --- a/build/build_diff.php +++ b/build/build_diff.php @@ -83,9 +83,6 @@ if (!$echo_changes) // Build Package run_command("$compress_command ./../../new_version/release_files/{$code_changes_filename}.{$extension} *"); - - // Build MD5 Sum - run_command("md5sum ./../../new_version/release_files/{$code_changes_filename}.{$extension} > ./../../new_version/release_files/{$code_changes_filename}.{$extension}.md5"); flush(); } } diff --git a/build/package.php b/build/package.php index 48f42b3572..22ea4e52af 100755 --- a/build/package.php +++ b/build/package.php @@ -285,9 +285,6 @@ if (sizeof($package->old_packages)) // Build Package $package->run_command($compress_command . ' ../release_files/' . $package->get('release_filename') . '-patch.' . $extension . ' *'); - - // Build MD5 Sum - $package->run_command('md5sum ../release_files/' . $package->get('release_filename') . '-patch.' . $extension . ' > ../release_files/' . $package->get('release_filename') . '-patch.' . $extension . '.md5'); } // Build Files Package @@ -319,8 +316,6 @@ if (sizeof($package->old_packages)) chdir('./release'); $package->run_command("$compress_command ../../release_files/" . $package->get('release_filename') . '-files.' . $extension . ' *'); - // Build MD5 Sum - $package->run_command('md5sum ../../release_files/' . $package->get('release_filename') . '-files.' . $extension . ' > ../../release_files/' . $package->get('release_filename') . '-files.' . $extension . '.md5'); chdir('..'); $package->run_command('rm -Rv ' . $package->get('files_directory') . '/release'); @@ -363,9 +358,6 @@ if (sizeof($package->old_packages)) // Copy last package over... $package->run_command('rm -v ../release_files/phpBB-' . $last_version . ".$extension"); $package->run_command("$compress_command ../../release_files/phpBB-$last_version.$extension *"); - - // Build MD5 Sum - $package->run_command("md5sum ../../release_files/phpBB-$last_version.$extension > ../../release_files/phpBB-$last_version.$extension.md5"); chdir('..'); } @@ -388,9 +380,6 @@ foreach ($compress_programs as $extension => $compress_command) // Build Package $package->run_command("$compress_command ./release_files/" . $package->get('release_filename') . '.' . $extension . ' ' . $package->get('package_name')); - - // Build MD5 Sum - $package->run_command('md5sum ./release_files/' . $package->get('release_filename') . '.' . $extension . ' > ./release_files/' . $package->get('release_filename') . '.' . $extension . '.md5'); } // Microsoft Web PI packaging @@ -398,7 +387,6 @@ $package->begin_status('Packaging phpBB for Microsoft WebPI'); $file = './release_files/' . $package->get('release_filename') . '.webpi.zip'; $package->run_command('cp -p ./release_files/' . $package->get('release_filename') . ".zip $file"); $package->run_command('cd ./../webpi && ' . $compress_programs['zip'] . " ./../new_version/$file *"); -$package->run_command("md5sum $file > $file.md5"); // verify results chdir($package->locations['root']); From 0cf9d657b7c56e602248d5998a49b7d392b16d39 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 30 Sep 2013 18:09:27 +0200 Subject: [PATCH 20/23] [ticket/11876] Replace MD5 with SHA256. PHPBB3-11876 --- build/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.xml b/build/build.xml index a861ebc205..f0962e67eb 100644 --- a/build/build.xml +++ b/build/build.xml @@ -166,7 +166,7 @@ - + From 7aadcd547244455a9d3a8539cf6d243ec36a8be5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Oct 2013 09:56:24 +0200 Subject: [PATCH 21/23] [ticket/11691] Fix conversion test PHPBB3-11691 --- tests/notification/convert_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index ed1fa9b1bf..c692f40b57 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -38,7 +38,7 @@ class phpbb_notification_convert_test extends phpbb_database_test_case public function test_convert() { $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); - $this->migration->perform_conversion($buffer, 'phpbb_user_notifications'); + $this->migration->perform_conversion($buffer, 0); $expected = array_merge( $this->create_expected('post', 1, 'email'), From 9503b4d5295884c6e47509d5251956a16e0497a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 2 Oct 2013 00:12:29 -0500 Subject: [PATCH 22/23] [ticket/11878] Missing leading \ in dependencies in soft_delete_mcp_modules PHPBB3-11878 --- phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php index 2db9780601..d1a31815b2 100644 --- a/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php +++ b/phpBB/phpbb/db/migration/data/v310/softdelete_mcp_modules.php @@ -28,8 +28,8 @@ class softdelete_mcp_modules extends \phpbb\db\migration\migration static public function depends_on() { return array( - 'phpbb\db\migration\data\v310\dev', - 'phpbb\db\migration\data\v310\softdelete_p2', + '\phpbb\db\migration\data\v310\dev', + '\phpbb\db\migration\data\v310\softdelete_p2', ); } From a79d0e6758715ba8a9bb00e8942058c8fc4696f4 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 2 Oct 2013 11:12:41 +0300 Subject: [PATCH 23/23] [ticket/11879] Replace .live() with .on() PHPBB3-11879 --- phpBB/styles/prosilver/template/forum_fn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/forum_fn.js b/phpBB/styles/prosilver/template/forum_fn.js index 240fe7e51d..6a65caf6f6 100644 --- a/phpBB/styles/prosilver/template/forum_fn.js +++ b/phpBB/styles/prosilver/template/forum_fn.js @@ -403,7 +403,7 @@ function apply_onkeypress_event() // jQuery code in case jQuery is used if (jquery_present) { - jQuery('form input[type=text], form input[type=password]').live('keypress', function (e) + jQuery('form input[type=text], form input[type=password]').on('keypress', function (e) { var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');