From 0f17e47d88cee7d3a616ca03517b8d6a5a3e6001 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 4 Oct 2020 14:38:18 +0200 Subject: [PATCH] Use HTMLForm features instead of mSubmit Rely on modern HTMLForm features instead of using a dedicated class property. The form identifiers are necessary, because these forms are GET forms, and HTMLForm will always think that the form was submitted, if it doesn't have an identifier (see T238467 and related tasks/patches). Additionally, make the first form on ViewRevert a GET form, like on Special:AbuseLog. Bug: T263627 Change-Id: Ia6ca45896732742ef73e401b09663728b9e7dda2 --- includes/Views/AbuseFilterView.php | 4 - includes/Views/AbuseFilterViewExamine.php | 22 ++- includes/Views/AbuseFilterViewRevert.php | 161 ++++++++++++---------- 3 files changed, 96 insertions(+), 91 deletions(-) diff --git a/includes/Views/AbuseFilterView.php b/includes/Views/AbuseFilterView.php index 18d2c3857..8c5916589 100644 --- a/includes/Views/AbuseFilterView.php +++ b/includes/Views/AbuseFilterView.php @@ -5,10 +5,6 @@ use MediaWiki\Linker\LinkRenderer; use Wikimedia\Rdbms\IDatabase; abstract class AbuseFilterView extends ContextSource { - /** - * @var bool Whether the form was submitted - */ - public $mSubmit; /** * @var array The parameters of the current request */ diff --git a/includes/Views/AbuseFilterViewExamine.php b/includes/Views/AbuseFilterViewExamine.php index 2bed84ad8..94968c618 100644 --- a/includes/Views/AbuseFilterViewExamine.php +++ b/includes/Views/AbuseFilterViewExamine.php @@ -82,21 +82,19 @@ class AbuseFilterViewExamine extends AbuseFilterView { ]; $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); $htmlForm->setWrapperLegendMsg( 'abusefilter-examine-legend' ) - ->addHiddenField( 'submit', 1 ) ->setSubmitTextMsg( 'abusefilter-examine-submit' ) - ->setMethod( 'get' ) - ->prepareForm() - ->displayForm( false ); - - if ( $this->mSubmit ) { - $this->showResults(); - } + ->setFormIdentifier( 'examine-select-date' ) + ->setSubmitCallback( [ $this, 'showResults' ] ) + ->showAlways(); } /** - * Show search results + * Show search results, called as submit callback by HTMLForm + * @param array $formData + * @param HTMLForm $form + * @return bool */ - public function showResults() { + public function showResults( array $formData, HTMLForm $form ) : bool { $changesList = new AbuseFilterChangesList( $this->getSkin(), $this->mTestFilter ); $output = $changesList->beginRecentChangesList(); $this->mCounter = 1; @@ -109,7 +107,8 @@ class AbuseFilterViewExamine extends AbuseFilterView { $output .= $changesList->endRecentChangesList(); - $this->getOutput()->addHTML( $output ); + $form->addPostText( $output ); + return true; } /** @@ -257,7 +256,6 @@ class AbuseFilterViewExamine extends AbuseFilterView { $request = $this->getRequest(); $this->mSearchPeriodStart = $request->getText( 'wpSearchPeriodStart' ); $this->mSearchPeriodEnd = $request->getText( 'wpSearchPeriodEnd' ); - $this->mSubmit = $request->getCheck( 'submit' ); $this->mTestFilter = $request->getText( 'testfilter' ); // Normalise username diff --git a/includes/Views/AbuseFilterViewRevert.php b/includes/Views/AbuseFilterViewRevert.php index 80a1c0c66..7b128653b 100644 --- a/includes/Views/AbuseFilterViewRevert.php +++ b/includes/Views/AbuseFilterViewRevert.php @@ -91,90 +91,102 @@ class AbuseFilterViewRevert extends AbuseFilterView { ]; HTMLForm::factory( 'ooui', $searchFields, $this->getContext() ) - ->addHiddenField( 'submit', 1 ) ->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() ) ->setWrapperLegendMsg( 'abusefilter-revert-search-legend' ) ->setSubmitTextMsg( 'abusefilter-revert-search' ) - ->setMethod( 'post' ) - ->prepareForm() - ->displayForm( false ); + ->setMethod( 'get' ) + ->setFormIdentifier( 'revert-select-date' ) + ->setSubmitCallback( [ $this, 'showRevertableActions' ] ) + ->showAlways(); + } - if ( $this->mSubmit ) { - // Add a summary of everything that will be reversed. - $out->addWikiMsg( 'abusefilter-revert-preview-intro' ); + /** + * Show revertable actions, called as submit callback by HTMLForm + * @param array $formData + * @param HTMLForm $dateForm + * @return bool + */ + public function showRevertableActions( array $formData, HTMLForm $dateForm ) : bool { + $lang = $this->getLanguage(); + $user = $this->getUser(); + $filter = $this->filter; - // Look up all of them. - $results = $this->doLookup(); - $list = []; + // Add a summary of everything that will be reversed. + $dateForm->addPostText( $this->msg( 'abusefilter-revert-preview-intro' )->parseAsBlock() ); - $context = $this->getContext(); - foreach ( $results as $result ) { - $displayActions = []; - foreach ( $result['actions'] as $action ) { - $displayActions[] = AbuseFilter::getActionDisplay( $action, $context ); - } + // Look up all of them. + $results = $this->doLookup(); + $list = []; - $msg = $this->msg( 'abusefilter-revert-preview-item' ) - ->params( - $lang->timeanddate( $result['timestamp'], true ) - )->rawParams( - Linker::userLink( $result['userid'], $result['user'] ) - )->params( - $result['action'] - )->rawParams( - $this->linkRenderer->makeLink( $result['title'] ) - )->params( - $lang->commaList( $displayActions ) - )->rawParams( - $this->linkRenderer->makeLink( - SpecialPage::getTitleFor( 'AbuseLog' ), - $this->msg( 'abusefilter-log-detailslink' )->text(), - [], - [ 'details' => $result['id'] ] - ) - )->params( $result['user'] )->parse(); - $list[] = Xml::tags( 'li', null, $msg ); + $context = $this->getContext(); + foreach ( $results as $result ) { + $displayActions = []; + foreach ( $result['actions'] as $action ) { + $displayActions[] = AbuseFilter::getActionDisplay( $action, $context ); } - $out->addHTML( Xml::tags( 'ul', null, implode( "\n", $list ) ) ); - - // Add a button down the bottom. - $confirmForm = []; - $confirmForm['edittoken'] = [ - 'type' => 'hidden', - 'name' => 'editToken', - 'default' => $user->getEditToken( "abusefilter-revert-$filter" ) - ]; - $confirmForm['title'] = [ - 'type' => 'hidden', - 'name' => 'title', - 'default' => $this->getTitle( "revert/$filter" )->getPrefixedDBkey() - ]; - $confirmForm['wpPeriodStart'] = [ - 'type' => 'hidden', - 'name' => 'wpPeriodStart', - 'default' => $this->origPeriodStart - ]; - $confirmForm['wpPeriodEnd'] = [ - 'type' => 'hidden', - 'name' => 'wpPeriodEnd', - 'default' => $this->origPeriodEnd - ]; - $confirmForm['reason'] = [ - 'type' => 'text', - 'label-message' => 'abusefilter-revert-reasonfield', - 'name' => 'wpReason', - 'id' => 'wpReason', - ]; - HTMLForm::factory( 'ooui', $confirmForm, $this->getContext() ) - ->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() ) - ->setWrapperLegendMsg( 'abusefilter-revert-confirm-legend' ) - ->setSubmitTextMsg( 'abusefilter-revert-confirm' ) - ->setMethod( 'post' ) - ->prepareForm() - ->displayForm( false ); - + $msg = $this->msg( 'abusefilter-revert-preview-item' ) + ->params( + $lang->timeanddate( $result['timestamp'], true ) + )->rawParams( + Linker::userLink( $result['userid'], $result['user'] ) + )->params( + $result['action'] + )->rawParams( + $this->linkRenderer->makeLink( $result['title'] ) + )->params( + $lang->commaList( $displayActions ) + )->rawParams( + $this->linkRenderer->makeLink( + SpecialPage::getTitleFor( 'AbuseLog' ), + $this->msg( 'abusefilter-log-detailslink' )->text(), + [], + [ 'details' => $result['id'] ] + ) + )->params( $result['user'] )->parse(); + $list[] = Xml::tags( 'li', null, $msg ); } + + $dateForm->addPostText( Xml::tags( 'ul', null, implode( "\n", $list ) ) ); + + // Add a button down the bottom. + $confirmForm = []; + $confirmForm['edittoken'] = [ + 'type' => 'hidden', + 'name' => 'editToken', + 'default' => $user->getEditToken( "abusefilter-revert-$filter" ) + ]; + $confirmForm['title'] = [ + 'type' => 'hidden', + 'name' => 'title', + 'default' => $this->getTitle( "revert/$filter" )->getPrefixedDBkey() + ]; + $confirmForm['wpPeriodStart'] = [ + 'type' => 'hidden', + 'name' => 'wpPeriodStart', + 'default' => $this->origPeriodStart + ]; + $confirmForm['wpPeriodEnd'] = [ + 'type' => 'hidden', + 'name' => 'wpPeriodEnd', + 'default' => $this->origPeriodEnd + ]; + $confirmForm['reason'] = [ + 'type' => 'text', + 'label-message' => 'abusefilter-revert-reasonfield', + 'name' => 'wpReason', + 'id' => 'wpReason', + ]; + + $revertForm = HTMLForm::factory( 'ooui', $confirmForm, $this->getContext() ) + ->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() ) + ->setWrapperLegendMsg( 'abusefilter-revert-confirm-legend' ) + ->setSubmitTextMsg( 'abusefilter-revert-confirm' ) + ->prepareForm() + ->getHTML( true ); + $dateForm->addPostText( $revertForm ); + + return true; } /** @@ -248,7 +260,6 @@ class AbuseFilterViewRevert extends AbuseFilterView { $this->mPeriodStart = strtotime( $this->origPeriodStart ) ?: null; $this->origPeriodEnd = $request->getText( 'wpPeriodEnd' ); $this->mPeriodEnd = strtotime( $this->origPeriodEnd ) ?: null; - $this->mSubmit = $request->getBool( 'submit' ); $this->mReason = $request->getVal( 'wpReason' ); }