aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/helper/iohandler
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/install/helper/iohandler')
-rw-r--r--phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php509
-rw-r--r--phpBB/phpbb/install/helper/iohandler/cli_iohandler.php323
-rw-r--r--phpBB/phpbb/install/helper/iohandler/exception/iohandler_not_implemented_exception.php19
-rw-r--r--phpBB/phpbb/install/helper/iohandler/factory.php79
-rw-r--r--phpBB/phpbb/install/helper/iohandler/iohandler_base.php209
-rw-r--r--phpBB/phpbb/install/helper/iohandler/iohandler_interface.php222
6 files changed, 1361 insertions, 0 deletions
diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php
new file mode 100644
index 0000000000..2a608f504e
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php
@@ -0,0 +1,509 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler;
+
+use phpbb\path_helper;
+use phpbb\routing\router;
+
+/**
+ * Input-Output handler for the AJAX frontend
+ */
+class ajax_iohandler extends iohandler_base
+{
+ /**
+ * @var path_helper
+ */
+ protected $path_helper;
+
+ /**
+ * @var \phpbb\request\request_interface
+ */
+ protected $request;
+
+ /**
+ * @var \phpbb\template\template
+ */
+ protected $template;
+
+ /**
+ * @var router
+ */
+ protected $router;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
+ protected $file_status;
+
+ /**
+ * @var string
+ */
+ protected $form;
+
+ /**
+ * @var bool
+ */
+ protected $request_client_refresh;
+
+ /**
+ * @var array
+ */
+ protected $nav_data;
+
+ /**
+ * @var array
+ */
+ protected $cookies;
+
+ /**
+ * @var array
+ */
+ protected $download;
+
+ /**
+ * @var array
+ */
+ protected $redirect_url;
+
+ /**
+ * @var resource
+ */
+ protected $file_lock_pointer;
+
+ /**
+ * Constructor
+ *
+ * @param path_helper $path_helper
+ * @param \phpbb\request\request_interface $request HTTP request interface
+ * @param \phpbb\template\template $template Template engine
+ * @param router $router Router
+ * @param string $root_path Path to phpBB's root
+ */
+ public function __construct(path_helper $path_helper, \phpbb\request\request_interface $request, \phpbb\template\template $template, router $router, $root_path)
+ {
+ $this->path_helper = $path_helper;
+ $this->request = $request;
+ $this->router = $router;
+ $this->template = $template;
+ $this->form = '';
+ $this->nav_data = array();
+ $this->cookies = array();
+ $this->download = array();
+ $this->redirect_url = array();
+ $this->file_status = '';
+ $this->phpbb_root_path = $root_path;
+
+ parent::__construct();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_input($name, $default, $multibyte = false)
+ {
+ return $this->request->variable($name, $default, $multibyte);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_raw_input($name, $default)
+ {
+ return $this->request->raw_variable($name, $default);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_server_variable($name, $default = '')
+ {
+ return $this->request->server($name, $default);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_header_variable($name, $default = '')
+ {
+ return $this->request->header($name, $default);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function is_secure()
+ {
+ return $this->request->is_secure();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_user_form_group($title, $form)
+ {
+ $this->form = $this->generate_form_render_data($title, $form);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generate_form_render_data($title, $form)
+ {
+ $this->template->assign_block_vars('options', array(
+ 'LEGEND' => $this->language->lang($title),
+ 'S_LEGEND' => true,
+ ));
+
+ $not_button_form = false;
+
+ foreach ($form as $input_name => $input_options)
+ {
+ if (!isset($input_options['type']))
+ {
+ continue;
+ }
+
+ $tpl_ary = array();
+ $not_button_form = ($input_options['type'] !== 'submit' || $not_button_form);
+
+ $tpl_ary['TYPE'] = $input_options['type'];
+ $tpl_ary['TITLE'] = $this->language->lang($input_options['label']);
+ $tpl_ary['KEY'] = $input_name;
+ $tpl_ary['S_EXPLAIN'] = false;
+ $tpl_ary['DISABLED'] = isset($input_options['disabled']) ? $input_options['disabled'] : false;
+ $tpl_ary['IS_SECONDARY'] = isset($input_options['is_secondary']) ? $input_options['is_secondary'] : false;
+
+ if (isset($input_options['default']))
+ {
+ $default = $input_options['default'];
+ $default = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', array($this, 'lang_replace_callback'), $default);
+ $tpl_ary['DEFAULT'] = $default;
+ }
+
+ if (isset($input_options['description']))
+ {
+ $tpl_ary['TITLE_EXPLAIN'] = $this->language->lang($input_options['description']);
+ $tpl_ary['S_EXPLAIN'] = true;
+ }
+
+ if (in_array($input_options['type'], array('select', 'radio'), true))
+ {
+ for ($i = 0, $total = count($input_options['options']); $i < $total; $i++)
+ {
+ if (isset($input_options['options'][$i]['label']))
+ {
+ $input_options['options'][$i]['label'] = $this->language->lang($input_options['options'][$i]['label']);
+ }
+ }
+
+ $tpl_ary['OPTIONS'] = $input_options['options'];
+ }
+
+ $block_name = ($input_options['type'] === 'submit') ? 'submit_buttons' : 'options';
+ $this->template->assign_block_vars($block_name, $tpl_ary);
+ }
+
+ if (isset($form['database_update_submit']) && !$form['database_update_submit']['disabled'])
+ {
+ $this->template->assign_var('FORM_TITLE', $this->language->lang('UPDATE_CONTINUE_UPDATE_PROCESS'));
+ }
+
+ $this->template->assign_var('S_NOT_ONLY_BUTTON_FORM', $not_button_form);
+
+ if (!$not_button_form)
+ {
+ $this->template->destroy_block_vars('options');
+ }
+
+ $this->template->set_filenames(array(
+ 'form_install' => 'installer_form.html',
+ ));
+
+ return $this->template->assign_display('form_install');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function send_response($no_more_output = false)
+ {
+ $json_data_array = $this->prepare_json_array($no_more_output);
+
+ if (empty($json_data_array))
+ {
+ return;
+ }
+
+ $json_data = json_encode($json_data_array);
+
+ // Try to push content to the browser
+ print(str_pad(' ', 4096) . "\n");
+ print($json_data . "\n\n");
+ flush();
+ }
+
+ /**
+ * Prepares iohandler's data to be sent out to the client.
+ *
+ * @param bool $no_more_output Whether or not there will be more output in this response
+ *
+ * @return array
+ */
+ protected function prepare_json_array($no_more_output = false)
+ {
+ $json_array = array();
+
+ if (!empty($this->errors))
+ {
+ $json_array['errors'] = $this->errors;
+ $this->errors = array();
+ }
+
+ if (!empty($this->warnings))
+ {
+ $json_array['warnings'] = $this->warnings;
+ $this->warnings = array();
+ }
+
+ if (!empty($this->logs))
+ {
+ $json_array['logs'] = $this->logs;
+ $this->logs = array();
+ }
+
+ if (!empty($this->success))
+ {
+ $json_array['success'] = $this->success;
+ $this->success = array();
+ }
+
+ if (!empty($this->download))
+ {
+ $json_array['download'] = $this->download;
+ $this->download = array();
+ }
+
+ if (!empty($this->form))
+ {
+ $json_array['form'] = $this->form;
+ $this->form = '';
+ }
+
+ if (!empty($this->file_status))
+ {
+ $json_array['file_status'] = $this->file_status;
+ $this->file_status = '';
+ }
+
+ // If current task name is set, we push progress message to the client side
+ if (!empty($this->current_task_name))
+ {
+ $json_array['progress'] = array(
+ 'task_name' => $this->current_task_name,
+ 'task_num' => $this->current_task_progress,
+ 'task_count' => $this->task_progress_count,
+ );
+
+ if ($this->restart_progress_bar)
+ {
+ $json_array['progress']['restart'] = 1;
+ $this->restart_progress_bar = false;
+ }
+ }
+
+ if (!empty($this->nav_data))
+ {
+ $json_array['nav'] = $this->nav_data;
+ $this->nav_data = array();
+ }
+
+ if ($this->request_client_refresh)
+ {
+ $json_array['refresh'] = true;
+ $this->request_client_refresh = false;
+ }
+
+ if (!empty($this->cookies))
+ {
+ $json_array['cookies'] = $this->cookies;
+ $this->cookies = array();
+ }
+
+ if (!empty($this->redirect_url))
+ {
+ $json_array['redirect'] = $this->redirect_url;
+ $this->redirect_url = array();
+ }
+
+ if ($no_more_output)
+ {
+ $json_array['over'] = true;
+ }
+
+ return $json_array;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_progress($task_lang_key, $task_number)
+ {
+ parent::set_progress($task_lang_key, $task_number);
+ $this->send_response();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function request_refresh()
+ {
+ $this->request_client_refresh = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_active_stage_menu($menu_path)
+ {
+ $this->nav_data['active'] = $menu_path[count($menu_path) - 1];
+ $this->send_response();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_finished_stage_menu($menu_path)
+ {
+ $this->nav_data['finished'][] = $menu_path[count($menu_path) - 1];
+ $this->send_response();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_cookie($cookie_name, $cookie_value)
+ {
+ $this->cookies[] = array(
+ 'name' => $cookie_name,
+ 'value' => $cookie_value
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_download_link($route, $title, $msg = null)
+ {
+ $link_properties = array(
+ 'href' => $this->router->generate($route),
+ 'title' => $this->language->lang($title),
+ 'download' => $this->language->lang('DOWNLOAD'),
+ );
+
+ if ($msg !== null)
+ {
+ $link_properties['msg'] = htmlspecialchars_decode($this->language->lang($msg));
+ }
+
+ $this->download[] = $link_properties;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function render_update_file_status($status_array)
+ {
+ $this->template->assign_vars(array(
+ 'T_IMAGE_PATH' => $this->path_helper->get_web_root_path() . 'adm/images/',
+ ));
+
+ foreach ($status_array as $block => $list)
+ {
+ foreach ($list as $filename)
+ {
+ $dirname = dirname($filename);
+
+ $this->template->assign_block_vars($block, array(
+ 'STATUS' => $block,
+ 'FILENAME' => $filename,
+ 'DIR_PART' => (!empty($dirname) && $dirname !== '.') ? dirname($filename) . '/' : false,
+ 'FILE_PART' => basename($filename),
+ ));
+ }
+ }
+
+ $this->template->set_filenames(array(
+ 'file_status' => 'installer_update_file_status.html',
+ ));
+
+ $this->file_status = $this->template->assign_display('file_status');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect($url, $use_ajax = false)
+ {
+ $this->redirect_url = array('url' => $url, 'use_ajax' => $use_ajax);
+ $this->send_response(true);
+ }
+
+ /**
+ * Acquires a file lock
+ */
+ public function acquire_lock()
+ {
+ $lock_file = $this->phpbb_root_path . 'store/io_lock.lock';
+ $this->file_lock_pointer = @fopen($lock_file, 'w+');
+
+ if ($this->file_lock_pointer)
+ {
+ flock($this->file_lock_pointer, LOCK_EX);
+ }
+ }
+
+ /**
+ * Release file lock
+ */
+ public function release_lock()
+ {
+ if ($this->file_lock_pointer)
+ {
+ fwrite($this->file_lock_pointer, 'ok');
+ flock($this->file_lock_pointer, LOCK_UN);
+ fclose($this->file_lock_pointer);
+ }
+ }
+
+ /**
+ * Callback function for language replacing
+ *
+ * @param array $matches
+ * @return string
+ */
+ public function lang_replace_callback($matches)
+ {
+ if (!empty($matches[1]))
+ {
+ return $this->language->lang($matches[1]);
+ }
+
+ return '';
+ }
+}
diff --git a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php
new file mode 100644
index 0000000000..4117a3dfd3
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php
@@ -0,0 +1,323 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler;
+
+use phpbb\install\exception\installer_exception;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\OutputStyle;
+
+/**
+ * Input-Output handler for the CLI frontend
+ */
+class cli_iohandler extends iohandler_base
+{
+ /**
+ * @var OutputInterface
+ */
+ protected $output;
+
+ /**
+ * @var OutputStyle
+ */
+ protected $io;
+
+ /**
+ * @var array
+ */
+ protected $input_values = array();
+
+ /**
+ * @var \Symfony\Component\Console\Helper\ProgressBar
+ */
+ protected $progress_bar;
+
+ /**
+ * Set the style and output used to display feedback;
+ *
+ * @param OutputStyle $style
+ * @param OutputInterface $output
+ */
+ public function set_style(OutputStyle $style, OutputInterface $output)
+ {
+ $this->io = $style;
+ $this->output = $output;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_input($name, $default, $multibyte = false)
+ {
+ $result = $default;
+
+ if (isset($this->input_values[$name]))
+ {
+ $result = $this->input_values[$name];
+ }
+
+ if ($multibyte)
+ {
+ return utf8_normalize_nfc($result);
+ }
+
+ return $result;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_raw_input($name, $default)
+ {
+ return $this->get_input($name, $default, true);
+ }
+
+ /**
+ * Set input variable
+ *
+ * @param string $name Name of input variable
+ * @param mixed $value Value of input variable
+ */
+ public function set_input($name, $value)
+ {
+ $this->input_values[$name] = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_server_variable($name, $default = '')
+ {
+ return $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_header_variable($name, $default = '')
+ {
+ return $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function is_secure()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_user_form_group($title, $form)
+ {
+ throw new installer_exception('MISSING_DATA');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function send_response($no_more_output = false)
+ {
+ }
+
+ /**
+ * {@inheritdoc
+ */
+ public function add_error_message($error_title, $error_description = false)
+ {
+ $this->io->newLine();
+ $message = $this->translate_message($error_title, $error_description);
+ $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
+
+ if (strpos($message_string, '<br />') !== false)
+ {
+ $message_string = strip_tags(str_replace('<br />', "\n", $message_string));
+ }
+
+ $this->io->error($message_string);
+
+ if ($this->progress_bar !== null)
+ {
+ $this->io->newLine(2);
+ $this->progress_bar->display();
+ }
+ }
+
+ /**
+ * {@inheritdoc
+ */
+ public function add_warning_message($warning_title, $warning_description = false)
+ {
+ $this->io->newLine();
+
+ $message = $this->translate_message($warning_title, $warning_description);
+ $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
+ $this->io->warning($message_string);
+
+ if ($this->progress_bar !== null)
+ {
+ $this->io->newLine(2);
+ $this->progress_bar->display();
+ }
+ }
+
+ /**
+ * {@inheritdoc
+ */
+ public function add_log_message($log_title, $log_description = false)
+ {
+ if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL)
+ {
+ $message = $this->translate_message($log_title, $log_description);
+ $this->output->writeln(sprintf('[%3d/%-3d] ---- %s', $this->current_task_progress, $this->task_progress_count, $message['title']));
+ }
+ }
+
+ /**
+ * {@inheritdoc
+ */
+ public function add_success_message($error_title, $error_description = false)
+ {
+ $this->io->newLine();
+
+ $message = $this->translate_message($error_title, $error_description);
+ $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
+ $this->io->success($message_string);
+
+ if ($this->progress_bar !== null)
+ {
+ $this->io->newLine(2);
+ $this->progress_bar->display();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_task_count($task_count, $restart = false)
+ {
+ parent::set_task_count($task_count, $restart);
+
+ if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL)
+ {
+ if ($this->progress_bar !== null)
+ {
+ // Symfony's ProgressBar is immutable regarding task_count, so delete the old and create a new one.
+ $this->progress_bar->clear();
+ }
+ else
+ {
+ $this->io->newLine(2);
+ }
+
+ $this->progress_bar = $this->io->createProgressBar($task_count);
+ $this->progress_bar->setFormat(
+ " %current:3s%/%max:-3s% %bar% %percent:3s%%\n" .
+ " %message%\n");
+ $this->progress_bar->setBarWidth(60);
+
+ if (!defined('PHP_WINDOWS_VERSION_BUILD'))
+ {
+ $this->progress_bar->setEmptyBarCharacter('░'); // light shade character \u2591
+ $this->progress_bar->setProgressCharacter('');
+ $this->progress_bar->setBarCharacter('▓'); // dark shade character \u2593
+ }
+
+ $this->progress_bar->setMessage('');
+ $this->progress_bar->start();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_progress($task_lang_key, $task_number)
+ {
+ parent::set_progress($task_lang_key, $task_number);
+
+ if ($this->progress_bar !== null)
+ {
+ $this->progress_bar->setProgress($this->current_task_progress);
+ $this->progress_bar->setMessage($this->current_task_name);
+ }
+ else
+ {
+ $this->output->writeln(sprintf('[%3d/%-3d] %s', $this->current_task_progress, $this->task_progress_count, $this->current_task_name));
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function finish_progress($message_lang_key)
+ {
+ parent::finish_progress($message_lang_key);
+
+ if ($this->progress_bar !== null)
+ {
+ $this->progress_bar->finish();
+ $this->progress_bar = null;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function request_refresh()
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_active_stage_menu($menu_path)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_finished_stage_menu($menu_path)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_cookie($cookie_name, $cookie_value)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_download_link($route, $title, $msg = null)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function render_update_file_status($status_array)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function redirect($url, $use_ajax = false)
+ {
+ }
+}
diff --git a/phpBB/phpbb/install/helper/iohandler/exception/iohandler_not_implemented_exception.php b/phpBB/phpbb/install/helper/iohandler/exception/iohandler_not_implemented_exception.php
new file mode 100644
index 0000000000..f2ddeda6f7
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/exception/iohandler_not_implemented_exception.php
@@ -0,0 +1,19 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler\exception;
+
+class iohandler_not_implemented_exception extends \Exception
+{
+
+}
diff --git a/phpBB/phpbb/install/helper/iohandler/factory.php b/phpBB/phpbb/install/helper/iohandler/factory.php
new file mode 100644
index 0000000000..1e8395760a
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/factory.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler;
+
+use phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception;
+
+/**
+ * Input-output handler factory
+ */
+class factory
+{
+ /**
+ * @var \Symfony\Component\DependencyInjection\ContainerInterface
+ */
+ protected $container;
+
+ /**
+ * @var string
+ */
+ protected $environment;
+
+ /**
+ * Constructor
+ *
+ * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Dependency injection container
+ */
+ public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container)
+ {
+ $this->container = $container;
+ $this->environment = null;
+ }
+
+ /**
+ * @param string $environment The name of the input-output handler to use
+ */
+ public function set_environment($environment)
+ {
+ $this->environment = $environment;
+ }
+
+ /**
+ * Factory getter for iohandler
+ *
+ * @return \phpbb\install\helper\iohandler\iohandler_interface
+ *
+ * @throws \phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception
+ * When the specified iohandler_interface does not exists
+ */
+ public function get()
+ {
+ switch ($this->environment)
+ {
+ case 'ajax':
+ return $this->container->get('installer.helper.iohandler_ajax');
+ break;
+ case 'nojs':
+ // @todo replace this
+ return $this->container->get('installer.helper.iohandler_ajax');
+ break;
+ case 'cli':
+ return $this->container->get('installer.helper.iohandler_cli');
+ break;
+ default:
+ throw new iohandler_not_implemented_exception();
+ break;
+ }
+ }
+}
diff --git a/phpBB/phpbb/install/helper/iohandler/iohandler_base.php b/phpBB/phpbb/install/helper/iohandler/iohandler_base.php
new file mode 100644
index 0000000000..1797a6c9ad
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/iohandler_base.php
@@ -0,0 +1,209 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler;
+
+/**
+ * Base class for installer input-output handlers
+ */
+abstract class iohandler_base implements iohandler_interface
+{
+ /**
+ * Array of errors
+ *
+ * Errors should be added, when the installation cannot continue without
+ * user interaction. If the aim is to notify the user about something, please
+ * use a warning instead.
+ *
+ * @var array
+ */
+ protected $errors;
+
+ /**
+ * Array of warnings
+ *
+ * @var array
+ */
+ protected $warnings;
+
+ /**
+ * Array of logs
+ *
+ * @var array
+ */
+ protected $logs;
+
+ /**
+ * Array of success messages
+ *
+ * @var array
+ */
+ protected $success;
+
+ /**
+ * @var \phpbb\language\language
+ */
+ protected $language;
+
+ /**
+ * @var int
+ */
+ protected $task_progress_count;
+
+ /**
+ * @var int
+ */
+ protected $current_task_progress;
+
+ /**
+ * @var string
+ */
+ protected $current_task_name;
+
+ /**
+ * @var bool
+ */
+ protected $restart_progress_bar;
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->errors = array();
+ $this->warnings = array();
+ $this->logs = array();
+ $this->success = array();
+
+ $this->restart_progress_bar = false;
+ $this->task_progress_count = 0;
+ $this->current_task_progress = 0;
+ $this->current_task_name = '';
+ }
+
+ /**
+ * Set language service
+ *
+ * @param \phpbb\language\language $language
+ */
+ public function set_language(\phpbb\language\language $language)
+ {
+ $this->language = $language;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_error_message($error_title, $error_description = false)
+ {
+ if (!is_array($error_title) && strpos($error_title, '<br />') !== false)
+ {
+ $error_title = strip_tags(htmlspecialchars_decode($error_title));
+ }
+ $this->errors[] = $this->translate_message($error_title, $error_description);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_warning_message($warning_title, $warning_description = false)
+ {
+ $this->warnings[] = $this->translate_message($warning_title, $warning_description);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_log_message($log_title, $log_description = false)
+ {
+ $this->logs[] = $this->translate_message($log_title, $log_description);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_success_message($success_title, $success_description = false)
+ {
+ $this->success[] = $this->translate_message($success_title, $success_description);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_task_count($task_count, $restart = false)
+ {
+ $this->task_progress_count = $task_count;
+ $this->restart_progress_bar = $restart;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set_progress($task_lang_key, $task_number)
+ {
+ $this->current_task_name = '';
+
+ if (!empty($task_lang_key))
+ {
+ $this->current_task_name = $this->language->lang($task_lang_key);
+ }
+
+ $this->current_task_progress = $task_number;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function finish_progress($message_lang_key)
+ {
+ if (!empty($message_lang_key))
+ {
+ $this->current_task_name = $this->language->lang($message_lang_key);
+ }
+
+ $this->current_task_progress = $this->task_progress_count;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generate_form_render_data($title, $form)
+ {
+ return '';
+ }
+
+ /**
+ * Localize message.
+ *
+ * Note: When an array is passed into the parameters below, it will be
+ * resolved as printf($param[0], $param[1], ...).
+ *
+ * @param array|string $title Title of the message
+ * @param array|string|bool $description Description of the message
+ *
+ * @return array Localized message in an array
+ */
+ protected function translate_message($title, $description)
+ {
+ $message_array = array();
+
+ $message_array['title'] = call_user_func_array(array($this->language, 'lang'), (array) $title);
+
+ if ($description !== false)
+ {
+ $message_array['description'] = call_user_func_array(array($this->language, 'lang'), (array) $description);
+ }
+
+ return $message_array;
+ }
+}
diff --git a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php
new file mode 100644
index 0000000000..440748901c
--- /dev/null
+++ b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php
@@ -0,0 +1,222 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\helper\iohandler;
+
+/**
+ * Input-Output handler interface for the installer
+ */
+interface iohandler_interface
+{
+ /**
+ * Renders or returns response message
+ *
+ * @param bool $no_more_output Whether or not there will be more output in this output unit
+ */
+ public function send_response($no_more_output = false);
+
+ /**
+ * Returns input variable
+ *
+ * @param string $name Name of the input variable to obtain
+ * @param mixed $default A default value that is returned if the variable was not set.
+ * This function will always return a value of the same type as the default.
+ * @param bool $multibyte If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters
+ * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
+ *
+ * @return mixed Value of the input variable
+ */
+ public function get_input($name, $default, $multibyte = false);
+
+ /**
+ * Returns raw input variable
+ *
+ * @param string $name Name of the input variable to obtain
+ * @param mixed $default A default value that is returned if the variable was not set.
+ * This function will always return a value of the same type as the default.
+ *
+ * @return mixed Value of the raw input variable
+ */
+ public function get_raw_input($name, $default);
+
+ /**
+ * Returns server variable
+ *
+ * This function should work the same as request_interface::server().
+ *
+ * @param string $name Name of the server variable
+ * @param mixed $default Default value to return when the requested variable does not exist
+ *
+ * @return mixed Value of the server variable
+ */
+ public function get_server_variable($name, $default = '');
+
+ /**
+ * Wrapper function for request_interface::header()
+ *
+ * @param string $name Name of the request header variable
+ * @param mixed $default Default value to return when the requested variable does not exist
+ *
+ * @return mixed
+ */
+ public function get_header_variable($name, $default = '');
+
+ /**
+ * Returns true if the connection is encrypted
+ *
+ * @return bool
+ */
+ public function is_secure();
+
+ /**
+ * Adds an error message to the rendering queue
+ *
+ * Note: When an array is passed into the parameters below, it will be
+ * resolved as printf($param[0], $param[1], ...).
+ *
+ * @param string|array $error_title Title of the error message.
+ * @param string|bool|array $error_description Description of the error (and possibly guidelines to resolve it),
+ * or false if the error description is not available.
+ */
+ public function add_error_message($error_title, $error_description = false);
+
+ /**
+ * Adds a warning message to the rendering queue
+ *
+ * Note: When an array is passed into the parameters below, it will be
+ * resolved as printf($param[0], $param[1], ...).
+ *
+ * @param string|array $warning_title Title of the warning message
+ * @param string|bool|array $warning_description Description of the warning (and possibly guidelines to resolve it),
+ * or false if the warning description is not available
+ */
+ public function add_warning_message($warning_title, $warning_description = false);
+
+ /**
+ * Adds a log message to the rendering queue
+ *
+ * Note: When an array is passed into the parameters below, it will be
+ * resolved as printf($param[0], $param[1], ...).
+ *
+ * @param string|array $log_title Title of the log message
+ * @param string|bool|array $log_description Description of the log,
+ * or false if the log description is not available
+ */
+ public function add_log_message($log_title, $log_description = false);
+
+ /**
+ * Adds a success message to the rendering queue
+ *
+ * Note: When an array is passed into the parameters below, it will be
+ * resolved as printf($param[0], $param[1], ...).
+ *
+ * @param string|array $success_title Title of the success message
+ * @param string|bool|array $success_description Description of the success,
+ * or false if the success description is not available
+ *
+ * @return null
+ */
+ public function add_success_message($success_title, $success_description = false);
+
+ /**
+ * Adds a requested data group to the rendering queue
+ *
+ * @param string $title Language variable with the title of the form
+ * @param array $form An array describing the required data (options etc)
+ */
+ public function add_user_form_group($title, $form);
+
+ /**
+ * Returns the rendering information for the form
+ *
+ * @param string $title Language variable with the title of the form
+ * @param array $form An array describing the required data (options etc)
+ *
+ * @return string Information to render the form
+ */
+ public function generate_form_render_data($title, $form);
+
+ /**
+ * Sets the number of tasks belonging to the installer in the current mode.
+ *
+ * @param int $task_count Number of tasks
+ * @param bool $restart Whether or not to restart the progress bar, false by default
+ */
+ public function set_task_count($task_count, $restart = false);
+
+ /**
+ * Sets the progress information
+ *
+ * @param string $task_lang_key Language key for the name of the task
+ * @param int $task_number Position of the current task in the task queue
+ */
+ public function set_progress($task_lang_key, $task_number);
+
+ /**
+ * Sends refresh request to the client
+ */
+ public function request_refresh();
+
+ /**
+ * Marks stage as active in the navigation bar
+ *
+ * @param array $menu_path Array to the navigation elem
+ */
+ public function set_active_stage_menu($menu_path);
+
+ /**
+ * Marks stage as completed in the navigation bar
+ *
+ * @param array $menu_path Array to the navigation elem
+ */
+ public function set_finished_stage_menu($menu_path);
+
+ /**
+ * Finish the progress bar
+ *
+ * @param string $message_lang_key Language key for the message
+ */
+ public function finish_progress($message_lang_key);
+
+ /**
+ * Adds a download link
+ *
+ * @param string $route Route for the link
+ * @param string $title Language key for the title
+ * @param string|null|array $msg Language key for the message
+ */
+ public function add_download_link($route, $title, $msg = null);
+
+ /**
+ * Redirects the user to a new page
+ *
+ * @param string $url URL to redirect to
+ * @param bool $use_ajax Whether or not to use AJAX redirect
+ */
+ public function redirect($url, $use_ajax = false);
+
+ /**
+ * Renders the status of update files
+ *
+ * @param array $status_array Array containing files in groups to render
+ */
+ public function render_update_file_status($status_array);
+
+ /**
+ * Sends and sets cookies
+ *
+ * @param string $cookie_name Name of the cookie to set
+ * @param string $cookie_value Value of the cookie to set
+ */
+ public function set_cookie($cookie_name, $cookie_value);
+}