Merge "message boxes: Use CSS classes adhering to class naming scheme"

This commit is contained in:
jenkins-bot 2021-01-22 02:15:34 +00:00 committed by Gerrit Code Review
commit e2be1836e9
4 changed files with 47 additions and 18 deletions

View file

@ -715,6 +715,11 @@ class Html {
if ( $heading !== '' ) {
$html = self::element( 'h2', [], $heading ) . $html;
}
if ( is_array( $className ) ) {
$className[] = 'mw-message-box';
} else {
$className .= ' mw-message-box';
}
return self::rawElement( 'div', [ 'class' => $className ], $html );
}
@ -727,7 +732,12 @@ class Html {
* @return string of HTML representing a warning box.
*/
public static function warningBox( $html, $className = '' ) {
return self::messageBox( $html, [ 'warningbox', $className ] );
return self::messageBox( $html, [
'mw-warning-box',
// Deprecated class `warningbox` kept for gadgets/user styles.
'warningbox',
$className
] );
}
/**
@ -740,7 +750,12 @@ class Html {
* @return string of HTML representing an error box.
*/
public static function errorBox( $html, $heading = '', $className = '' ) {
return self::messageBox( $html, [ 'errorbox', $className ], $heading );
return self::messageBox( $html, [
'mw-error-box',
// Deprecated class `errorbox` Kept for gadgets/user styles.
'errorbox',
$className
], $heading );
}
/**
@ -752,7 +767,12 @@ class Html {
* @return string of HTML representing a success box.
*/
public static function successBox( $html, $className = '' ) {
return self::messageBox( $html, [ 'successbox', $className ] );
return self::messageBox( $html, [
'mw-success-box',
// Deprecated class `successbox` Kept for gadgets/user styles.
'successbox',
$className
] );
}
/**

View file

@ -1,8 +1,13 @@
/* stylelint-disable selector-class-pattern */
.messagebox,
.errorbox,
.warningbox,
.successbox {
.mw-message-box,
.mw-error-box,
.mw-warning-box,
.mw-success-box,
.messagebox, /* Deprecated since v1.36 */
.errorbox, /* Deprecated since v1.36 */
.warningbox, /* Deprecated since v1.36 */
.successbox { /* Deprecated since v1.36 */
/* stylelint-enable selector-class-pattern */
color: #000;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
@ -30,22 +35,26 @@
}
}
.messagebox {
.mw-message-box,
.messagebox { /* stylelint-disable-line selector-class-pattern */
background-color: #eaecf0;
border-color: #a2a9b1;
}
.errorbox {
.mw-error-box,
.errorbox { /* stylelint-disable-line selector-class-pattern */
background-color: #fee7e6;
border-color: #d33;
}
.warningbox {
.mw-warning-box,
.warningbox { /* stylelint-disable-line selector-class-pattern */
background-color: #fef6e7;
border-color: #fc3;
}
.successbox {
.mw-success-box,
.successbox { /* stylelint-disable-line selector-class-pattern */
background-color: #d5fdf4;
border-color: #14866d;
}

View file

@ -504,7 +504,7 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
*/
public function testWarningBox() {
$this->assertEquals(
'<div class="warningbox">warn</div>',
'<div class="mw-warning-box warningbox mw-message-box">warn</div>',
Html::warningBox( 'warn' )
);
}
@ -515,15 +515,15 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
*/
public function testErrorBox() {
$this->assertEquals(
'<div class="errorbox">err</div>',
'<div class="mw-error-box errorbox mw-message-box">err</div>',
Html::errorBox( 'err' )
);
$this->assertEquals(
'<div class="errorbox errorbox-custom-class"><h2>heading</h2>err</div>',
'<div class="mw-error-box errorbox errorbox-custom-class mw-message-box"><h2>heading</h2>err</div>',
Html::errorBox( 'err', 'heading', 'errorbox-custom-class' )
);
$this->assertEquals(
'<div class="errorbox"><h2>0</h2>err</div>',
'<div class="mw-error-box errorbox mw-message-box"><h2>0</h2>err</div>',
Html::errorBox( 'err', '0', '' )
);
}
@ -534,11 +534,11 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
*/
public function testSuccessBox() {
$this->assertEquals(
'<div class="successbox">great</div>',
'<div class="mw-success-box successbox mw-message-box">great</div>',
Html::successBox( 'great' )
);
$this->assertEquals(
'<div class="successbox"><script>beware no escaping!</script></div>',
'<div class="mw-success-box successbox mw-message-box"><script>beware no escaping!</script></div>',
Html::successBox( '<script>beware no escaping!</script>' )
);
}

View file

@ -43,7 +43,7 @@ class SpecialSearchTest extends MediaWikiIntegrationTestCase {
->getSpecialPageFactory()
->executePath( $sp, $ctx );
$html = $ctx->getOutput()->getHTML();
$this->assertRegExp( '/class="warningbox"/', $html, 'must contain warnings' );
$this->assertRegExp( '/class="mw-warning-box warningbox/', $html, 'must contain warnings' );
$this->assertRegExp( '/Sort order of invalid is unrecognized/',
$html, 'must tell user sort order is invalid' );
}