Taueres has uploaded a new change for review. https://gerrit.wikimedia.org/r/208522
Change subject: Web installer: improve error handling on session start ...................................................................... Web installer: improve error handling on session start * This commit removes the attribute WebInstaller#phpErrors and all related methods. * Error handling has been improved creating the following new classes: - WebInstallerErrorHandler - SessionStartException This commit successfully clean WebInstaller interface removing useless and misleading methods. Change-Id: I92428cc79921b756443a88ff63fb597db8284a82 --- M autoload.php M includes/installer/WebInstaller.php A includes/installer/WebInstallerErrorHandler.php A includes/installer/exception/SessionStartException.php M mw-config/index.php 5 files changed, 134 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/22/208522/1 diff --git a/autoload.php b/autoload.php index 81ee8b1..3d2ffaa 100644 --- a/autoload.php +++ b/autoload.php @@ -1073,6 +1073,7 @@ 'SearchUpdate' => __DIR__ . '/includes/deferred/SearchUpdate.php', 'SectionProfileCallback' => __DIR__ . '/includes/profiler/SectionProfiler.php', 'SectionProfiler' => __DIR__ . '/includes/profiler/SectionProfiler.php', + 'SessionStartException' => __DIR__ . '/includes/installer/exception/SessionStartException.php', 'SevenZipStream' => __DIR__ . '/maintenance/7zip.inc', 'ShiConverter' => __DIR__ . '/languages/classes/LanguageShi.php', 'ShortPagesPage' => __DIR__ . '/includes/specials/SpecialShortpages.php', @@ -1332,6 +1333,7 @@ 'WebInstallerDBConnect' => __DIR__ . '/includes/installer/WebInstallerPage.php', 'WebInstallerDBSettings' => __DIR__ . '/includes/installer/WebInstallerPage.php', 'WebInstallerDocument' => __DIR__ . '/includes/installer/WebInstallerPage.php', + 'WebInstallerErrorHandler' => __DIR__ . '/includes/installer/WebInstallerErrorHandler.php', 'WebInstallerExistingWiki' => __DIR__ . '/includes/installer/WebInstallerPage.php', 'WebInstallerInstall' => __DIR__ . '/includes/installer/WebInstallerPage.php', 'WebInstallerLanguage' => __DIR__ . '/includes/installer/WebInstallerPage.php', diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index f3dba3a..761d7fd 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -49,13 +49,6 @@ protected $session; /** - * Captured PHP error text. Temporary. - * - * @var string[] - */ - protected $phpErrors; - - /** * The main sequence of page names. These will be displayed in turn. * * To add a new installer page: @@ -330,8 +323,9 @@ /** * Start the PHP session. This may be called before execute() to start the PHP session. + * Throw SessionStartException if errors occur. Return true on success. * - * @throws Exception + * @throws SessionStartException * @return bool */ public function startSession() { @@ -340,18 +334,17 @@ return true; } - $this->phpErrors = array(); - set_error_handler( array( $this, 'errorHandler' ) ); + $errorHandler = new WebInstallerErrorHandler(); + set_error_handler( array( $errorHandler, 'handleError' ) ); try { session_start(); } catch ( Exception $e ) { - restore_error_handler(); - throw $e; + $errorHandler->addError( $e->getMessage() ); } restore_error_handler(); - if ( $this->phpErrors ) { - return false; + if ( $errorHandler->hasErrors() ) { + throw new SessionStartException( $errorHandler->getErrors() ); } return true; @@ -395,16 +388,6 @@ $args = array_map( 'htmlspecialchars', $args ); $msg = wfMessage( $msg, $args )->useDatabase( false )->plain(); $this->output->addHTML( $this->getErrorBox( $msg ) ); - } - - /** - * Temporary error handler for session start debugging. - * - * @param int $errno Unused - * @param string $errstr - */ - public function errorHandler( $errno, $errstr ) { - $this->phpErrors[] = $errstr; } /** @@ -1198,13 +1181,6 @@ public function outputCss() { $this->request->response()->header( 'Content-type: text/css' ); echo $this->output->getCSS(); - } - - /** - * @return string[] - */ - public function getPhpErrors() { - return $this->phpErrors; } } diff --git a/includes/installer/WebInstallerErrorHandler.php b/includes/installer/WebInstallerErrorHandler.php new file mode 100644 index 0000000..c0775da --- /dev/null +++ b/includes/installer/WebInstallerErrorHandler.php @@ -0,0 +1,70 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Deployment + */ + +/** + * Temporary error handler used by WebInstaller. + * + * @ingroup Deployment + * @since 1.26 + */ +class WebInstallerErrorHandler { + + /** + * @var string[] + */ + private $errors; + + /** + * Build new error handler instance + */ + public function __construct() { + $this->errors = array(); + } + + /** + * @param int $errno + * @param string $errstr + */ + public function handleError( $errno, $errstr ) { + $this->addError( $errstr ); + } + + /** + * @param string $error + */ + public function addError( $error ) { + $this->errors[] = $error; + } + + /** + * @return bool + */ + public function hasErrors() { + return count( $this->errors ) > 0; + } + + /** + * @return string[] + */ + public function getErrors() { + return $this->errors; + } +} \ No newline at end of file diff --git a/includes/installer/exception/SessionStartException.php b/includes/installer/exception/SessionStartException.php new file mode 100644 index 0000000..198f970 --- /dev/null +++ b/includes/installer/exception/SessionStartException.php @@ -0,0 +1,48 @@ +<?php +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Exception + */ + +/** + * Exception thrown if errors occur during start of session + * + * @ingroup Exception + * @since 1.26 + */ +class SessionStartException extends RuntimeException { + + /** + * @var string[] + */ + private $errors; + + /** + * @param string[] $errors + */ + public function __construct(array $errors) { + $this->errors = $errors; + } + + /** + * @return string[] + */ + public function getErrors() { + return $this->errors; + } +} \ No newline at end of file diff --git a/mw-config/index.php b/mw-config/index.php index ed3e7f4..3a5c59d 100644 --- a/mw-config/index.php +++ b/mw-config/index.php @@ -42,17 +42,18 @@ $installer = InstallerOverrides::getWebInstaller( $wgRequest ); - if ( !$installer->startSession() ) { - + try { + $installer->startSession(); + } catch ( SessionStartException $e ) { if ( $installer->request->getVal( "css" ) ) { // Do not display errors on css pages $installer->outputCss(); - exit; + } else { + $errors = $e->getErrors(); + $installer->showError( 'config-session-error', $errors[0] ); + $installer->finish(); } - $errors = $installer->getPhpErrors(); - $installer->showError( 'config-session-error', $errors[0] ); - $installer->finish(); exit; } -- To view, visit https://gerrit.wikimedia.org/r/208522 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I92428cc79921b756443a88ff63fb597db8284a82 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Taueres <santoro....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits