From dff35eaa423608f0140e701f5052cd7775717a98 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 22 Jan 2025 18:45:46 +0000 Subject: [PATCH] installer: Fix conflation between warning and info messages * Fix getInfoBox to not be a warning box, but an information notice like it is intended to be. * Update getInfoBox() to use codex class names, same as showMessage(). * Update getInfoBox() to bold the "Information" title, as per Codex examples and guidelines, e.g. https://doc.wikimedia.org/codex/latest/components/demos/message.html#multiline * Remove infoBox() utility, it was used only once, in getInfoBox(). The `mw-installer-box-*`, `mw-installer-infobox-*` CSS classes are also unusd now, however there is nothing to remove because these were already removed in a previous refactor. * Introduce showWarning(), and apply it to showMessage() calls that convey non-fatal issues. Bug: T384524 Change-Id: I6722346ef81a0a9cf8983153271be579905c7898 --- includes/installer/CliInstaller.php | 6 +++ includes/installer/Installer.php | 32 +++++++++++---- includes/installer/WebInstaller.php | 64 ++++++++++++----------------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/includes/installer/CliInstaller.php b/includes/installer/CliInstaller.php index b5d07036c37..3db61eb8293 100644 --- a/includes/installer/CliInstaller.php +++ b/includes/installer/CliInstaller.php @@ -262,6 +262,12 @@ class CliInstaller extends Installer { flush(); } + public function showWarning( $msg, ...$params ) { + // @phan-suppress-next-line SecurityCheck-XSS + echo $this->getMessageText( $msg, $params ) . "\n"; + flush(); + } + public function showError( $msg, ...$params ) { // @phan-suppress-next-line SecurityCheck-XSS echo "***{$this->getMessageText( $msg, $params )}***\n"; diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 1822e6671f0..2e678d63c6d 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -358,17 +358,31 @@ abstract class Installer { protected array $virtualDomains = []; /** - * UI interface for displaying a short message - * The parameters are like parameters to wfMessage(). - * The messages will be in wikitext format, which will be converted to an - * output format such as HTML or text before being sent to the user. - * @param string|MessageSpecifier $msg + * Display a short neutral message + * + * @param string|MessageSpecifier $msg String of wikitext that will be converted + * to HTML, or interface message that will be parsed. * @param mixed ...$params */ abstract public function showMessage( $msg, ...$params ); /** - * Same as showMessage(), but for displaying errors + * Display a warning message + * + * @param string|MessageSpecifier $msg String of wikitext that will be converted + * to HTML, or interface message that will be parsed. + * @param string|int|float ...$params Message parameters, same as wfMessage(). + */ + abstract public function showWarning( $msg, ...$params ); + + /** + * Display an error message + * + * Avoid error fatigue in the installer. Use this only if something the + * user expects has failed and requires intervention to continue. + * If something non-essential failed that can be continued past with + * no action, use a warning instead. + * * @param string|MessageSpecifier $msg * @param mixed ...$params */ @@ -1100,7 +1114,7 @@ abstract class Installer { $safe = !$this->dirIsExecutable( $dir, $url ); if ( !$safe ) { - $this->showMessage( 'config-uploads-not-safe', $dir ); + $this->showWarning( 'config-uploads-not-safe', $dir ); } return true; @@ -1128,14 +1142,14 @@ abstract class Installer { } if ( !$status || !$status->isGood() ) { - $this->showMessage( 'config-uploads-security-requesterror', 'X-Content-Type-Options: nosniff' ); + $this->showWarning( 'config-uploads-security-requesterror', 'X-Content-Type-Options: nosniff' ); return true; } $headerValue = $req->getResponseHeader( 'X-Content-Type-Options' ) ?? ''; $responseList = Header::splitList( $headerValue ); if ( !in_array( 'nosniff', $responseList, true ) ) { - $this->showMessage( 'config-uploads-security-headers', 'X-Content-Type-Options: nosniff' ); + $this->showWarning( 'config-uploads-security-headers', 'X-Content-Type-Options: nosniff' ); } return true; diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 0e6e12460af..5c79e5a066b 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -626,19 +626,6 @@ class WebInstaller extends Installer { "" ); } - /** - * Get HTML for an information message box with an icon. - * - * @param string|HtmlArmor $text Wikitext to be parsed (from Message::plain) or raw HTML. - * @return string HTML - */ - public function getInfoBox( $text ) { - $html = ( $text instanceof HtmlArmor ) ? - HtmlArmor::getHtml( $text ) : - $this->parse( $text, true ); - return self::infoBox( $html, wfMessage( 'config-information' )->text() ); - } - /** * Get small text indented help for a preceding form field. * Parameters like wfMessage(). @@ -673,6 +660,23 @@ class WebInstaller extends Installer { $this->output->addHTML( $html ); } + /** + * Get HTML for an information message box. + * + * @param string|HtmlArmor $text Wikitext to be parsed (from Message::plain) or raw HTML. + * @return string HTML + */ + public function getInfoBox( $text ) { + $html = ( $text instanceof HtmlArmor ) ? + HtmlArmor::getHtml( $text ) : + $this->parse( $text, true ); + return '
' . + '
' . + '

' . wfMessage( 'config-information' )->escaped() . '

' . + $html . + "
\n"; + } + public function showMessage( $msg, ...$params ) { $html = '
' . '
' . @@ -681,13 +685,21 @@ class WebInstaller extends Installer { $this->output->addHTML( $html ); } + public function showWarning( $msg, ...$params ) { + $html = '
' . + '
' . + $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) . + "
\n"; + $this->output->addHTML( $html ); + } + public function showStatusMessage( Status $status ) { // Show errors at the top in web installer to make them easier to notice foreach ( $status->getMessages( 'error' ) as $msg ) { - $this->showMessage( $msg ); + $this->showWarning( $msg ); } foreach ( $status->getMessages( 'warning' ) as $msg ) { - $this->showMessage( $msg ); + $this->showWarning( $msg ); } } @@ -1224,28 +1236,6 @@ class WebInstaller extends Installer { return $this->phpErrors; } - /** - * Get HTML for an information message box with an icon. - * - * @since 1.36 - * @param string $rawHtml HTML - * @param string $text text for the icon - * @param string $class Additional class name to add to the wrapper div - * @return string HTML - */ - protected static function infoBox( $rawHtml, $text, $class = '' ) { - $s = Html::openElement( 'div', [ 'class' => 'mw-installer-box-left' ] ) . - Html::element( 'strong', [ 'class' => 'mw-installer-infobox-title' ], $text ) . - Html::closeElement( 'div' ) . - Html::openElement( 'div', [ 'class' => 'mw-installer-box-right' ] ) . - $rawHtml . - Html::closeElement( 'div' ) . - Html::element( 'div', [ 'style' => 'clear: left;' ], ' ' ); - - return Html::warningBox( $s, $class ) - . Html::element( 'div', [ 'style' => 'clear: left;' ], ' ' ); - } - /** * Determine whether the current database needs to be upgraded, i.e. whether * it already has MediaWiki tables.