=== 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 ===
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)
*
} 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",
$type,
$logId,
MWExceptionHandler::getURL( $this )
- ) . "</div>\n" .
+ ) ) .
"<!-- Set \$wgShowExceptionDetails = true; " .
"at the bottom of LocalSettings.php to show detailed " .
"debugging information. -->";
$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;
* 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>
*/
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();
}
}
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 = [];
}
}
- $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' ) ) {
$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;
}
public function onSuccess() {
$this->getOutput()->wrapWikiMsg(
- "<div class='successbox'>\n$1\n</div>",
+ Html::successBox( '$1' ),
'resettokens-done'
);
}
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();
}
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' )
) );
}