From deadc0665298f18a937fc959da449e9098873c0b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 30 Apr 2015 23:01:28 +0200 Subject: [PATCH 1/3] [ticket/13801] Removed user dependency from text_formatter.s9e.parser PHPBB3-13801 --- .../container/services_text_formatter.yml | 1 - phpBB/includes/message_parser.php | 4 +++ phpBB/phpbb/textformatter/s9e/parser.php | 27 ++++++------------- .../phpbb_test_case_helpers.php | 2 -- tests/text_formatter/s9e/parser_test.php | 10 +------ 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/phpBB/config/default/container/services_text_formatter.yml b/phpBB/config/default/container/services_text_formatter.yml index 972be31b31..20436f0f64 100644 --- a/phpBB/config/default/container/services_text_formatter.yml +++ b/phpBB/config/default/container/services_text_formatter.yml @@ -41,7 +41,6 @@ services: arguments: - @cache.driver - %text_formatter.cache.parser.key% - - @user - @text_formatter.s9e.factory - @dispatcher diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 9fe598d7fb..3edc7fe1c6 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1254,6 +1254,10 @@ class parse_message extends bbcode_firstpass $errors = $parser->get_errors(); if ($errors) { + foreach ($errors as $i => $args) + { + $errors[$i] = call_user_func_array(array($user, 'lang'), $args); + } $this->warn_msg = array_merge($this->warn_msg, $errors); return (!$update_this_message) ? $return_message : $this->warn_msg; diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index e46a0578d2..178669d84f 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -31,21 +31,15 @@ class parser implements \phpbb\textformatter\parser_interface */ protected $parser; - /** - * @var \phpbb\user User object, used for translating errors - */ - protected $user; - /** * Constructor * * @param \phpbb\cache\driver_interface $cache * @param string $key Cache key - * @param \phpbb\user $user * @param factory $factory * @param \phpbb\event\dispatcher_interface $dispatcher */ - public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, \phpbb\user $user, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) + public function __construct(\phpbb\cache\driver\driver_interface $cache, $key, factory $factory, \phpbb\event\dispatcher_interface $dispatcher) { $parser = $cache->get($key); if (!$parser) @@ -56,24 +50,20 @@ class parser implements \phpbb\textformatter\parser_interface $this->dispatcher = $dispatcher; $this->parser = $parser; - $this->user = $user; $parser = $this; /** * Configure the parser service * * Can be used to: - * - toggle features according to the user's preferences, - * - toggle BBCodes according to the user's permissions, * - register variables or custom parsers in the s9e\TextFormatter * - configure the s9e\TextFormatter parser * * @event core.text_formatter_s9e_parser_setup * @var \phpbb\textformatter\s9e\parser parser This parser service - * @var \phpbb\user user Current user * @since 3.2.0-a1 */ - $vars = array('parser', 'user'); + $vars = array('parser'); extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); } @@ -202,7 +192,6 @@ class parser implements \phpbb\textformatter\parser_interface public function get_errors() { $errors = array(); - foreach ($this->parser->getLogger()->get() as $entry) { list($type, $msg, $context) = $entry; @@ -211,29 +200,29 @@ class parser implements \phpbb\textformatter\parser_interface { if ($context['tagName'] === 'E') { - $errors[] = $this->user->lang('TOO_MANY_SMILIES', $context['tagLimit']); + $errors[] = array('TOO_MANY_SMILIES', $context['tagLimit']); } else if ($context['tagName'] === 'URL') { - $errors[] = $this->user->lang('TOO_MANY_URLS', $context['tagLimit']); + $errors[] = array('TOO_MANY_URLS', $context['tagLimit']); } } else if ($msg === 'MAX_FONT_SIZE_EXCEEDED') { - $errors[] = $this->user->lang($msg, $context['max_size']); + $errors[] = array($msg, $context['max_size']); } else if (preg_match('/^MAX_(?:FLASH|IMG)_(HEIGHT|WIDTH)_EXCEEDED$/D', $msg, $m)) { - $errors[] = $this->user->lang($msg, $context['max_' . strtolower($m[1])]); + $errors[] = array($msg, $context['max_' . strtolower($m[1])]); } else if ($msg === 'Tag is disabled') { $name = strtolower($context['tag']->getName()); - $errors[] = $this->user->lang('UNAUTHORISED_BBCODE', '[' . $name . ']'); + $errors[] = array('UNAUTHORISED_BBCODE', '[' . $name . ']'); } else if ($msg === 'UNABLE_GET_IMAGE_SIZE') { - $errors[] = $this->user->lang($msg); + $errors[] = array($msg); } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 685014d3e4..210cda9a94 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -494,11 +494,9 @@ class phpbb_test_case_helpers $parser = new \phpbb\textformatter\s9e\parser( $cache, $cache_key_parser, - $user, $factory, $dispatcher ); - $container->set('text_formatter.parser', $parser); $container->set('text_formatter.s9e.parser', $parser); diff --git a/tests/text_formatter/s9e/parser_test.php b/tests/text_formatter/s9e/parser_test.php index 71966f9d36..3b72e713e1 100644 --- a/tests/text_formatter/s9e/parser_test.php +++ b/tests/text_formatter/s9e/parser_test.php @@ -35,7 +35,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -63,7 +62,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -92,7 +90,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( new phpbb_mock_cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -126,7 +123,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $cache, '_foo_parser', - $this->getMockBuilder('phpbb\\user')->disableOriginalConstructor()->getMock(), $factory, new phpbb_mock_event_dispatcher ); @@ -191,7 +187,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case new \phpbb\textformatter\s9e\parser( $container->get('cache.driver'), '_foo_parser', - $container->get('user'), $container->get('text_formatter.s9e.factory'), $dispatcher ); @@ -200,9 +195,7 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case public function setup_event_callback($vars) { return isset($vars['parser']) - && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser - && isset($vars['user']) - && $vars['user'] instanceof \phpbb\user; + && $vars['parser'] instanceof \phpbb\textformatter\s9e\parser; } /** @@ -236,7 +229,6 @@ class phpbb_textformatter_s9e_parser_test extends phpbb_test_case $parser = new \phpbb\textformatter\s9e\parser( $container->get('cache.driver'), '_foo_parser', - $container->get('user'), $container->get('text_formatter.s9e.factory'), $dispatcher ); From 7b552152b416d9f0c2e873f6f70c4d3cec575ea6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 8 May 2015 14:51:46 +0200 Subject: [PATCH 2/3] [ticket/13801] Updated comments for clarity PHPBB3-13801 --- phpBB/includes/message_parser.php | 1 + phpBB/phpbb/textformatter/parser_interface.php | 3 ++- phpBB/phpbb/textformatter/s9e/parser.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 3edc7fe1c6..496a7885f1 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1256,6 +1256,7 @@ class parse_message extends bbcode_firstpass { foreach ($errors as $i => $args) { + // Translate each error with $user->lang() $errors[$i] = call_user_func_array(array($user, 'lang'), $args); } $this->warn_msg = array_merge($this->warn_msg, $errors); diff --git a/phpBB/phpbb/textformatter/parser_interface.php b/phpBB/phpbb/textformatter/parser_interface.php index 3cb9f8e977..ad611fb5b4 100644 --- a/phpBB/phpbb/textformatter/parser_interface.php +++ b/phpBB/phpbb/textformatter/parser_interface.php @@ -82,7 +82,8 @@ interface parser_interface /** * Get the list of errors that were generated during last parsing * - * @return array + * @return array[] Array of arrays. Each array contains a lang string at index 0 plus any number + * of optional parameters */ public function get_errors(); diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index 178669d84f..ee033f6d21 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -186,7 +186,7 @@ class parser implements \phpbb\textformatter\parser_interface /** * {@inheritdoc} * - * This will translate the log entries found in s9e\TextFormatter's logger into phpBB error + * This will convert the log entries found in s9e\TextFormatter's logger into phpBB error * messages */ public function get_errors() From 5772e06b1aace1d5fbef263217e71ad10347364d Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 17 May 2015 14:09:02 +0200 Subject: [PATCH 3/3] [ticket/13801] Updated event description [ci skip] PHPBB3-13801 --- phpBB/phpbb/textformatter/s9e/parser.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index ee033f6d21..b7d0b2b90b 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -56,8 +56,9 @@ class parser implements \phpbb\textformatter\parser_interface * Configure the parser service * * Can be used to: - * - register variables or custom parsers in the s9e\TextFormatter - * - configure the s9e\TextFormatter parser + * - toggle features or BBCodes + * - register variables or custom parsers in the s9e\TextFormatter parser + * - configure the s9e\TextFormatter parser's runtime settings * * @event core.text_formatter_s9e_parser_setup * @var \phpbb\textformatter\s9e\parser parser This parser service