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;
|
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;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory as AfParserFactory;
|
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;
|
2021-01-01 17:28:36 +00:00
|
|
|
use Title;
|
2020-10-23 14:19:02 +00:00
|
|
|
use Wikimedia\ObjectFactory;
|
|
|
|
|
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 => [
|
|
|
|
'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 => [
|
|
|
|
'RevisionLookup',
|
|
|
|
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 => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterLookup::SERVICE_NAME,
|
|
|
|
],
|
|
|
|
AbuseFilterViewImport::class => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
],
|
|
|
|
AbuseFilterViewList::class => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
FilterProfiler::SERVICE_NAME,
|
|
|
|
],
|
|
|
|
AbuseFilterViewRevert::class => [
|
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 => [
|
|
|
|
AbuseFilterPermissionManager::SERVICE_NAME,
|
|
|
|
EditBoxBuilderFactory::SERVICE_NAME,
|
|
|
|
AfParserFactory::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' ) );
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->wrapWikiMsg( '<p class="success">$1</p>',
|
2017-06-15 14:23:34 +00:00
|
|
|
[
|
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 )
|
2017-06-15 14:23:34 +00:00
|
|
|
]
|
2013-10-06 02:30:37 +00:00
|
|
|
);
|
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
|
|
|
|
*
|
|
|
|
* @phan-param class-string $viewClass
|
|
|
|
* @suppress PhanTypeInvalidCallableArraySize
|
|
|
|
*
|
|
|
|
* @param string $viewClass
|
|
|
|
* @param array $params
|
|
|
|
* @return AbuseFilterView
|
|
|
|
*/
|
|
|
|
public function instantiateView( string $viewClass, array $params ) : AbuseFilterView {
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
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 ?: '' ),
|
|
|
|
function ( $value ) {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function getTitleForSubpage( $subpage ) : Title {
|
|
|
|
return self::getTitleFor( self::PAGE_NAME, $subpage );
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|