2008-06-27 06:18:51 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-01 17:28:36 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Special;
|
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2021-04-17 16:57:38 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\CentralDBManager;
|
2020-11-29 15:18:32 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesFactory;
|
2020-12-18 14:05:33 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesRegistry;
|
2021-02-01 15:47:46 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\EditBox\EditBoxBuilderFactory;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterImporter;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterLookup;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterProfiler;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterStore;
|
2021-09-01 11:53:38 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Parser\RuleCheckerFactory;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
|
2021-01-03 13:10:20 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGeneratorFactory;
|
2021-01-02 13:41:31 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariablesBlobStore;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariablesFormatter;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
|
2020-11-29 10:53:29 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterView;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewDiff;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewEdit;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewExamine;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewHistory;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewImport;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewList;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewRevert;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewTestBatch;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\View\AbuseFilterViewTools;
|
2023-12-10 19:03:19 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2023-08-19 17:49:36 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-03-09 21:58:00 +00:00
|
|
|
use Wikimedia\ObjectFactory\ObjectFactory;
|
2020-10-23 14:19:02 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
class SpecialAbuseFilter extends AbuseFilterSpecialPage {
|
2020-10-03 13:05:20 +00:00
|
|
|
|
2020-10-03 17:13:32 +00:00
|
|
|
private const PAGE_NAME = 'AbuseFilter';
|
2013-10-15 13:22:05 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
/**
|
2020-10-23 14:19:02 +00:00
|
|
|
* @var ObjectFactory
|
|
|
|
*/
|
|
|
|
private $objectFactory;
|
|
|
|
|
|
|
|
private const SERVICES_PER_VIEW = [
|
|
|
|
AbuseFilterViewDiff::class => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
2020-10-02 15:08:48 +00:00
|
|
|
SpecsFormatter::SERVICE_NAME,
|
2021-01-04 13:46:34 +00:00
|
|
|
FilterLookup::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewEdit::class => [
|
2023-02-26 12:51:08 +00:00
|
|
|
'DBLoadBalancerFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
'PermissionManager',
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterProfiler::SERVICE_NAME,
|
|
|
|
FilterLookup::SERVICE_NAME,
|
|
|
|
FilterImporter::SERVICE_NAME,
|
|
|
|
FilterStore::SERVICE_NAME,
|
|
|
|
EditBoxBuilderFactory::SERVICE_NAME,
|
2020-11-29 22:55:34 +00:00
|
|
|
ConsequencesRegistry::SERVICE_NAME,
|
2020-10-02 15:08:48 +00:00
|
|
|
SpecsFormatter::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewExamine::class => [
|
2023-02-26 12:51:08 +00:00
|
|
|
'DBLoadBalancerFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterLookup::SERVICE_NAME,
|
|
|
|
EditBoxBuilderFactory::SERVICE_NAME,
|
2020-09-29 14:52:05 +00:00
|
|
|
VariablesBlobStore::SERVICE_NAME,
|
2020-12-31 13:29:00 +00:00
|
|
|
VariablesFormatter::SERVICE_NAME,
|
2020-10-18 22:25:05 +00:00
|
|
|
VariablesManager::SERVICE_NAME,
|
2021-01-03 13:10:20 +00:00
|
|
|
VariableGeneratorFactory::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewHistory::class => [
|
2022-07-29 11:40:34 +00:00
|
|
|
'UserNameUtils',
|
|
|
|
'LinkBatchFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterLookup::SERVICE_NAME,
|
2021-04-09 09:10:48 +00:00
|
|
|
SpecsFormatter::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewImport::class => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
],
|
|
|
|
AbuseFilterViewList::class => [
|
2022-07-29 11:40:34 +00:00
|
|
|
'LinkBatchFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterProfiler::SERVICE_NAME,
|
2021-04-17 16:57:38 +00:00
|
|
|
SpecsFormatter::SERVICE_NAME,
|
|
|
|
CentralDBManager::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewRevert::class => [
|
2023-02-26 12:51:08 +00:00
|
|
|
'DBLoadBalancerFactory',
|
2020-11-29 15:18:32 +00:00
|
|
|
'UserFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
2020-11-29 15:18:32 +00:00
|
|
|
FilterLookup::SERVICE_NAME,
|
|
|
|
ConsequencesFactory::SERVICE_NAME,
|
2020-09-29 14:52:05 +00:00
|
|
|
VariablesBlobStore::SERVICE_NAME,
|
2020-10-02 15:08:48 +00:00
|
|
|
SpecsFormatter::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewTestBatch::class => [
|
2023-02-26 12:51:08 +00:00
|
|
|
'DBLoadBalancerFactory',
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
EditBoxBuilderFactory::SERVICE_NAME,
|
2021-09-01 11:53:38 +00:00
|
|
|
RuleCheckerFactory::SERVICE_NAME,
|
2021-01-03 13:10:20 +00:00
|
|
|
VariableGeneratorFactory::SERVICE_NAME,
|
2020-10-23 14:19:02 +00:00
|
|
|
],
|
|
|
|
AbuseFilterViewTools::class => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
EditBoxBuilderFactory::SERVICE_NAME,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-01-02 09:52:35 +00:00
|
|
|
* @param AbuseFilterPermissionManager $afPermissionManager
|
2020-10-23 14:19:02 +00:00
|
|
|
* @param ObjectFactory $objectFactory
|
2019-02-08 17:45:25 +00:00
|
|
|
*/
|
2021-01-02 09:52:35 +00:00
|
|
|
public function __construct(
|
|
|
|
AbuseFilterPermissionManager $afPermissionManager,
|
|
|
|
ObjectFactory $objectFactory
|
|
|
|
) {
|
|
|
|
parent::__construct( self::PAGE_NAME, 'abusefilter-view', $afPermissionManager );
|
2020-10-23 14:19:02 +00:00
|
|
|
$this->objectFactory = $objectFactory;
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
2019-02-08 17:45:25 +00:00
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2016-05-11 17:20:49 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
2019-02-08 17:45:25 +00:00
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function getGroupName() {
|
|
|
|
return 'wiki';
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param string|null $subpage
|
|
|
|
*/
|
2009-10-07 13:57:06 +00:00
|
|
|
public function execute( $subpage ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
2009-01-15 19:04:36 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addModuleStyles( 'ext.abuseFilter' );
|
2008-06-27 06:18:51 +00:00
|
|
|
|
|
|
|
$this->setHeaders();
|
2019-07-03 15:43:44 +00:00
|
|
|
$this->addHelpLink( 'Extension:AbuseFilter' );
|
2008-06-27 06:18:51 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->checkPermissions();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $request->getVal( 'result' ) === 'success' ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$out->setSubtitle( $this->msg( 'abusefilter-edit-done-subtitle' ) );
|
2011-11-16 05:34:24 +00:00
|
|
|
$changedFilter = intval( $request->getVal( 'changedfilter' ) );
|
2013-10-06 02:30:37 +00:00
|
|
|
$changeId = intval( $request->getVal( 'changeid' ) );
|
2021-04-27 14:42:55 +00:00
|
|
|
$out->addHTML( Html::successBox(
|
|
|
|
$this->msg(
|
2013-10-06 02:30:37 +00:00
|
|
|
'abusefilter-edit-done',
|
2014-06-28 19:23:43 +00:00
|
|
|
$changedFilter,
|
|
|
|
$changeId,
|
|
|
|
$this->getLanguage()->formatNum( $changedFilter )
|
2021-04-27 14:42:55 +00:00
|
|
|
)->parse()
|
|
|
|
) );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
[ $view, $pageType, $params ] = $this->getViewClassAndPageType( $subpage );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
// Links at the top
|
|
|
|
$this->addNavigationLinks( $pageType );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
$view = $this->instantiateView( $view, $params );
|
|
|
|
$view->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate the view class
|
|
|
|
*
|
|
|
|
* @suppress PhanTypeInvalidCallableArraySize
|
|
|
|
*
|
2023-11-16 18:55:40 +00:00
|
|
|
* @param class-string<AbuseFilterView> $viewClass
|
2020-10-23 14:19:02 +00:00
|
|
|
* @param array $params
|
|
|
|
* @return AbuseFilterView
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function instantiateView( string $viewClass, array $params ): AbuseFilterView {
|
2020-10-23 14:19:02 +00:00
|
|
|
return $this->objectFactory->createObject( [
|
|
|
|
'class' => $viewClass,
|
|
|
|
'services' => self::SERVICES_PER_VIEW[$viewClass],
|
|
|
|
'args' => [ $this->getContext(), $this->getLinkRenderer(), self::PAGE_NAME, $params ]
|
|
|
|
] );
|
2020-10-03 13:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine the view class to instantiate
|
|
|
|
*
|
|
|
|
* @param string|null $subpage
|
|
|
|
* @return array A tuple of three elements:
|
|
|
|
* - a subclass of AbuseFilterView
|
|
|
|
* - type of page for addNavigationLinks
|
|
|
|
* - array of parameters for the class
|
|
|
|
* @phan-return array{0:class-string,1:string,2:array}
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function getViewClassAndPageType( $subpage ): array {
|
2009-05-26 13:08:15 +00:00
|
|
|
// Filter by removing blanks.
|
2020-10-03 13:05:20 +00:00
|
|
|
$params = array_values( array_filter(
|
|
|
|
explode( '/', $subpage ?: '' ),
|
2021-04-30 18:54:17 +00:00
|
|
|
static function ( $value ) {
|
2020-10-03 13:05:20 +00:00
|
|
|
return $value !== '';
|
2009-05-26 13:08:15 +00:00
|
|
|
}
|
2020-10-03 13:05:20 +00:00
|
|
|
) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $subpage === 'tools' ) {
|
2020-10-03 13:05:20 +00:00
|
|
|
return [ AbuseFilterViewTools::class, 'tools', [] ];
|
2008-07-17 13:40:45 +00:00
|
|
|
}
|
2009-01-28 00:10:35 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $subpage === 'import' ) {
|
|
|
|
return [ AbuseFilterViewImport::class, 'import', [] ];
|
2009-01-28 00:10:35 +00:00
|
|
|
}
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( is_numeric( $subpage ) || $subpage === 'new' ) {
|
2020-09-20 10:18:46 +00:00
|
|
|
return [
|
|
|
|
AbuseFilterViewEdit::class,
|
|
|
|
'edit',
|
|
|
|
[ 'filter' => is_numeric( $subpage ) ? (int)$subpage : null ]
|
|
|
|
];
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $params ) {
|
|
|
|
if ( count( $params ) === 2 && $params[0] === 'revert' && is_numeric( $params[1] ) ) {
|
2020-09-20 10:18:46 +00:00
|
|
|
$params[1] = (int)$params[1];
|
2020-10-03 13:05:20 +00:00
|
|
|
return [ AbuseFilterViewRevert::class, 'revert', $params ];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $params[0] === 'test' ) {
|
|
|
|
return [ AbuseFilterViewTestBatch::class, 'test', $params ];
|
2008-08-03 14:04:26 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $params[0] === 'examine' ) {
|
|
|
|
return [ AbuseFilterViewExamine::class, 'examine', $params ];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $params[0] === 'history' || $params[0] === 'log' ) {
|
|
|
|
if ( count( $params ) <= 2 ) {
|
2020-10-09 13:28:05 +00:00
|
|
|
$params = isset( $params[1] ) ? [ 'filter' => (int)$params[1] ] : [];
|
2020-10-03 13:05:20 +00:00
|
|
|
return [ AbuseFilterViewHistory::class, 'recentchanges', $params ];
|
|
|
|
}
|
|
|
|
if ( count( $params ) === 4 && $params[2] === 'item' ) {
|
|
|
|
return [
|
|
|
|
AbuseFilterViewEdit::class,
|
|
|
|
'',
|
2020-09-20 10:18:46 +00:00
|
|
|
[ 'filter' => (int)$params[1], 'history' => (int)$params[3] ]
|
2020-10-03 13:05:20 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
if ( count( $params ) === 5 && $params[2] === 'diff' ) {
|
|
|
|
// Special:AbuseFilter/history/<filter>/diff/<oldid>/<newid>
|
|
|
|
return [ AbuseFilterViewDiff::class, '', $params ];
|
|
|
|
}
|
|
|
|
}
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 13:05:20 +00:00
|
|
|
return [ AbuseFilterViewList::class, 'home', [] ];
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2020-10-03 17:13:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static variant to get the associated Title.
|
|
|
|
*
|
|
|
|
* @param string|int $subpage
|
|
|
|
* @return Title
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public static function getTitleForSubpage( $subpage ): Title {
|
2020-10-03 17:13:32 +00:00
|
|
|
return self::getTitleFor( self::PAGE_NAME, $subpage );
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|