2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-29 10:53:29 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\View;
|
|
|
|
|
|
|
|
use HTMLForm;
|
|
|
|
use IContextSource;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2021-02-01 15:47:46 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\EditBox\EditBoxBuilderFactory;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\EditBox\EditBoxField;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2020-11-29 10:53:29 +00:00
|
|
|
use Xml;
|
2020-09-18 14:49:13 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
class AbuseFilterViewTools extends AbuseFilterView {
|
2020-10-23 14:19:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EditBoxBuilderFactory
|
|
|
|
*/
|
|
|
|
private $boxBuilderFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
|
|
|
* @param EditBoxBuilderFactory $boxBuilderFactory
|
|
|
|
* @param IContextSource $context
|
|
|
|
* @param LinkRenderer $linkRenderer
|
|
|
|
* @param string $basePageName
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
|
|
|
EditBoxBuilderFactory $boxBuilderFactory,
|
|
|
|
IContextSource $context,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
string $basePageName,
|
|
|
|
array $params
|
|
|
|
) {
|
|
|
|
parent::__construct( $afPermManager, $context, $linkRenderer, $basePageName, $params );
|
|
|
|
$this->boxBuilderFactory = $boxBuilderFactory;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2018-03-10 03:21:04 +00:00
|
|
|
$out->enableOOUI();
|
2020-10-03 13:05:20 +00:00
|
|
|
$out->addHelpLink( 'Extension:AbuseFilter/Rules format' );
|
2018-02-04 18:50:43 +00:00
|
|
|
$request = $this->getRequest();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2021-02-19 17:50:38 +00:00
|
|
|
if ( !$this->afPermManager->canUseTestTools( $this->getUser() ) ) {
|
|
|
|
// TODO: the message still refers to the old rights
|
2018-05-04 19:56:45 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-mustviewprivateoredit' );
|
2017-07-29 16:15:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Header
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-tools-text' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
$boxBuilder = $this->boxBuilderFactory->newEditBoxBuilder( $this, $this->getUser(), $out );
|
2020-11-24 12:16:41 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Expression evaluator
|
2021-02-01 15:47:46 +00:00
|
|
|
$formDesc = [
|
|
|
|
'rules' => [
|
|
|
|
'class' => EditBoxField::class,
|
|
|
|
'html' => $boxBuilder->buildEditBox(
|
|
|
|
$request->getText( 'wpFilterRules' ),
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
]
|
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2021-02-01 15:47:46 +00:00
|
|
|
HTMLForm::factory( 'ooui', $formDesc, $this->getContext() )
|
|
|
|
->setMethod( 'GET' )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-tools-expr' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-tools-submitexpr' )
|
|
|
|
->setSubmitId( 'mw-abusefilter-submitexpr' )
|
|
|
|
->setFooterText( Xml::element( 'pre', [ 'id' => 'mw-abusefilter-expr-result' ], ' ' ) )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addModules( 'ext.abuseFilter.tools' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
if ( $this->afPermManager->canEdit( $this->getUser() ) ) {
|
2019-09-13 18:31:17 +00:00
|
|
|
// Hacky little box to re-enable autoconfirmed if it got disabled
|
|
|
|
$formDescriptor = [
|
|
|
|
'RestoreAutoconfirmed' => [
|
|
|
|
'label-message' => 'abusefilter-tools-reautoconfirm-user',
|
|
|
|
'type' => 'user',
|
|
|
|
'name' => 'wpReAutoconfirmUser',
|
|
|
|
'id' => 'reautoconfirm-user',
|
|
|
|
'infusable' => true
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
|
|
|
$htmlForm->setWrapperLegendMsg( 'abusefilter-tools-reautoconfirm' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-tools-reautoconfirm-submit' )
|
|
|
|
->setSubmitName( 'wpReautoconfirmSubmit' )
|
|
|
|
->setSubmitId( 'mw-abusefilter-reautoconfirmsubmit' )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|