jenkins-bot has submitted this change and it was merged.
Change subject: Convert SpecialNewEntity and subclasses to HTMLForm in 'ooui'
mode
......................................................................
Convert SpecialNewEntity and subclasses to HTMLForm in 'ooui' mode
Bug: T48248
Change-Id: I751be2abf819be5e287cc06a7868f1da4d3a4e34
---
M repo/includes/specials/SpecialNewEntity.php
M repo/includes/specials/SpecialNewItem.php
M repo/includes/specials/SpecialNewProperty.php
M repo/tests/phpunit/includes/specials/SpecialNewItemTest.php
M repo/tests/phpunit/includes/specials/SpecialNewPropertyTest.php
5 files changed, 116 insertions(+), 161 deletions(-)
Approvals:
Bene: Looks good to me, approved
Jonas Kress (WMDE): Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/repo/includes/specials/SpecialNewEntity.php
b/repo/includes/specials/SpecialNewEntity.php
index f535a3f..58f39e7 100644
--- a/repo/includes/specials/SpecialNewEntity.php
+++ b/repo/includes/specials/SpecialNewEntity.php
@@ -2,6 +2,7 @@
namespace Wikibase\Repo\Specials;
+use HTMLForm;
use Html;
use Language;
use Status;
@@ -99,7 +100,7 @@
$uiLanguageCode = $this->getLanguage()->getCode();
if ( $this->getRequest()->wasPosted()
- && $this->getUser()->matchEditToken(
$this->getRequest()->getVal( 'token' ) )
+ && $this->getUser()->matchEditToken(
$this->getRequest()->getVal( 'wpEditToken' ) )
) {
if ( $this->hasSufficientArguments() ) {
$entity = $this->createEntity();
@@ -114,7 +115,7 @@
$status = $this->saveEntity(
$entity,
$summary,
- $this->getRequest()->getVal(
'token' ),
+ $this->getRequest()->getVal(
'wpEditToken' ),
EDIT_NEW
);
@@ -225,79 +226,53 @@
$langCode = $this->contentLanguage->getCode();
$langName = Language::fetchLanguageName( $langCode );
$langDir = $this->contentLanguage->getDir();
- return Html::hidden(
- 'lang',
- $langCode
- )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newentity-label',
- 'class' => 'wb-label'
+ return array(
+ 'lang' => array(
+ 'name' => 'lang',
+ 'default' => $langCode,
+ 'type' => 'hidden'
),
- $this->msg( 'wikibase-newentity-label' )->text()
- )
- . Html::input(
- 'label',
- $this->label ?: '',
- 'text',
- array(
+ 'label' => array(
+ 'name' => 'label',
+ 'default' => $this->label ?: '',
+ 'type' => 'text',
'id' => 'wb-newentity-label',
- 'class' => 'wb-input',
+ 'cssclass' => 'wb-input',
'lang' => $langCode,
'dir' => $langDir,
'placeholder' => $this->msg(
'wikibase-label-edit-placeholder-language-aware',
$langName
)->text(),
- )
- )
- . Html::element( 'br' )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newentity-description',
- 'class' => 'wb-label'
+ 'label-message' => 'wikibase-newentity-label'
),
- $this->msg( 'wikibase-newentity-description' )->text()
- )
- . Html::input(
- 'description',
- $this->description ?: '',
- 'text',
- array(
+ 'description' => array(
+ 'name' => 'description',
+ 'default' => $this->description ?: '',
+ 'type' => 'text',
'id' => 'wb-newentity-description',
- 'class' => 'wb-input',
+ 'cssclass' => 'wb-input',
'lang' => $langCode,
'dir' => $langDir,
'placeholder' => $this->msg(
'wikibase-description-edit-placeholder-language-aware',
$langName
)->text(),
- )
- )
- . Html::element( 'br' )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newentity-aliases',
- 'class' => 'wb-label'
+ 'label-message' =>
'wikibase-newentity-description'
),
- $this->msg( 'wikibase-newentity-aliases' )->text()
- )
- . Html::input(
- 'aliases',
- $this->aliases ? implode( '|', $this->aliases ) : '',
- 'text',
- array(
+ 'aliases' => array(
+ 'name' => 'aliases',
+ 'default' => $this->aliases ? implode( '|',
$this->aliases ) : '',
+ 'type' => 'text',
'id' => 'wb-newentity-aliases',
- 'class' => 'wb-input',
+ 'cssclass' => 'wb-input',
'lang' => $langCode,
'dir' => $langDir,
'placeholder' => $this->msg(
'wikibase-aliases-edit-placeholder-language-aware',
$langName
)->text(),
+ 'label-message' => 'wikibase-newentity-aliases'
)
);
}
@@ -306,49 +281,19 @@
* Building the HTML form for creating a new item.
*
* @param string|null $legend initial value for the label input box
- * @param string $additionalHtml initial value for the description
input box
+ * @param array $additionalFormElements initial value for the
description input box
*/
- private function createForm( $legend = null, $additionalHtml = '' ) {
+ private function createForm( $legend = null, $additionalFormElements =
array() ) {
$this->addCopyrightText();
- $this->getOutput()->addHTML(
- Html::openElement(
- 'form',
- array(
- 'method' => 'post',
- 'action' =>
$this->getPageTitle()->getFullUrl(),
- 'name' => 'newentity',
- 'id' => 'mw-newentity-form1',
- 'class' => 'wb-form'
- )
- )
- . Html::openElement(
- 'fieldset',
- array( 'class' => 'wb-fieldset' )
- )
- . Html::element(
- 'legend',
- array( 'class' => 'wb-legend' ),
- $legend
- )
- . Html::hidden(
- 'token',
- $this->getUser()->getEditToken()
- )
- . $additionalHtml
- . Html::element( 'br' )
- . Html::input(
- 'submit',
- $this->msg( 'wikibase-newentity-submit'
)->text(),
- 'submit',
- array(
- 'id' => 'wb-newentity-submit',
- 'class' => 'wb-button'
- )
- )
- . Html::closeElement( 'fieldset' )
- . Html::closeElement( 'form' )
- );
+ HTMLForm::factory( 'ooui', $additionalFormElements,
$this->getContext() )
+ ->setId( 'mw-newentity-form1' )
+ ->setSubmitID( 'wb-newentity-submit' )
+ ->setSubmitName( 'submit' )
+ ->setSubmitTextMsg( 'wikibase-newentity-submit' )
+ ->setWrapperLegendMsg( $legend )
+ ->setSubmitCallback( function () {// no-op
+ } )->show();
}
/**
diff --git a/repo/includes/specials/SpecialNewItem.php
b/repo/includes/specials/SpecialNewItem.php
index 3b34eff..b0c2fed 100644
--- a/repo/includes/specials/SpecialNewItem.php
+++ b/repo/includes/specials/SpecialNewItem.php
@@ -2,7 +2,6 @@
namespace Wikibase\Repo\Specials;
-use Html;
use InvalidArgumentException;
use Status;
use Wikibase\DataModel\Entity\Entity;
@@ -90,50 +89,34 @@
/**
* @see SpecialNewEntity::additionalFormElements
*
- * @return string
+ * @return array
*/
protected function additionalFormElements() {
if ( $this->site === null || $this->page === null ) {
return parent::additionalFormElements();
}
- return parent::additionalFormElements()
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newitem-site',
- 'class' => 'wb-label'
- ),
- $this->msg( 'wikibase-newitem-site' )->text()
- )
- . Html::input(
- 'site',
- $this->site,
- 'text',
- array(
- 'id' => 'wb-newitem-site',
- 'class' => 'wb-input',
- 'readonly' => 'readonly'
- )
- )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newitem-page',
- 'class' => 'wb-label'
- ),
- $this->msg( 'wikibase-newitem-page' )->text()
- )
- . Html::input(
- 'page',
- $this->page,
- 'text',
- array(
- 'id' => 'wb-newitem-page',
- 'class' => 'wb-input',
- 'readonly' => 'readonly'
- )
+ $formDescriptor = parent::additionalFormElements();
+ $formDescriptor['site'] = array(
+ 'name' => 'site',
+ 'default' => $this->site,
+ 'type' => 'text',
+ 'id' => 'wb-newitem-site',
+ 'cssclass' => 'wb-input',
+ 'readonly' => 'readonly',
+ 'label-message' => 'wikibase-newitem-site'
);
+ $formDescriptor['page'] = array(
+ 'name' => 'page',
+ 'default' => $this->page,
+ 'type' => 'text',
+ 'id' => 'wb-newitem-page',
+ 'cssclass' => 'wb-input',
+ 'readonly' => 'readonly',
+ 'label-message' => 'wikibase-newitem-page'
+ );
+
+ return $formDescriptor;
}
/**
diff --git a/repo/includes/specials/SpecialNewProperty.php
b/repo/includes/specials/SpecialNewProperty.php
index fda837e..9d647f3 100644
--- a/repo/includes/specials/SpecialNewProperty.php
+++ b/repo/includes/specials/SpecialNewProperty.php
@@ -2,7 +2,6 @@
namespace Wikibase\Repo\Specials;
-use Html;
use InvalidArgumentException;
use Status;
use Wikibase\DataModel\Entity\Entity;
@@ -99,17 +98,17 @@
$selector = new DataTypeSelector( $dataTypeFactory->getTypes(),
$this->getLanguage()->getCode() );
- return parent::additionalFormElements()
- . Html::element( 'br' )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-newproperty-datatype',
- 'class' => 'wb-label'
- ),
- $this->msg( 'wikibase-newproperty-datatype'
)->text()
- )
- . $selector->getHtml( 'wb-newproperty-datatype' );
+ $formDescriptor = parent::additionalFormElements();
+ $formDescriptor['datatype'] = array(
+ 'name' => 'datatype',
+ 'type' => 'select',
+ 'options' => array_flip( $selector->getOptionsArray() ),
+ 'id' => 'wb-newproperty-datatype',
+ 'cssclass' => 'wb-select',
+ 'label-message' => 'wikibase-newproperty-datatype'
+ );
+
+ return $formDescriptor;
}
/**
diff --git a/repo/tests/phpunit/includes/specials/SpecialNewItemTest.php
b/repo/tests/phpunit/includes/specials/SpecialNewItemTest.php
index 828bad0..a5ea661 100644
--- a/repo/tests/phpunit/includes/specials/SpecialNewItemTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialNewItemTest.php
@@ -33,26 +33,40 @@
$this->setMwGlobals( 'wgGroupPermissions', array( '*' => array(
'createpage' => true ) ) );
$matchers['label'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-label',
'class' => 'wb-input',
- 'name' => 'label',
+ ),
+ 'child' => array(
+ 'tag' => 'input',
+ 'attributes' => array(
+ 'name' => 'label',
+ )
) );
$matchers['description'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-description',
'class' => 'wb-input',
- 'name' => 'description',
+ ),
+ 'child' => array(
+ 'tag' => 'input',
+ 'attributes' => array(
+ 'name' => 'description',
+ )
) );
$matchers['submit'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-submit',
- 'class' => 'wb-button',
- 'type' => 'submit',
- 'name' => 'submit',
+ ),
+ 'child' => array(
+ 'tag' => 'button',
+ 'attributes' => array(
+ 'type' => 'submit',
+ 'name' => 'submit',
+ )
) );
list( $output, ) = $this->executeSpecialPage( '' );
@@ -61,8 +75,8 @@
}
list( $output, ) = $this->executeSpecialPage(
'LabelText/DescriptionText' );
- $matchers['label']['attributes']['value'] = 'LabelText';
- $matchers['description']['attributes']['value'] =
'DescriptionText';
+ $matchers['label']['child'][0]['attributes']['value'] =
'LabelText';
+ $matchers['description']['child'][0]['attributes']['value'] =
'DescriptionText';
foreach ( $matchers as $key => $matcher ) {
$this->assertTag( $matcher, $output, "Failed to match
html output with tag '{$key}''" );
diff --git a/repo/tests/phpunit/includes/specials/SpecialNewPropertyTest.php
b/repo/tests/phpunit/includes/specials/SpecialNewPropertyTest.php
index e0b72ff..9edb69f 100644
--- a/repo/tests/phpunit/includes/specials/SpecialNewPropertyTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialNewPropertyTest.php
@@ -32,26 +32,40 @@
$this->setMwGlobals( 'wgGroupPermissions', array( '*' => array(
'property-create' => true ) ) );
$matchers['label'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-label',
'class' => 'wb-input',
- 'name' => 'label',
+ ),
+ 'child' => array(
+ 'tag' => 'input',
+ 'attributes' => array(
+ 'name' => 'label',
+ )
) );
$matchers['description'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-description',
'class' => 'wb-input',
- 'name' => 'description',
+ ),
+ 'child' => array(
+ 'tag' => 'input',
+ 'attributes' => array(
+ 'name' => 'description',
+ )
) );
$matchers['submit'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-newentity-submit',
- 'class' => 'wb-button',
- 'type' => 'submit',
- 'name' => 'submit',
+ ),
+ 'child' => array(
+ 'tag' => 'button',
+ 'attributes' => array(
+ 'type' => 'submit',
+ 'name' => 'submit',
+ )
) );
list( $output, ) = $this->executeSpecialPage( '' );
@@ -60,8 +74,8 @@
}
list( $output, ) = $this->executeSpecialPage(
'LabelText/DescriptionText' );
- $matchers['label']['attributes']['value'] = 'LabelText';
- $matchers['description']['attributes']['value'] =
'DescriptionText';
+ $matchers['label']['child'][0]['attributes']['value'] =
'LabelText';
+ $matchers['description']['child'][0]['attributes']['value'] =
'DescriptionText';
foreach ( $matchers as $key => $matcher ) {
$this->assertTag( $matcher, $output, "Failed to match
html output with tag '{$key}''" );
--
To view, visit https://gerrit.wikimedia.org/r/235407
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I751be2abf819be5e287cc06a7868f1da4d3a4e34
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Bene <[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