Provide message/warning/error box abstraction
This will help us consolidate the various uses into one single method which will help us drive standardisation of these defacto widgets. Hopefully, by being a method of the Html class, which has a very low barrier for use will drive down the inconsistent display of warning/error boxes across MediaWiki's products Various usages of warningbox and errorbox have been ported over. I've retained some more complicated usages which make use of the parser (wrapWikiMsg) and any where id and class are medled with - we'll probably want to consider whether we want to encourage those going forward as they encourage adjusting the styling. Bug: T166915 Change-Id: I2757e1f4ff2599e93a7257fc644cab69063896d2
This commit is contained in:
parent
7853da416d
commit
4e7021a231
11 changed files with 73 additions and 30 deletions
|
|
@ -20,6 +20,9 @@ production.
|
|||
=== New features in 1.31 ===
|
||||
* Wikimedia\Rdbms\IDatabase->select() and similar methods now support
|
||||
joins with parentheses for grouping.
|
||||
* As a first pass in standardizing dialog boxes across the MediaWiki product,
|
||||
Html class now provides helper methods for messageBox, successBox, errorBox and
|
||||
warningBox generation.
|
||||
|
||||
=== External library changes in 1.31 ===
|
||||
|
||||
|
|
|
|||
|
|
@ -675,6 +675,52 @@ class Html {
|
|||
return self::input( $name, $value, 'checkbox', $attribs );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $heading (optional)
|
||||
* @return string of HTML representing a box.
|
||||
*/
|
||||
public static function messageBox( $html, $className, $heading = '' ) {
|
||||
if ( $heading ) {
|
||||
$html = self::element( 'h2', [], $heading ) . $html;
|
||||
}
|
||||
return self::rawElement( 'div', [ 'class' => $className ], $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a warning box.
|
||||
* @since 1.31
|
||||
* @param string $html of contents of box
|
||||
* @return string of HTML representing a warning box.
|
||||
*/
|
||||
public static function warningBox( $html ) {
|
||||
return self::messageBox( $html, 'warningbox' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an error box.
|
||||
* @since 1.31
|
||||
* @param string $html of contents of error box
|
||||
* @param string $heading (optional)
|
||||
* @return string of HTML representing an error box.
|
||||
*/
|
||||
public static function errorBox( $html, $heading = '' ) {
|
||||
return self::messageBox( $html, 'errorbox', $heading );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a success box.
|
||||
* @since 1.31
|
||||
* @param string $html of contents of box
|
||||
* @return string of HTML representing a success box.
|
||||
*/
|
||||
public static function successBox( $html ) {
|
||||
return self::messageBox( $html, 'successbox' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to produce a radio button (input element with type=radio)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class MWException extends Exception {
|
|||
} else {
|
||||
$logId = WebRequest::getRequestId();
|
||||
$type = static::class;
|
||||
return "<div class=\"errorbox\">" .
|
||||
return Html::errorBox(
|
||||
'[' . $logId . '] ' .
|
||||
gmdate( 'Y-m-d H:i:s' ) . ": " .
|
||||
$this->msg( "internalerror-fatal-exception",
|
||||
|
|
@ -110,7 +110,7 @@ class MWException extends Exception {
|
|||
$type,
|
||||
$logId,
|
||||
MWExceptionHandler::getURL( $this )
|
||||
) . "</div>\n" .
|
||||
) ) .
|
||||
"<!-- Set \$wgShowExceptionDetails = true; " .
|
||||
"at the bottom of LocalSettings.php to show detailed " .
|
||||
"debugging information. -->";
|
||||
|
|
|
|||
|
|
@ -590,7 +590,7 @@ class Article implements Page {
|
|||
$outputPage->setRobotPolicy( 'noindex,nofollow' );
|
||||
|
||||
$errortext = $error->getWikiText( false, 'view-pool-error' );
|
||||
$outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
|
||||
$outputPage->addWikiText( Html::errorBox( $errortext ) );
|
||||
}
|
||||
# Connection or timeout error
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -96,12 +96,9 @@ class SkinFallbackTemplate extends BaseTemplate {
|
|||
* warning message and page content.
|
||||
*/
|
||||
public function execute() {
|
||||
$this->html( 'headelement' ) ?>
|
||||
|
||||
<div class="warningbox">
|
||||
<?php echo $this->buildHelpfulInformationMessage() ?>
|
||||
</div>
|
||||
|
||||
$this->html( 'headelement' );
|
||||
echo Html::warningBox( $this->buildHelpfulInformationMessage() );
|
||||
?>
|
||||
<form action="<?php $this->text( 'wgScript' ) ?>">
|
||||
<input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>" />
|
||||
<h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
|
||||
|
|
|
|||
|
|
@ -451,9 +451,8 @@ class SpecialEditTags extends UnlistedSpecialPage {
|
|||
*/
|
||||
protected function failure( $status ) {
|
||||
$this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
|
||||
$this->getOutput()->addWikiText( '<div class="errorbox">' .
|
||||
$status->getWikiText( 'tags-edit-failure' ) .
|
||||
'</div>'
|
||||
$this->getOutput()->addWikiText(
|
||||
Html::errorBox( $status->getWikiText( 'tags-edit-failure' ) )
|
||||
);
|
||||
$this->showForm();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,18 +235,18 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
}
|
||||
|
||||
if ( count( $err ) ) {
|
||||
$out->addHTML( "<div class='errorbox'>\n" );
|
||||
$action_desc = $this->msg( 'action-move' )->plain();
|
||||
$out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
|
||||
$errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
|
||||
count( $err ), $action_desc )->parseAsBlock();
|
||||
|
||||
if ( count( $err ) == 1 ) {
|
||||
$errMsg = $err[0];
|
||||
$errMsgName = array_shift( $errMsg );
|
||||
|
||||
if ( $errMsgName == 'hookaborted' ) {
|
||||
$out->addHTML( "<p>{$errMsg[0]}</p>\n" );
|
||||
$errMsgHtml .= "<p>{$errMsg[0]}</p>\n";
|
||||
} else {
|
||||
$out->addWikiMsgArray( $errMsgName, $errMsg );
|
||||
$errMsgHtml .= $this->msg( $errMsgName, $errMsg )->parseAsBlock();
|
||||
}
|
||||
} else {
|
||||
$errStr = [];
|
||||
|
|
@ -260,9 +260,9 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
}
|
||||
}
|
||||
|
||||
$out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
|
||||
$errMsgHtml .= '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n";
|
||||
}
|
||||
$out->addHTML( "</div>\n" );
|
||||
$out->addHTML( Html::errorBox( $errMsgHtml ) );
|
||||
}
|
||||
|
||||
if ( $this->oldTitle->isProtected( 'move' ) ) {
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
|
|||
$outputPage = $this->getOutput();
|
||||
$title = Title::newFromText( $target );
|
||||
if ( !$title || $title->isExternal() ) {
|
||||
$outputPage->addHTML( '<div class="errorbox">' . $this->msg( 'allpagesbadtitle' )
|
||||
->parse() . '</div>' );
|
||||
$outputPage->addHTML(
|
||||
Html::errorBox( $this->msg( 'allpagesbadtitle' )->parse() )
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class SpecialResetTokens extends FormSpecialPage {
|
|||
|
||||
public function onSuccess() {
|
||||
$this->getOutput()->wrapWikiMsg(
|
||||
"<div class='successbox'>\n$1\n</div>",
|
||||
Html::successBox( '$1' ),
|
||||
'resettokens-done'
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -636,9 +636,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
|
|||
protected function failure( $status ) {
|
||||
// Messages: revdelete-failure, logdelete-failure
|
||||
$this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
|
||||
$this->getOutput()->addWikiText( '<div class="errorbox">' .
|
||||
$status->getWikiText( $this->typeLabels['failure'] ) .
|
||||
'</div>'
|
||||
$this->getOutput()->addWikiText(
|
||||
Html::errorBox(
|
||||
$status->getWikiText( $this->typeLabels['failure'] )
|
||||
)
|
||||
);
|
||||
$this->showForm();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,16 +365,12 @@ class SpecialSearch extends SpecialPage {
|
|||
if ( $hasErrors ) {
|
||||
list( $error, $warning ) = $textStatus->splitByErrorType();
|
||||
if ( $error->getErrors() ) {
|
||||
$out->addHTML( Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'errorbox' ],
|
||||
$out->addHTML( Html::errorBox(
|
||||
$error->getHTML( 'search-error' )
|
||||
) );
|
||||
}
|
||||
if ( $warning->getErrors() ) {
|
||||
$out->addHTML( Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'warningbox' ],
|
||||
$out->addHTML( Html::warningBox(
|
||||
$warning->getHTML( 'search-warning' )
|
||||
) );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue