jenkins-bot has submitted this change and it was merged.

Change subject: Convert SpecialMergeItems to HTMLForm in 'ooui' mode
......................................................................


Convert SpecialMergeItems to HTMLForm in 'ooui' mode

Bug: T48248
Change-Id: I2b666e550122f4d5f3e3464a7df614654ddcc57e
---
M repo/includes/specials/SpecialMergeItems.php
M repo/tests/phpunit/includes/specials/SpecialMergeItemsTest.php
2 files changed, 61 insertions(+), 106 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/specials/SpecialMergeItems.php 
b/repo/includes/specials/SpecialMergeItems.php
index 5007f93..e1b699c 100644
--- a/repo/includes/specials/SpecialMergeItems.php
+++ b/repo/includes/specials/SpecialMergeItems.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\Specials;
 
 use Exception;
+use HTMLForm;
 use Html;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Entity\EntityIdParser;
@@ -177,7 +178,7 @@
         * @param string $summary
         */
        private function mergeItems( ItemId $fromId, ItemId $toId, array 
$ignoreConflicts, $summary ) {
-               $this->tokenCheck->checkRequestToken( $this->getRequest(), 
'token' );
+               $this->tokenCheck->checkRequestToken( $this->getRequest(), 
'wpEditToken' );
 
                /** @var EntityRevision $newRevisionFrom  */
                /** @var EntityRevision $newRevisionTo */
@@ -199,112 +200,52 @@
        protected function createForm() {
                $this->getOutput()->addModuleStyles( array( 'wikibase.special' 
) );
 
+               $pre = '';
                if ( $this->getUser()->isAnon() ) {
-                       $this->getOutput()->addHTML(
-                               Html::rawElement(
-                                       'p',
-                                       array( 'class' => 'warning' ),
-                                       $this->msg(
-                                               'wikibase-anonymouseditwarning',
-                                               $this->msg( 
'wikibase-entity-item' )->text()
-                                       )->parse()
-                               )
+                       $pre = Html::rawElement(
+                               'p',
+                               array( 'class' => 'warning' ),
+                               $this->msg(
+                                       'wikibase-anonymouseditwarning',
+                                       $this->msg( 'wikibase-entity-item' 
)->text()
+                               )->parse()
                        );
                }
 
-               // Form header
-               $this->getOutput()->addHTML(
-                       Html::openElement(
-                               'form',
-                               array(
-                                       'method' => 'post',
-                                       'action' => 
$this->getPageTitle()->getFullUrl(),
-                                       'name' => 'mergeitems',
-                                       'id' => 'wb-mergeitems-form1',
-                                       'class' => 'wb-form'
-                               )
-                       )
-                       . Html::openElement(
-                               'fieldset',
-                               array( 'class' => 'wb-fieldset' )
-                       )
-                       . Html::element(
-                               'legend',
-                               array( 'class' => 'wb-legend' ),
-                               $this->msg( 'special-mergeitems' )->text()
-                       )
-               );
-
-               // Form elements
-               $this->getOutput()->addHTML( $this->getFormElements() );
-
-               // Form body
-               $this->getOutput()->addHTML(
-                       Html::element( 'br' )
-                       . Html::input(
-                               'wikibase-mergeitems-submit',
-                               $this->msg( 'wikibase-mergeitems-submit' 
)->text(),
-                               'submit',
-                               array(
-                                       'id' => 'wb-mergeitems-submit',
-                                       'class' => 'wb-button'
-                               )
-                       )
-                       . Html::input(
-                               'token',
-                               $this->getUser()->getEditToken(),
-                               'hidden'
-                       )
-                       . Html::closeElement( 'fieldset' )
-                       . Html::closeElement( 'form' )
-               );
+               HTMLForm::factory( 'ooui', $this->getFormElements(), 
$this->getContext() )
+                       ->setId( 'wb-mergeitems-form1' )
+                       ->setPreText( $pre )
+                       ->setHeaderText( $this->msg( 
'wikibase-mergeitems-intro' )->parse() )
+                       ->setSubmitID( 'wb-mergeitems-submit' )
+                       ->setSubmitName( 'wikibase-mergeitems-submit' )
+                       ->setSubmitTextMsg( 'wikibase-mergeitems-submit' )
+                       ->setWrapperLegendMsg( 'special-mergeitems' )
+                       ->setSubmitCallback( function () {// no-op
+                       } )->show();
        }
 
        /**
         * Returns the form elements.
         *
-        * @return string
+        * @return array
         */
        protected function getFormElements() {
-               return Html::rawElement(
-                       'p',
-                       array(),
-                       // Message: wikibase-mergeitems-intro
-                       $this->msg( 'wikibase-mergeitems-intro' )->parse()
-               )
-               . Html::element(
-                       'label',
-                       array(
-                               'for' => 'wb-mergeitems-fromid',
-                               'class' => 'wb-label'
+               return array(
+                       'fromid' => array(
+                               'name' => 'fromid',
+                               'default' => $this->getRequest()->getVal( 
'fromid' ),
+                               'type' => 'text',
+                               'cssclass' => 'wb-input',
+                               'id' => 'wb-mergeitems-fromid',
+                               'label-message' => 'wikibase-mergeitems-fromid'
                        ),
-                       $this->msg( 'wikibase-mergeitems-fromid' )->text()
-               )
-               . Html::input(
-                       'fromid',
-                       $this->getRequest()->getVal( 'fromid' ),
-                       'text',
-                       array(
-                               'class' => 'wb-input',
-                               'id' => 'wb-mergeitems-fromid'
-                       )
-               )
-               . Html::element( 'br' )
-               . Html::element(
-                       'label',
-                       array(
-                               'for' => 'wb-mergeitems-toid',
-                               'class' => 'wb-label'
-                       ),
-                       $this->msg( 'wikibase-mergeitems-toid' )->text()
-               )
-               . Html::input(
-                       'toid',
-                       $this->getRequest()->getVal( 'toid' ),
-                       'text',
-                       array(
-                               'class' => 'wb-input',
-                               'id' => 'wb-mergeitems-toid'
+                       'toid' => array(
+                               'name' => 'toid',
+                               'default' => $this->getRequest()->getVal( 
'toid' ),
+                               'type' => 'text',
+                               'cssclass' => 'wb-input',
+                               'id' => 'wb-mergeitems-toid',
+                               'label-message' => 'wikibase-mergeitems-toid'
                        )
                );
                // TODO: Selector for ignoreconflicts
diff --git a/repo/tests/phpunit/includes/specials/SpecialMergeItemsTest.php 
b/repo/tests/phpunit/includes/specials/SpecialMergeItemsTest.php
index 75dd9e0..648a786 100644
--- a/repo/tests/phpunit/includes/specials/SpecialMergeItemsTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialMergeItemsTest.php
@@ -163,8 +163,8 @@
                // HACK: we need this in newSpecialPage, but executeSpecialPage 
doesn't pass the context on.
                $this->user = $user;
 
-               if ( !isset( $params['token'] ) ) {
-                       $params['token'] = $user->getEditToken();
+               if ( !isset( $params['wpEditToken'] ) ) {
+                       $params['wpEditToken'] = $user->getEditToken();
                }
 
                $request = new \FauxRequest( $params, true );
@@ -174,26 +174,40 @@
 
        public function testForm() {
                $matchers['fromid'] = array(
-                       'tag' => 'input',
+                       'tag' => 'div',
                        'attributes' => array(
                                'id' => 'wb-mergeitems-fromid',
                                'class' => 'wb-input',
-                               'name' => 'fromid',
+                       ),
+                       'child' => array(
+                               'tag' => 'input',
+                               'attributes' => array(
+                                       'name' => 'fromid',
+                               )
                        ) );
                $matchers['toid'] = array(
-                       'tag' => 'input',
+                       'tag' => 'div',
                        'attributes' => array(
                                'id' => 'wb-mergeitems-toid',
                                'class' => 'wb-input',
-                               'name' => 'toid',
+                       ),
+                       'child' => array(
+                               'tag' => 'input',
+                               'attributes' => array(
+                                       'name' => 'toid',
+                               )
                        ) );
                $matchers['submit'] = array(
-                       'tag' => 'input',
+                       'tag' => 'div',
                        'attributes' => array(
                                'id' => 'wb-mergeitems-submit',
-                               'class' => 'wb-button',
-                               'type' => 'submit',
-                               'name' => 'wikibase-mergeitems-submit',
+                       ),
+                       'child' => array(
+                               'tag' => 'button',
+                               'attributes' => array(
+                                       'type' => 'submit',
+                                       'name' => 'wikibase-mergeitems-submit',
+                               )
                        ) );
 
                $output = $this->executeSpecialMergeItems( array() );
@@ -340,7 +354,7 @@
                                'p' => array( 'fromid' => 'Q1', 'toid' => 'P1' 
),
                                'e' => 
'Wikibase\Lib\UserInputException:wikibase-itemmerge-not-item' ),
                        array( //10 bad token
-                               'p' => array( 'fromid' => 'Q1', 'toid' => 'Q2', 
'token' => 'BAD' ),
+                               'p' => array( 'fromid' => 'Q1', 'toid' => 'Q2', 
'wpEditToken' => 'BAD' ),
                                'e' => 
'Wikibase\Repo\Interactors\TokenCheckException:wikibase-tokencheck-badtoken' ),
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/236002
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2b666e550122f4d5f3e3464a7df614654ddcc57e
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to