Skip to content

Commit

Permalink
switch from html::(notice/warning/error)Box to OOUI messageWidget(typ…
Browse files Browse the repository at this point in the history
…e: (notice/warning/error)) (#128)

…e: (notice/warning/error))

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced message display using modern UI components, improving the
consistency and clarity of informational, error, and warning messages.
  
- **Style**
- Updated the styling of message boxes by switching to new CSS class
names for a more modern and cohesive user interface.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
MacFan4000 authored Feb 4, 2025
1 parent e9d4e87 commit 2df8a9f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
97 changes: 60 additions & 37 deletions includes/ImportDumpRequestViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\User\User;
use MediaWiki\WikiMap\WikiMap;
use OOUI\HtmlSnippet;
use OOUI\MessageWidget;
use UserNotLoggedIn;

class ImportDumpRequestViewer implements ImportDumpStatus {
Expand Down Expand Up @@ -70,6 +72,8 @@ public function getFormDescriptor(): array {
);
}

$this->context->getOutput()->enableOOUI();

$formDescriptor = [
'source' => [
'label-message' => 'importdump-label-source',
Expand Down Expand Up @@ -207,7 +211,8 @@ public function getFormDescriptor(): array {

$fileInfo .= Html::element( 'button', [
'type' => 'button',
'onclick' => 'navigator.clipboard.writeText( $( \'.mw-message-box-notice code\' ).text() );',
'onclick' => 'navigator.clipboard.writeText(
$( \'.oo-ui-flaggedElement-notice\' ).text() );',
],
$this->context->msg( 'importdump-button-copy' )->text()
);
Expand All @@ -226,52 +231,67 @@ public function getFormDescriptor(): array {
)->parse();
}

$info = Html::noticeBox( $fileInfo, '' );
$info = new MessageWidget( [
'label' => new HtmlSnippet( $fileInfo ),
'type' => 'notice',
] );
} else {
$info = Html::errorBox(
$this->context->msg( 'importdump-info-no-file-found',
$this->importDumpRequestManager->getFilePath()
)->escaped()
);
$info = new MessageWidget( [
'label' => new HtmlSnippet(
$this->context->msg( 'importdump-info-no-file-found',
$this->importDumpRequestManager->getFilePath()
)->escaped()
),
'type' => 'error',
] );

$validRequest = false;
if ( $status === self::STATUS_PENDING || $status === self::STATUS_INPROGRESS ) {
$status = self::STATUS_DECLINED;
}
}

$info .= Html::noticeBox(
$this->context->msg( 'importdump-info-groups',
$this->importDumpRequestManager->getRequester()->getName(),
$this->importDumpRequestManager->getTarget(),
$this->context->getLanguage()->commaList(
$this->importDumpRequestManager->getUserGroupsFromTarget()
)
)->escaped(),
''
);
$info .= new MessageWidget( [
'label' => new HtmlSnippet(
$this->context->msg( 'importdump-info-groups',
$this->importDumpRequestManager->getRequester()->getName(),
$this->importDumpRequestManager->getTarget(),
$this->context->getLanguage()->commaList(
$this->importDumpRequestManager->getUserGroupsFromTarget()
)
)->escaped(),
),
'type' => 'notice',
] );

if ( $this->importDumpRequestManager->isPrivate() ) {
$info .= Html::warningBox(
$this->context->msg( 'importdump-info-request-private' )->escaped()
);
$info .= new MessageWidget( [
'label' => new HtmlSnippet( $this->context->msg( 'importdump-info-request-private' )->escaped() ),
'type' => 'warning',
] );
}

if ( $this->importDumpRequestManager->getRequester()->getBlock() ) {
$info .= Html::warningBox(
$this->context->msg( 'importdump-info-requester-blocked',
$this->importDumpRequestManager->getRequester()->getName(),
WikiMap::getCurrentWikiId()
)->escaped()
);
$info .= new MessageWidget( [
'label' => new HtmlSnippet(
$this->context->msg( 'importdump-info-requester-blocked',
$this->importDumpRequestManager->getRequester()->getName(),
WikiMap::getCurrentWikiId()
)->escaped()
),
'type' => 'warning',
] );
}

if ( $this->importDumpRequestManager->getRequester()->isLocked() ) {
$info .= Html::errorBox(
$this->context->msg( 'importdump-info-requester-locked',
$this->importDumpRequestManager->getRequester()->getName()
)->escaped()
);
$info .= new MessageWidget( [
'label' => new HtmlSnippet(
$this->context->msg( 'importdump-info-requester-locked',
$this->importDumpRequestManager->getRequester()->getName()
)->escaped()
),
'type' => 'error',
] );

$validRequest = false;
if ( $status === self::STATUS_PENDING || $status === self::STATUS_INPROGRESS ) {
Expand All @@ -280,12 +300,15 @@ public function getFormDescriptor(): array {
}

if ( !$this->importDumpRequestManager->getInterwikiPrefix() ) {
$info .= Html::errorBox(
$this->context->msg( 'importdump-info-no-interwiki-prefix',
$this->importDumpRequestManager->getTarget(),
parse_url( $this->importDumpRequestManager->getSource(), PHP_URL_HOST )
)->escaped()
);
$info .= new MessageWidget( [
'label' => new HtmlSnippet(
$this->context->msg( 'importdump-info-no-interwiki-prefix',
$this->importDumpRequestManager->getTarget(),
parse_url( $this->importDumpRequestManager->getSource(), PHP_URL_HOST )
)->escaped()
),
'type' => 'error',
] );
}

$formDescriptor += [
Expand Down
2 changes: 1 addition & 1 deletion modules/ext.importdump.oouiform.ooui.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#importdump {
filter: brightness( 1 );

.mw-message-box-notice {
.oo-ui-flaggedElement-notice {
border-color: #33a6f1;
background: #bce5fd;

Expand Down

0 comments on commit 2df8a9f

Please sign in to comment.