From a9252abb1cf0ad52ee25dc8c56d76a29a71d7045 Mon Sep 17 00:00:00 2001 From: Volker E Date: Mon, 16 Sep 2019 21:39:49 -0700 Subject: [PATCH] Replace infobox usages and extend successbox, warningbox and errorbox Adding optional $className parameter to provide additional styling options. Optional parameter $heading was introduced for MobileFrontend. Therefore leaving inconsistent parameter order is necessary for the time being. Bug: T232903 Change-Id: I5857b2c58a47a83156c32f086a73fe2bd48ab0c8 --- includes/Html.php | 20 +++++++++++++------- includes/installer/DatabaseInstaller.php | 2 +- includes/installer/WebInstaller.php | 7 ++++--- includes/installer/WebInstallerOptions.php | 2 +- includes/installer/WebInstallerRestart.php | 2 +- tests/phpunit/includes/HtmlTest.php | 6 +++--- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index c4b57af978..a8f349606c 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -704,7 +704,7 @@ class Html { * Return the HTML for a message box. * @since 1.31 * @param string $html of contents of box - * @param string $className corresponding to box + * @param string|array $className corresponding to box * @param string $heading (optional) * @return string of HTML representing a box. */ @@ -718,32 +718,38 @@ class Html { /** * Return a warning box. * @since 1.31 + * @since 1.34 $className optional parameter added * @param string $html of contents of box + * @param string $className (optional) corresponding to box * @return string of HTML representing a warning box. */ - public static function warningBox( $html ) { - return self::messageBox( $html, 'warningbox' ); + public static function warningBox( $html, $className = '' ) { + return self::messageBox( $html, [ 'warningbox', $className ] ); } /** * Return an error box. * @since 1.31 + * @since 1.34 $className optional parameter added * @param string $html of contents of error box * @param string $heading (optional) + * @param string $className (optional) corresponding to box * @return string of HTML representing an error box. */ - public static function errorBox( $html, $heading = '' ) { - return self::messageBox( $html, 'errorbox', $heading ); + public static function errorBox( $html, $heading = '', $className = '' ) { + return self::messageBox( $html, [ 'errorbox', $className ], $heading ); } /** * Return a success box. * @since 1.31 + * @since 1.34 $className optional parameter added * @param string $html of contents of box + * @param string $className (optional) corresponding to box * @return string of HTML representing a success box. */ - public static function successBox( $html ) { - return self::messageBox( $html, 'successbox' ); + public static function successBox( $html, $className = '' ) { + return self::messageBox( $html, [ 'successbox', $className ] ); } /** diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index ac8c9e6745..ce7e29ddb5 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -690,7 +690,7 @@ abstract class DatabaseInstaller { $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) . $this->parent->getHelpBox( 'config-db-web-help' ); if ( $noCreateMsg ) { - $s .= $this->parent->getWarningBox( wfMessage( $noCreateMsg )->plain() ); + $s .= Html::warningBox( wfMessage( $noCreateMsg )->plain(), 'config-warning-box' ); } else { $s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' ); } diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index b6e90a9b45..21ad210f5e 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -390,7 +390,8 @@ class WebInstaller extends Installer { ); } $text = $msg->useDatabase( false )->plain(); - $this->output->addHTML( $this->getErrorBox( $text ) ); + $box = Html::errorBox( $text, '', 'config-error-box' ); + $this->output->addHTML( $box ); } /** @@ -1046,9 +1047,9 @@ class WebInstaller extends Installer { $text = $status->getWikiText(); if ( $status->isOK() ) { - $box = $this->getWarningBox( $text ); + $box = Html::warningBox( $text, 'config-warning-box' ); } else { - $box = $this->getErrorBox( $text ); + $box = Html::errorBox( $text, '', 'config-error-box' ); } $this->output->addHTML( $box ); diff --git a/includes/installer/WebInstallerOptions.php b/includes/installer/WebInstallerOptions.php index 7bec49a369..3521fa188f 100644 --- a/includes/installer/WebInstallerOptions.php +++ b/includes/installer/WebInstallerOptions.php @@ -137,7 +137,7 @@ class WebInstallerOptions extends WebInstallerPage { } } else { $skinHtml .= - $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) . + Html::warningBox( wfMessage( 'config-skins-missing' )->plain(), 'config-warning-box' ) . Html::hidden( 'config_wgDefaultSkin', $chosenSkinName ); } diff --git a/includes/installer/WebInstallerRestart.php b/includes/installer/WebInstallerRestart.php index be55c32fd0..07e2e7513f 100644 --- a/includes/installer/WebInstallerRestart.php +++ b/includes/installer/WebInstallerRestart.php @@ -36,7 +36,7 @@ class WebInstallerRestart extends WebInstallerPage { } $this->startForm(); - $s = $this->parent->getWarningBox( wfMessage( 'config-help-restart' )->plain() ); + $s = Html::warningBox( wfMessage( 'config-help-restart' )->plain(), '', 'config-warning-box' ); $this->addHTML( $s ); $this->endForm( 'restart' ); diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 4401410ef3..35d06dd63d 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -566,11 +566,11 @@ class HtmlTest extends MediaWikiTestCase { '
err
' ); $this->assertEquals( - Html::errorBox( 'err', 'heading' ), - '

heading

err
' + Html::errorBox( 'err', 'heading', 'errorbox-custom-class' ), + '

heading

err
' ); $this->assertEquals( - Html::errorBox( 'err', '0' ), + Html::errorBox( 'err', '0', '' ), '

0

err
' ); } -- 2.20.1