jenkins-bot has submitted this change and it was merged.
Change subject: Convert SpecialRedirectEntity to HTMLForm in 'ooui' mode
......................................................................
Convert SpecialRedirectEntity to HTMLForm in 'ooui' mode
Bug: T48248
Change-Id: I1eb2deb59482e32c0f70144caba462f5e236231f
---
M repo/includes/specials/SpecialRedirectEntity.php
M repo/tests/phpunit/includes/specials/SpecialRedirectEntityTest.php
2 files changed, 69 insertions(+), 98 deletions(-)
Approvals:
Addshore: Checked; Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/specials/SpecialRedirectEntity.php
b/repo/includes/specials/SpecialRedirectEntity.php
index 110a228..cc28730 100644
--- a/repo/includes/specials/SpecialRedirectEntity.php
+++ b/repo/includes/specials/SpecialRedirectEntity.php
@@ -3,6 +3,7 @@
namespace Wikibase\Repo\Specials;
use Exception;
+use HTMLForm;
use Html;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Services\EntityId\EntityIdParser;
@@ -149,7 +150,7 @@
* @param EntityId $toId
*/
private function redirectEntity( EntityId $fromId, EntityId $toId ) {
- $this->tokenCheck->checkRequestToken( $this->getRequest(),
'token' );
+ $this->tokenCheck->checkRequestToken( $this->getRequest(),
'wpEditToken' );
$this->interactor->createRedirect( $fromId, $toId, false );
@@ -164,67 +165,38 @@
* Creates the HTML form for redirecting an entity
*/
protected function createForm() {
- $out = $this->getOutput();
- $out->addModuleStyles( array( 'wikibase.special' ) );
+ $this->getOutput()->addModuleStyles( array( 'wikibase.special'
) );
+ $pre = '';
if ( $this->getUser()->isAnon() ) {
- $out->addHTML(
- Html::rawElement(
- 'p',
- array( 'class' => 'warning' ),
- $this->msg(
- 'wikibase-anonymouseditwarning',
- $this->msg( 'wikibase-entity'
)->text()
- )->parse()
- )
+ $pre = Html::rawElement(
+ 'p',
+ array( 'class' => 'warning' ),
+ $this->msg(
+ 'wikibase-anonymouseditwarning',
+ $this->msg( 'wikibase-entity' )->text()
+ )->parse()
);
}
- // Form header
- $out->addHTML(
- Html::openElement(
- 'form',
- array(
- 'method' => 'post',
- 'action' =>
$this->getPageTitle()->getFullUrl(),
- 'name' => 'redirectentity',
- 'id' => 'wb-redirectentity-form1',
- 'class' => 'wb-form'
- )
- )
- . Html::openElement(
- 'fieldset',
- array( 'class' => 'wb-fieldset' )
- )
- . Html::element(
- 'legend',
- array( 'class' => 'wb-legend' ),
- $this->msg( 'special-redirectentity' )->text()
- )
- );
-
// Form elements
- $out->addHTML( $this->getFormElements() );
+ $formDescriptor = $this->getFormElements();
- // Form body
- $out->addHTML(
- Html::input(
- 'wikibase-redirectentity-submit',
- $this->msg( 'wikibase-redirectentity-submit'
)->text(),
- 'submit',
- array(
- 'id' => 'wb-redirectentity-submit',
- 'class' => 'wb-button'
- )
- )
- . Html::input(
- 'token',
- $this->getUser()->getEditToken(),
- 'hidden'
- )
- . Html::closeElement( 'fieldset' )
- . Html::closeElement( 'form' )
+ $formDescriptor['submit'] = array(
+ 'name' => 'wikibase-redirectentity-submit',
+ 'section' => 'redirectentity', // special-redirectentity
+ 'default' => $this->msg(
'wikibase-redirectentity-submit' )->text(),
+ 'type' => 'submit',
+ 'id' => 'wb-redirectentity-submit',
+ 'cssclass' => 'wb-button'
);
+
+ HTMLForm::factory( 'ooui', $formDescriptor,
$this->getContext(), 'special' )
+ ->setId( 'wb-redirectentity-form1' )
+ ->setPreText( $pre )
+ ->suppressDefaultSubmit()
+ ->setSubmitCallback( function () {// no-op
+ } )->show();
}
/**
@@ -233,42 +205,26 @@
* @return string
*/
protected function getFormElements() {
- return Html::element(
- 'label',
- array(
- 'for' => 'wb-redirectentity-fromid',
- 'class' => 'wb-label'
+ return array(
+ 'fromid' => array(
+ 'name' => 'fromid',
+ 'section' => 'redirectentity', //
special-redirectentity
+ 'default' => $this->getRequest()->getVal(
'fromid' ),
+ 'type' => 'text',
+ 'cssclass' => 'wb-input',
+ 'id' => 'wb-redirectentity-fromid',
+ 'label-message' =>
'wikibase-redirectentity-fromid'
),
- $this->msg( 'wikibase-redirectentity-fromid' )->text()
- )
- . Html::input(
- 'fromid',
- $this->getRequest()->getVal( 'fromid' ),
- 'text',
- array(
- 'class' => 'wb-input',
- 'id' => 'wb-redirectentity-fromid'
+ 'toid' => array(
+ 'name' => 'toid',
+ 'section' => 'redirectentity', //
special-redirectentity
+ 'default' => $this->getRequest()->getVal(
'toid' ),
+ 'type' => 'text',
+ 'cssclass' => 'wb-input',
+ 'id' => 'wb-redirectentity-toid',
+ 'label-message' =>
'wikibase-redirectentity-toid'
)
- )
- . Html::element( 'br' )
- . Html::element(
- 'label',
- array(
- 'for' => 'wb-redirectentity-toid',
- 'class' => 'wb-label'
- ),
- $this->msg( 'wikibase-redirectentity-toid' )->text()
- )
- . Html::input(
- 'toid',
- $this->getRequest()->getVal( 'toid' ),
- 'text',
- array(
- 'class' => 'wb-input',
- 'id' => 'wb-redirectentity-toid'
- )
- )
- . Html::element( 'br' );
+ );
}
}
diff --git a/repo/tests/phpunit/includes/specials/SpecialRedirectEntityTest.php
b/repo/tests/phpunit/includes/specials/SpecialRedirectEntityTest.php
index 0a15524..5266579 100644
--- a/repo/tests/phpunit/includes/specials/SpecialRedirectEntityTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialRedirectEntityTest.php
@@ -138,8 +138,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 );
@@ -149,26 +149,41 @@
public function testForm() {
$matchers['fromid'] = array(
- 'tag' => 'input',
+ 'tag' => 'div',
'attributes' => array(
'id' => 'wb-redirectentity-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-redirectentity-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-redirectentity-submit',
'class' => 'wb-button',
- 'type' => 'submit',
- 'name' => 'wikibase-redirectentity-submit',
+ ),
+ 'child' => array(
+ 'tag' => 'button',
+ 'attributes' => array(
+ 'type' => 'submit',
+ 'name' =>
'wikibase-redirectentity-submit',
+ )
) );
$output = $this->executeSpecialEntityRedirect( array() );
@@ -257,7 +272,7 @@
'p' => array( 'fromid' => 'Q1', 'toid' => 'P1'
),
'e' =>
'Wikibase\Repo\Interactors\RedirectCreationException:target-is-incompatible' ),
array( //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/234317
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1eb2deb59482e32c0f70144caba462f5e236231f
Gerrit-PatchSet: 5
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: Ricordisamoa <[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