mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Streamline HTML rendering code for format messages
The idea is to make it a little easier to follow what's going on here. This also improves an error message when tests fail. Change-Id: If35be8aefab5a1568d53a9ecdc4313a66f71317b
This commit is contained in:
parent
71392dc6d4
commit
e297e767f0
|
@ -31,17 +31,27 @@ class TemplateDataHtmlFormatter {
|
|||
public function getHtml( TemplateDataBlob $templateData ): string {
|
||||
$data = $templateData->getDataInLanguage( $this->languageCode );
|
||||
|
||||
if ( is_string( $data->format ) && isset( TemplateDataValidator::PREDEFINED_FORMATS[$data->format] ) ) {
|
||||
$icon = null;
|
||||
$formatMsg = null;
|
||||
if ( isset( $data->format ) && is_string( $data->format ) ) {
|
||||
$format = $data->format;
|
||||
'@phan-var string $format';
|
||||
if ( isset( TemplateDataValidator::PREDEFINED_FORMATS[$format] ) ) {
|
||||
// The following icon names are used here:
|
||||
// * template-format-block
|
||||
// * template-format-inline
|
||||
// @phan-suppress-next-line PhanTypeSuspiciousStringExpression
|
||||
$icon = 'template-format-' . $data->format;
|
||||
$formatMsg = $data->format;
|
||||
} else {
|
||||
$icon = 'settings';
|
||||
$formatMsg = $data->format ? 'custom' : null;
|
||||
$icon = 'template-format-' . $format;
|
||||
// Messages that can be used here:
|
||||
// * templatedata-doc-format-block
|
||||
// * templatedata-doc-format-inline
|
||||
$formatMsg = $this->localizer->msg( 'templatedata-doc-format-' . $format );
|
||||
}
|
||||
if ( !$formatMsg || $formatMsg->isDisabled() ) {
|
||||
$icon = 'settings';
|
||||
$formatMsg = $this->localizer->msg( 'templatedata-doc-format-custom' );
|
||||
}
|
||||
}
|
||||
|
||||
$sorting = count( (array)$data->params ) > 1 ? " sortable" : "";
|
||||
$html = '<header>'
|
||||
. Html::element( 'p',
|
||||
|
@ -60,17 +70,13 @@ class TemplateDataHtmlFormatter {
|
|||
Html::element( 'p', [],
|
||||
$this->localizer->msg( 'templatedata-doc-params' )->text()
|
||||
)
|
||||
. ( $formatMsg !== null ?
|
||||
. ( $formatMsg ?
|
||||
Html::rawElement( 'p', [],
|
||||
new \OOUI\IconWidget( [ 'icon' => $icon ] )
|
||||
. Html::element(
|
||||
'span',
|
||||
[ 'class' => 'mw-templatedata-format' ],
|
||||
// Messages that can be used here:
|
||||
// * templatedata-doc-format-block
|
||||
// * templatedata-doc-format-custom
|
||||
// * templatedata-doc-format-inline
|
||||
$this->localizer->msg( 'templatedata-doc-format-' . $formatMsg )->text()
|
||||
$formatMsg->text()
|
||||
)
|
||||
) :
|
||||
''
|
||||
|
|
|
@ -753,7 +753,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertSame(
|
||||
$case['status'],
|
||||
is_string( $case['status'] ) ? $this->getStatusText( $status ) : $status->isGood(),
|
||||
'Status: ' . $case['msg']
|
||||
$case['msg'] . ' (status "' . $this->getStatusText( $status ) . '")'
|
||||
);
|
||||
|
||||
if ( !isset( $case['output'] ) ) {
|
||||
|
|
Loading…
Reference in a new issue