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
This commit is contained in:
Timo Tijhof 2025-01-22 18:45:46 +00:00
parent f680c0edc1
commit dff35eaa42
3 changed files with 56 additions and 46 deletions

View file

@ -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";

View file

@ -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;

View file

@ -626,19 +626,6 @@ class WebInstaller extends Installer {
"</div>" );
}
/**
* 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 '<div class="cdx-message cdx-message--block cdx-message--notice">' .
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' .
'<p><strong>' . wfMessage( 'config-information' )->escaped() . '</strong></p>' .
$html .
"</div></div>\n";
}
public function showMessage( $msg, ...$params ) {
$html = '<div class="cdx-message cdx-message--block cdx-message--notice">' .
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' .
@ -681,13 +685,21 @@ class WebInstaller extends Installer {
$this->output->addHTML( $html );
}
public function showWarning( $msg, ...$params ) {
$html = '<div class="cdx-message cdx-message--block cdx-message--warning">' .
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' .
$this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
"</div></div>\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.