From 65a8e68ec07d7eed10d868f4338f29cbbcefa992 Mon Sep 17 00:00:00 2001 From: Jayprakash12345 <0freerunning@gmail.com> Date: Sun, 27 May 2018 00:55:24 +0530 Subject: [PATCH] Convert file delete to use OOUI MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also make a few changes for consistency with normal delete form: * Add `autofocus` attribute on the "Other/additional reason" text field * Remove bold styling from "Suppress â¦" checkbox label * Remove `class="wpReasonDropDown"` from the "Reason" dropdown * Remove `id="wpDeleteSuppressRow"` from the "Suppress â¦" form row Bug: T173997 Change-Id: Ia5a0412c959c6149b01afe7fc6cbf5e8591673ac --- includes/FileDeleteForm.php | 219 +++++++++++------- resources/Resources.php | 1 + .../mediawiki.action.delete.file.js | 10 +- 3 files changed, 135 insertions(+), 95 deletions(-) diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 898005ecc9..eb0052c7e4 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -79,7 +79,7 @@ class FileDeleteForm { $this->oldimage = $wgRequest->getText( 'oldimage', false ); $token = $wgRequest->getText( 'wpEditToken' ); # Flag to hide all contents of the archived revisions - $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); + $suppress = $wgRequest->getCheck( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); if ( $this->oldimage ) { $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( @@ -249,101 +249,140 @@ class FileDeleteForm { $conf = RequestContext::getMain()->getConfig(); $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD; - if ( $wgUser->isAllowed( 'suppressrevision' ) ) { - $suppress = "
' . $link . '
'; - } - $wgOut->addHTML( $form ); + $fields[] = new OOUI\FieldLayout( + new OOUI\ButtonInputWidget( [ + 'name' => 'mw-filedelete-submit', + 'inputId' => 'mw-filedelete-submit', + 'tabIndex' => 4, + 'value' => $wgOut->msg( 'filedelete-submit' )->text(), + 'label' => $wgOut->msg( 'filedelete-submit' )->text(), + 'flags' => [ 'primary', 'destructive' ], + 'type' => 'submit', + ] ), + [ + 'align' => 'top', + ] + ); + + $fieldset = new OOUI\FieldsetLayout( [ + 'label' => $wgOut->msg( 'filedelete-legend' )->text(), + 'items' => $fields, + ] ); + + $form = new OOUI\FormLayout( [ + 'method' => 'post', + 'action' => $this->getAction(), + 'id' => 'mw-img-deleteconfirm', + ] ); + $form->appendContent( + $fieldset, + new OOUI\HtmlSnippet( + Html::hidden( 'wpEditToken', $wgUser->getEditToken( $this->oldimage ) ) + ) + ); + + $wgOut->addHTML( + new OOUI\PanelLayout( [ + 'classes' => [ 'deletepage-wrapper' ], + 'expanded' => false, + 'padded' => true, + 'framed' => true, + 'content' => $form, + ] ) + ); + + if ( $wgUser->isAllowed( 'editinterface' ) ) { + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); + $link = $linkRenderer->makeKnownLink( + $wgOut->msg( 'filedelete-reason-dropdown' )->inContentLanguage()->getTitle(), + wfMessage( 'filedelete-edit-reasonlist' )->text(), + [], + [ 'action' => 'edit' ] + ); + $wgOut->addHTML( '' . $link . '
' ); + } } /** diff --git a/resources/Resources.php b/resources/Resources.php index 4e0a452776..56dfaf9527 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1435,6 +1435,7 @@ return [ 'mediawiki.action.delete.file' => [ 'scripts' => 'resources/src/mediawiki.action/mediawiki.action.delete.file.js', 'dependencies' => [ + 'oojs-ui-core', 'jquery.lengthLimit', ], 'messages' => [ diff --git a/resources/src/mediawiki.action/mediawiki.action.delete.file.js b/resources/src/mediawiki.action/mediawiki.action.delete.file.js index 7dcdc81552..c282d6ac81 100644 --- a/resources/src/mediawiki.action/mediawiki.action.delete.file.js +++ b/resources/src/mediawiki.action/mediawiki.action.delete.file.js @@ -6,11 +6,11 @@ var colonSeparator = mw.message( 'colon-separator' ).text(), summaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ), summaryByteLimit = mw.config.get( 'wgCommentByteLimit' ), - $wpDeleteReasonList = $( '#wpDeleteReasonList' ), - $wpReason = $( '#wpReason' ), + reasonList = OO.ui.infuse( $( '#wpDeleteReasonList' ).closest( '.oo-ui-widget' ) ), + reason = OO.ui.infuse( $( '#wpReason' ).closest( '.oo-ui-widget' ) ), filterFn = function ( input ) { // Should be built the same as in SpecialRevisionDelete::submit() - var comment = $wpDeleteReasonList.val(); + var comment = reasonList.getValue(); if ( comment === 'other' ) { comment = input; } else if ( input !== '' ) { @@ -22,9 +22,9 @@ // Limit to bytes or UTF-8 codepoints, depending on MediaWiki's configuration if ( summaryCodePointLimit ) { - $wpReason.codePointLimit( summaryCodePointLimit, filterFn ); + reason.$input.codePointLimit( summaryCodePointLimit, filterFn ); } else if ( summaryByteLimit ) { - $wpReason.byteLimit( summaryByteLimit, filterFn ); + reason.$input.byteLimit( summaryByteLimit, filterFn ); } } ); -- 2.20.1