2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-29 10:53:29 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\View;
|
|
|
|
|
|
|
|
use ContextSource;
|
2021-01-31 16:45:12 +00:00
|
|
|
use Flow\Data\Listener\RecentChangesListener;
|
2020-11-29 10:53:29 +00:00
|
|
|
use IContextSource;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2020-10-03 17:13:32 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2021-03-11 10:50:44 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2023-12-10 19:03:19 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-08-19 17:49:36 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2020-11-29 10:53:29 +00:00
|
|
|
use OOUI;
|
|
|
|
use RecentChange;
|
2023-06-07 15:41:20 +00:00
|
|
|
use UnexpectedValueException;
|
2023-06-12 15:05:15 +00:00
|
|
|
use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
2020-11-29 10:53:29 +00:00
|
|
|
use Xml;
|
2016-12-04 15:13:16 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
abstract class AbuseFilterView extends ContextSource {
|
2020-10-23 14:19:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AbuseFilterPermissionManager
|
|
|
|
*/
|
|
|
|
protected $afPermManager;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var array The parameters of the current request
|
|
|
|
*/
|
2022-02-02 11:32:09 +00:00
|
|
|
protected $mParams;
|
2013-10-15 13:22:05 +00:00
|
|
|
|
2016-12-04 15:13:16 +00:00
|
|
|
/**
|
2020-10-03 17:13:32 +00:00
|
|
|
* @var LinkRenderer
|
2016-12-04 15:13:16 +00:00
|
|
|
*/
|
|
|
|
protected $linkRenderer;
|
2020-10-23 14:19:02 +00:00
|
|
|
|
2020-10-16 22:36:15 +00:00
|
|
|
/** @var string */
|
2018-10-16 19:58:22 +00:00
|
|
|
protected $basePageName;
|
2016-12-04 15:13:16 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
/**
|
2020-10-23 14:19:02 +00:00
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
2020-10-03 17:13:32 +00:00
|
|
|
* @param IContextSource $context
|
|
|
|
* @param LinkRenderer $linkRenderer
|
2020-10-16 22:36:15 +00:00
|
|
|
* @param string $basePageName
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param array $params
|
2011-11-16 05:34:24 +00:00
|
|
|
*/
|
2020-10-16 22:36:15 +00:00
|
|
|
public function __construct(
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
2020-10-16 22:36:15 +00:00
|
|
|
IContextSource $context,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
string $basePageName,
|
|
|
|
array $params
|
|
|
|
) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$this->mParams = $params;
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->setContext( $context );
|
|
|
|
$this->linkRenderer = $linkRenderer;
|
2020-10-16 22:36:15 +00:00
|
|
|
$this->basePageName = $basePageName;
|
2020-10-23 14:19:02 +00:00
|
|
|
$this->afPermManager = $afPermManager;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 17:32:57 +00:00
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @param string|int $subpage
|
2011-02-10 17:32:57 +00:00
|
|
|
* @return Title
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function getTitle( $subpage = '' ) {
|
2020-10-16 22:36:15 +00:00
|
|
|
return SpecialPage::getTitleFor( $this->basePageName, $subpage );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Function to show the page
|
|
|
|
*/
|
|
|
|
abstract public function show();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2018-12-09 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Build input and button for loading a filter
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function buildFilterLoader() {
|
|
|
|
$loadText =
|
|
|
|
new OOUI\TextInputWidget(
|
|
|
|
[
|
|
|
|
'type' => 'number',
|
|
|
|
'name' => 'wpInsertFilter',
|
|
|
|
'id' => 'mw-abusefilter-load-filter'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$loadButton =
|
|
|
|
new OOUI\ButtonWidget(
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-test-load' )->text(),
|
|
|
|
'id' => 'mw-abusefilter-load'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$loadGroup =
|
|
|
|
new OOUI\ActionFieldLayout(
|
|
|
|
$loadText,
|
|
|
|
$loadButton,
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-test-load-filter' )->text()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// CSS class for reducing default input field width
|
2023-06-12 15:08:25 +00:00
|
|
|
return Xml::tags(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-abusefilter-load-filter-id' ],
|
|
|
|
$loadGroup
|
|
|
|
);
|
2018-12-09 13:33:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 08:19:09 +00:00
|
|
|
/**
|
2023-06-12 15:05:15 +00:00
|
|
|
* @param ISQLPlatform $db
|
2020-06-02 08:13:17 +00:00
|
|
|
* @param string|false $action 'edit', 'move', 'createaccount', 'delete' or false for all
|
2017-07-13 08:19:09 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2023-06-12 15:05:15 +00:00
|
|
|
public function buildTestConditions( ISQLPlatform $db, $action = false ) {
|
2021-01-31 16:45:12 +00:00
|
|
|
$editSources = [
|
|
|
|
RecentChange::SRC_EDIT,
|
|
|
|
RecentChange::SRC_NEW,
|
|
|
|
];
|
|
|
|
if ( in_array( 'flow', $this->getConfig()->get( 'AbuseFilterValidGroups' ), true ) ) {
|
|
|
|
// TODO Should this be separated somehow? Also, this case should be handled via a hook, not
|
|
|
|
// by special-casing Flow here.
|
|
|
|
// @phan-suppress-next-line PhanUndeclaredClassConstant Temporary solution
|
|
|
|
$editSources[] = RecentChangesListener::SRC_FLOW;
|
|
|
|
}
|
2017-07-13 08:19:09 +00:00
|
|
|
// If one of these is true, we're abusefilter compatible.
|
2018-05-01 10:40:56 +00:00
|
|
|
switch ( $action ) {
|
|
|
|
case 'edit':
|
|
|
|
return $db->makeList( [
|
|
|
|
// Actually, this is only one condition, but this way we get it as string
|
2021-01-31 16:45:12 +00:00
|
|
|
'rc_source' => $editSources
|
2018-05-01 10:40:56 +00:00
|
|
|
], LIST_AND );
|
|
|
|
case 'move':
|
|
|
|
return $db->makeList( [
|
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
|
|
|
'rc_log_type' => 'move',
|
|
|
|
'rc_log_action' => 'move'
|
|
|
|
], LIST_AND );
|
|
|
|
case 'createaccount':
|
|
|
|
return $db->makeList( [
|
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
|
|
|
'rc_log_type' => 'newusers',
|
2018-09-13 13:27:34 +00:00
|
|
|
'rc_log_action' => [ 'create', 'autocreate' ]
|
2018-05-01 10:40:56 +00:00
|
|
|
], LIST_AND );
|
|
|
|
case 'delete':
|
|
|
|
return $db->makeList( [
|
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
|
|
|
'rc_log_type' => 'delete',
|
|
|
|
'rc_log_action' => 'delete'
|
|
|
|
], LIST_AND );
|
2018-07-11 23:54:48 +00:00
|
|
|
case 'upload':
|
|
|
|
return $db->makeList( [
|
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
|
|
|
'rc_log_type' => 'upload',
|
|
|
|
'rc_log_action' => [ 'upload', 'overwrite', 'revert' ]
|
|
|
|
], LIST_AND );
|
2019-01-24 20:48:50 +00:00
|
|
|
case false:
|
|
|
|
// Done later
|
|
|
|
break;
|
2018-10-03 15:55:06 +00:00
|
|
|
default:
|
2023-06-07 15:41:20 +00:00
|
|
|
throw new UnexpectedValueException( __METHOD__ . ' called with invalid action: ' . $action );
|
2018-05-01 10:40:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 08:19:09 +00:00
|
|
|
return $db->makeList( [
|
2021-01-31 16:45:12 +00:00
|
|
|
'rc_source' => $editSources,
|
2017-07-13 08:19:09 +00:00
|
|
|
$db->makeList( [
|
|
|
|
'rc_source' => RecentChange::SRC_LOG,
|
|
|
|
$db->makeList( [
|
|
|
|
$db->makeList( [
|
|
|
|
'rc_log_type' => 'move',
|
|
|
|
'rc_log_action' => 'move'
|
|
|
|
], LIST_AND ),
|
|
|
|
$db->makeList( [
|
|
|
|
'rc_log_type' => 'newusers',
|
2018-09-13 13:27:34 +00:00
|
|
|
'rc_log_action' => [ 'create', 'autocreate' ]
|
2017-07-13 08:19:09 +00:00
|
|
|
], LIST_AND ),
|
2017-08-20 11:48:20 +00:00
|
|
|
$db->makeList( [
|
|
|
|
'rc_log_type' => 'delete',
|
|
|
|
'rc_log_action' => 'delete'
|
|
|
|
], LIST_AND ),
|
2018-07-11 23:54:48 +00:00
|
|
|
$db->makeList( [
|
|
|
|
'rc_log_type' => 'upload',
|
|
|
|
'rc_log_action' => [ 'upload', 'overwrite', 'revert' ]
|
|
|
|
], LIST_AND ),
|
2017-07-13 08:19:09 +00:00
|
|
|
], LIST_OR ),
|
|
|
|
], LIST_AND ),
|
|
|
|
], LIST_OR );
|
|
|
|
}
|
|
|
|
|
2021-03-09 22:09:41 +00:00
|
|
|
/**
|
2021-03-11 10:50:44 +00:00
|
|
|
* @todo Core should provide a method for this (T233222)
|
2023-06-12 15:05:15 +00:00
|
|
|
* @param ISQLPlatform $db
|
2021-03-11 10:50:44 +00:00
|
|
|
* @param Authority $authority
|
2021-03-09 22:09:41 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2023-06-12 15:05:15 +00:00
|
|
|
public function buildVisibilityConditions( ISQLPlatform $db, Authority $authority ): array {
|
2021-03-11 10:50:44 +00:00
|
|
|
if ( !$authority->isAllowed( 'deletedhistory' ) ) {
|
|
|
|
$bitmask = RevisionRecord::DELETED_USER;
|
|
|
|
} elseif ( !$authority->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
|
|
|
|
$bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
|
|
|
|
} else {
|
|
|
|
$bitmask = 0;
|
|
|
|
}
|
|
|
|
return $bitmask
|
|
|
|
? [ $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask" ]
|
|
|
|
: [];
|
2021-03-09 22:09:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 09:57:56 +00:00
|
|
|
/**
|
|
|
|
* @param string|int $id
|
|
|
|
* @param string|null $text
|
|
|
|
* @return string HTML
|
|
|
|
*/
|
|
|
|
public function getLinkToLatestDiff( $id, $text = null ) {
|
|
|
|
return $this->linkRenderer->makeKnownLink(
|
|
|
|
$this->getTitle( "history/$id/diff/prev/cur" ),
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
}
|
2020-10-25 14:54:56 +00:00
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|