From 8931b40119ebd2f9794973483f31b8f4fe95560c Mon Sep 17 00:00:00 2001 From: addshore Date: Sun, 23 Feb 2025 20:40:51 +0000 Subject: Add Y/n prompt at the end of interactive install Split out from I8b6b4138158e64fbe63a63e5e784a9b5a7574270 Bug: T48076 Change-Id: I6ac5550434850973e544c69a11a0d199ab2d422c --- maintenance/includes/Maintenance.php | 21 +++++++++++++++++++++ maintenance/install.php | 4 ++++ 2 files changed, 25 insertions(+) (limited to 'maintenance') diff --git a/maintenance/includes/Maintenance.php b/maintenance/includes/Maintenance.php index 976a73832e4d..6e01a2bd12e8 100644 --- a/maintenance/includes/Maintenance.php +++ b/maintenance/includes/Maintenance.php @@ -1653,6 +1653,27 @@ abstract class Maintenance { return $line; } + + /** + * @param string $prompt The prompt to display to the user + * @param bool|null $default The default value to return if the user just presses enter + * + * @return ?bool + * + * @since 1.44 + */ + protected function promptYesNo( $prompt, $default = null ) { + $defaultText = $default === null ? '' : ( $default ? 'Y' : 'n' ); + $line = self::readconsole( $prompt . " (Y/n) [$defaultText]" ); + if ( $line === false ) { + return $default; + } + if ( $line === '' ) { + return $default; + } + + return strtolower( $line ) === 'y'; + } } /** @deprecated class alias since 1.43 */ diff --git a/maintenance/install.php b/maintenance/install.php index 9a3cfdc2f7c6..2a4234e96167 100644 --- a/maintenance/install.php +++ b/maintenance/install.php @@ -182,6 +182,10 @@ class CommandLineInstaller extends Maintenance { $this->setOption( 'dbuser', $dbUser ); $this->setOption( 'dbpass', $dbPass ); $this->setOption( 'dbserver', $dbServer ); + if ( !$this->promptYesNo( 'Do you want to continue with the installation?', true ) ) { + $this->output( "Installation aborted.\n" ); + return false; + } } $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks -- cgit v1.2.3