From cb7dabbffc7ea5e2acffaa6fed96ea682f93581d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:13:59 -0400 Subject: [PATCH 1/8] [ticket/10586] Change the interface to an abstract class This allows the common phpBB objects to be automatically accessible to extensions without the author having to globalize and assign each one himself. This is better because it also gives purpose to the phpbb_extension_controller class; instead of just being the way to ensure a handle() method is present, it also does this work for us. PHPBB3-10586 --- phpBB/includes/extension/controller.php | 85 +++++++++++++++++++ .../extension/controller_interface.php | 31 ------- phpBB/index.php | 2 +- phpBB/language/en/common.php | 2 +- 4 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 phpBB/includes/extension/controller.php delete mode 100644 phpBB/includes/extension/controller_interface.php diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php new file mode 100644 index 0000000000..985aded862 --- /dev/null +++ b/phpBB/includes/extension/controller.php @@ -0,0 +1,85 @@ +request =& $request; + $this->db =& $db; + $this->user =& $user; + $this->template =& $template; + $this->config =& $config; + + $this->phpEx = $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Handle the request to display a page from an extension + * + * @return null + */ + abstract public function handle(); +} diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php deleted file mode 100644 index bcc8972db4..0000000000 --- a/phpBB/includes/extension/controller_interface.php +++ /dev/null @@ -1,31 +0,0 @@ -variable('ext', '')) $controller = new $class; - if (!($controller instanceof phpbb_extension_controller_interface)) + if (!($controller instanceof phpbb_extension_controller)) { send_status_line(500, 'Internal Server Error'); trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 94edddc6f5..300529f967 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -186,7 +186,7 @@ $lang = array_merge($lang, array( 'EXPAND_VIEW' => 'Expand view', 'EXTENSION' => 'Extension', 'EXTENSION_CONTROLLER_MISSING' => 'The extension %s is missing a controller class and cannot be accessed through the front-end.', - 'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class %s is not an instance of the phpbb_extension_controller_interface.', + 'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class %s is not an instance of the phpbb_extension_controller.', 'EXTENSION_DISABLED' => 'The extension %s is not enabled.', 'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension %s has been deactivated and can no longer be displayed.', 'EXTENSION_DOES_NOT_EXIST' => 'The extension %s does not exist.', From 9a8b3ff44967bed2dbc5400986e55e124e9018ab Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:21:17 -0400 Subject: [PATCH 2/8] [ticket/10586] Make the abstract class implement the original interface PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- .../extension/controller_interface.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/extension/controller_interface.php diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 985aded862..e7d4427c87 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * * @package extension */ -abstract class phpbb_extension_controller +abstract class phpbb_extension_controller implements phpbb_extension_controller_interface { /** * @var phpbb_request Request class object diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php new file mode 100644 index 0000000000..bcc8972db4 --- /dev/null +++ b/phpBB/includes/extension/controller_interface.php @@ -0,0 +1,31 @@ + Date: Wed, 28 Mar 2012 16:23:40 -0400 Subject: [PATCH 3/8] [ticket/10586] Do not pass as reference PHPBB3-10586 --- phpBB/includes/extension/controller.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index e7d4427c87..6e47948156 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -66,12 +66,11 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; - $this->request =& $request; - $this->db =& $db; - $this->user =& $user; - $this->template =& $template; - $this->config =& $config; - + $this->request = $request; + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->config = $config; $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } From 7b091f18a83f4bc31fc00ef067b55db48137ef47 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:37:42 -0400 Subject: [PATCH 4/8] [ticket/10586] Remove handle() from abstract class, undo change in index.php PHPBB3-10586 --- phpBB/includes/extension/controller.php | 7 ------- phpBB/includes/extension/controller_interface.php | 2 +- phpBB/index.php | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 6e47948156..8861ec2696 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -74,11 +74,4 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } - - /** - * Handle the request to display a page from an extension - * - * @return null - */ - abstract public function handle(); } diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php index bcc8972db4..2b88925388 100644 --- a/phpBB/includes/extension/controller_interface.php +++ b/phpBB/includes/extension/controller_interface.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) interface phpbb_extension_controller_interface { /** - * handle the request to display a page from an extension + * Handle the request to display a page from an extension * * @return null */ diff --git a/phpBB/index.php b/phpBB/index.php index 8b73f0008f..d71878a885 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -47,7 +47,7 @@ if ($ext = $request->variable('ext', '')) $controller = new $class; - if (!($controller instanceof phpbb_extension_controller)) + if (!($controller instanceof phpbb_extension_controller_interface)) { send_status_line(500, 'Internal Server Error'); trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); From c44d77b03148122dceb33c0bf30858013bbffd38 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:39:30 -0400 Subject: [PATCH 5/8] [ticket/10586] Undo change in language/en/common.php PHPBB3-10586 --- phpBB/language/en/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 300529f967..94edddc6f5 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -186,7 +186,7 @@ $lang = array_merge($lang, array( 'EXPAND_VIEW' => 'Expand view', 'EXTENSION' => 'Extension', 'EXTENSION_CONTROLLER_MISSING' => 'The extension %s is missing a controller class and cannot be accessed through the front-end.', - 'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class %s is not an instance of the phpbb_extension_controller.', + 'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class %s is not an instance of the phpbb_extension_controller_interface.', 'EXTENSION_DISABLED' => 'The extension %s is not enabled.', 'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension %s has been deactivated and can no longer be displayed.', 'EXTENSION_DOES_NOT_EXIST' => 'The extension %s does not exist.', From 35805a27408f4d25987c3f8df5c9bf54b15a19f3 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:48:16 -0400 Subject: [PATCH 6/8] [ticket/10586] Moved some loading stuff below extension controller, updated tests PHPBB3-10586 --- phpBB/index.php | 7 +++++-- tests/functional/fixtures/ext/error/class/controller.php | 7 +++---- .../functional/fixtures/ext/error/disabled/controller.php | 7 +++---- tests/functional/fixtures/ext/foo/bar/controller.php | 7 +++---- tests/functional/fixtures/ext/foobar/controller.php | 7 +++---- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/phpBB/index.php b/phpBB/index.php index d71878a885..9a57105d57 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -17,12 +17,11 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($phpbb_root_path . 'includes/functions_display.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); -$user->setup('viewforum'); +$user->setup(); // Handle the display of extension front pages if ($ext = $request->variable('ext', '')) @@ -57,6 +56,10 @@ if ($ext = $request->variable('ext', '')) exit_handler(); } +include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + +$user->add_lang('viewforum'); + display_forums('', $config['load_moderators']); $order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php index eb2ae362a6..99849584bc 100644 --- a/tests/functional/fixtures/ext/error/class/controller.php +++ b/tests/functional/fixtures/ext/error/class/controller.php @@ -1,13 +1,12 @@ set_ext_dir_prefix($phpbb_root_path . 'ext/error/class/'); + $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/error/class/'); - $template->set_filenames(array( + $this->template->set_filenames(array( 'body' => 'index_body.html' )); diff --git a/tests/functional/fixtures/ext/error/disabled/controller.php b/tests/functional/fixtures/ext/error/disabled/controller.php index b83a949020..ef2edda3de 100644 --- a/tests/functional/fixtures/ext/error/disabled/controller.php +++ b/tests/functional/fixtures/ext/error/disabled/controller.php @@ -1,13 +1,12 @@ set_ext_dir_prefix($phpbb_root_path . 'ext/error/disabled/'); + $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/error/disabled/'); - $template->set_filenames(array( + $this->template->set_filenames(array( 'body' => 'index_body.html' )); diff --git a/tests/functional/fixtures/ext/foo/bar/controller.php b/tests/functional/fixtures/ext/foo/bar/controller.php index 24d218c412..1910a4da88 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller.php @@ -1,13 +1,12 @@ set_ext_dir_prefix($phpbb_root_path . 'ext/foo/bar/'); + $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/foo/bar/'); - $template->set_filenames(array( + $this->template->set_filenames(array( 'body' => 'foobar_body.html' )); diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php index bf8d8139ae..5161b28fe8 100644 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ b/tests/functional/fixtures/ext/foobar/controller.php @@ -1,13 +1,12 @@ set_ext_dir_prefix($phpbb_root_path . 'ext/foobar/'); + $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/foobar/'); - $template->set_filenames(array( + $this->template->set_filenames(array( 'body' => 'foobar_body.html' )); From afc55b4c08ca891e11e2aba15dce1f9b5b7c481a Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:50:18 -0400 Subject: [PATCH 7/8] [ticket/10586] Added visibility indication to __construct() PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 8861ec2696..c7fd439a19 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -61,7 +61,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ * Constructor method that provides the common phpBB objects as inherited class * properties for automatic availability in extension controllers */ - function __construct() + public function __construct() { global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; From caf47f8e19da9e725702fe5a6c09f10be23dd473 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 20:21:54 -0400 Subject: [PATCH 8/8] [ticket/10586] Removed incorrect method call PHPBB3-10586 --- tests/functional/fixtures/ext/error/class/controller.php | 2 -- tests/functional/fixtures/ext/error/classtype/controller.php | 2 -- tests/functional/fixtures/ext/error/disabled/controller.php | 4 +--- tests/functional/fixtures/ext/foo/bar/controller.php | 2 -- tests/functional/fixtures/ext/foobar/controller.php | 2 -- 5 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php index 99849584bc..74bbbee540 100644 --- a/tests/functional/fixtures/ext/error/class/controller.php +++ b/tests/functional/fixtures/ext/error/class/controller.php @@ -4,8 +4,6 @@ class phpbb_ext_foobar_controller extends phpbb_extension_controller { public function handle() { - $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/error/class/'); - $this->template->set_filenames(array( 'body' => 'index_body.html' )); diff --git a/tests/functional/fixtures/ext/error/classtype/controller.php b/tests/functional/fixtures/ext/error/classtype/controller.php index 2276548b55..55ac651bdf 100644 --- a/tests/functional/fixtures/ext/error/classtype/controller.php +++ b/tests/functional/fixtures/ext/error/classtype/controller.php @@ -5,8 +5,6 @@ class phpbb_ext_error_classtype_controller public function handle() { global $template; - $template->set_ext_dir_prefix($phpbb_root_path . 'ext/error/classtype/'); - $template->set_filenames(array( 'body' => 'index_body.html' )); diff --git a/tests/functional/fixtures/ext/error/disabled/controller.php b/tests/functional/fixtures/ext/error/disabled/controller.php index ef2edda3de..57b913f377 100644 --- a/tests/functional/fixtures/ext/error/disabled/controller.php +++ b/tests/functional/fixtures/ext/error/disabled/controller.php @@ -3,9 +3,7 @@ class phpbb_ext_error_disabled_controller extends phpbb_extension_controller { public function handle() - { - $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/error/disabled/'); - + { $this->template->set_filenames(array( 'body' => 'index_body.html' )); diff --git a/tests/functional/fixtures/ext/foo/bar/controller.php b/tests/functional/fixtures/ext/foo/bar/controller.php index 1910a4da88..3375e317b3 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller.php @@ -4,8 +4,6 @@ class phpbb_ext_foo_bar_controller extends phpbb_extension_controller { public function handle() { - $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/foo/bar/'); - $this->template->set_filenames(array( 'body' => 'foobar_body.html' )); diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php index 5161b28fe8..ff35f12ee0 100644 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ b/tests/functional/fixtures/ext/foobar/controller.php @@ -4,8 +4,6 @@ class phpbb_ext_foobar_controller extends phpbb_extension_controller { public function handle() { - $this->template->set_ext_dir_prefix($this->phpbb_root_path . 'ext/foobar/'); - $this->template->set_filenames(array( 'body' => 'foobar_body.html' ));