Replace infobox usages and extend successbox, warningbox and errorbox
authorVolker E <volker.e@wikimedia.org>
Tue, 17 Sep 2019 04:39:49 +0000 (21:39 -0700)
committerVolker E <volker.e@wikimedia.org>
Tue, 24 Sep 2019 23:29:32 +0000 (16:29 -0700)
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
includes/installer/DatabaseInstaller.php
includes/installer/WebInstaller.php
includes/installer/WebInstallerOptions.php
includes/installer/WebInstallerRestart.php
tests/phpunit/includes/HtmlTest.php

index c4b57af..a8f3496 100644 (file)
@@ -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 ] );
        }
 
        /**
index ac8c9e6..ce7e29d 100644 (file)
@@ -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' );
                }
index b6e90a9..21ad210 100644 (file)
@@ -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 );
index 7bec49a..3521fa1 100644 (file)
@@ -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 );
                }
 
index be55c32..07e2e75 100644 (file)
@@ -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' );
 
index 4401410..35d06dd 100644 (file)
@@ -566,11 +566,11 @@ class HtmlTest extends MediaWikiTestCase {
                        '<div class="errorbox">err</div>'
                );
                $this->assertEquals(
-                       Html::errorBox( 'err', 'heading' ),
-                       '<div class="errorbox"><h2>heading</h2>err</div>'
+                       Html::errorBox( 'err', 'heading', 'errorbox-custom-class' ),
+                       '<div class="errorbox errorbox-custom-class"><h2>heading</h2>err</div>'
                );
                $this->assertEquals(
-                       Html::errorBox( 'err', '0' ),
+                       Html::errorBox( 'err', '0', '' ),
                        '<div class="errorbox"><h2>0</h2>err</div>'
                );
        }