mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "Use HTMLForm features instead of mSubmit"
This commit is contained in:
commit
1d06f5fc4c
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -78,21 +78,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 );
|
||||
$pager = new AbuseFilterExaminePager( $this, $changesList );
|
||||
|
||||
|
@ -102,7 +100,8 @@ class AbuseFilterViewExamine extends AbuseFilterView {
|
|||
. $pager->getNavigationBar()
|
||||
. $changesList->endRecentChangesList();
|
||||
|
||||
$this->getOutput()->addHTML( $output );
|
||||
$form->addPostText( $output );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,7 +249,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
|
||||
|
|
|
@ -92,90 +92,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,7 +261,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' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue