2008-06-27 06:18:51 +00:00
|
|
|
<?php
|
|
|
|
|
2020-08-07 21:48:47 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
2020-09-18 14:49:13 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
2020-11-29 22:55:34 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\ConsequencesRegistry;
|
2020-12-02 22:47:40 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\GlobalNameUtils;
|
2020-12-03 14:11:19 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Pager\AbuseLogPager;
|
2020-12-06 22:59:14 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\View\HideAbuseLog;
|
2019-08-11 13:11:20 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2019-09-18 21:48:40 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-09-17 06:54:06 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2018-10-16 19:58:22 +00:00
|
|
|
use OOUI\ButtonInputWidget;
|
2019-08-11 13:11:20 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
class SpecialAbuseLog extends AbuseFilterSpecialPage {
|
2011-07-25 22:09:05 +00:00
|
|
|
/**
|
2018-11-08 14:34:32 +00:00
|
|
|
* @var User The user whose AbuseLog entries are being searched
|
2011-07-25 22:09:05 +00:00
|
|
|
*/
|
|
|
|
protected $mSearchUser;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The start time of the search period
|
|
|
|
*/
|
2018-06-28 14:45:30 +00:00
|
|
|
protected $mSearchPeriodStart;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The end time of the search period
|
|
|
|
*/
|
2018-06-28 14:45:30 +00:00
|
|
|
protected $mSearchPeriodEnd;
|
|
|
|
|
2011-07-25 22:09:05 +00:00
|
|
|
/**
|
2018-11-08 14:34:32 +00:00
|
|
|
* @var Title The page of which AbuseLog entries are being searched
|
2011-07-25 22:09:05 +00:00
|
|
|
*/
|
|
|
|
protected $mSearchTitle;
|
|
|
|
|
2018-03-04 14:02:45 +00:00
|
|
|
/**
|
2018-11-08 14:34:32 +00:00
|
|
|
* @var string The action performed by the user
|
2018-03-04 14:02:45 +00:00
|
|
|
*/
|
|
|
|
protected $mSearchAction;
|
|
|
|
|
2018-02-24 13:49:39 +00:00
|
|
|
/**
|
2018-11-08 14:34:32 +00:00
|
|
|
* @var string The action taken by AbuseFilter
|
2018-02-24 13:49:39 +00:00
|
|
|
*/
|
|
|
|
protected $mSearchActionTaken;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The wiki name where we're performing the search
|
|
|
|
*/
|
2012-08-03 21:55:35 +00:00
|
|
|
protected $mSearchWiki;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string|null The filter IDs we're looking for. Either a single one, or a pipe-separated list
|
|
|
|
*/
|
2011-07-25 22:09:05 +00:00
|
|
|
protected $mSearchFilter;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The visibility of entries we're interested in
|
|
|
|
*/
|
2017-07-28 08:49:19 +00:00
|
|
|
protected $mSearchEntries;
|
|
|
|
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The impact of the user action, i.e. if the change has been saved
|
|
|
|
*/
|
2017-08-24 08:52:06 +00:00
|
|
|
protected $mSearchImpact;
|
|
|
|
|
2020-10-09 12:55:44 +00:00
|
|
|
/** @var string|null The filter group to search, as defined in $wgAbuseFilterValidGroups */
|
2019-01-17 17:34:07 +00:00
|
|
|
protected $mSearchGroup;
|
|
|
|
|
2020-08-07 21:48:47 +00:00
|
|
|
/** @var LinkBatchFactory */
|
|
|
|
private $linkBatchFactory;
|
|
|
|
|
2020-09-17 06:54:06 +00:00
|
|
|
/** @var PermissionManager */
|
|
|
|
private $permissionManager;
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
/** @var AbuseFilterPermissionManager */
|
|
|
|
private $afPermissionManager;
|
|
|
|
|
2020-11-29 22:55:34 +00:00
|
|
|
/** @var ConsequencesRegistry */
|
|
|
|
private $consequencesRegistry;
|
|
|
|
|
2019-01-11 16:34:08 +00:00
|
|
|
/**
|
2020-08-07 21:48:47 +00:00
|
|
|
* @param LinkBatchFactory $linkBatchFactory
|
2020-09-17 06:54:06 +00:00
|
|
|
* @param PermissionManager $permissionManager
|
2020-09-18 14:49:13 +00:00
|
|
|
* @param AbuseFilterPermissionManager $afPermissionManager
|
2020-11-29 22:55:34 +00:00
|
|
|
* @param ConsequencesRegistry $consequencesRegistry
|
2019-01-11 16:34:08 +00:00
|
|
|
*/
|
2020-09-18 14:49:13 +00:00
|
|
|
public function __construct(
|
|
|
|
LinkBatchFactory $linkBatchFactory,
|
|
|
|
PermissionManager $permissionManager,
|
2020-11-29 22:55:34 +00:00
|
|
|
AbuseFilterPermissionManager $afPermissionManager,
|
|
|
|
ConsequencesRegistry $consequencesRegistry
|
2020-09-18 14:49:13 +00:00
|
|
|
) {
|
2008-06-27 06:18:51 +00:00
|
|
|
parent::__construct( 'AbuseLog', 'abusefilter-log' );
|
2020-08-07 21:48:47 +00:00
|
|
|
$this->linkBatchFactory = $linkBatchFactory;
|
2020-09-17 06:54:06 +00:00
|
|
|
$this->permissionManager = $permissionManager;
|
2020-09-18 14:49:13 +00:00
|
|
|
$this->afPermissionManager = $afPermissionManager;
|
2020-11-29 22:55:34 +00:00
|
|
|
$this->consequencesRegistry = $consequencesRegistry;
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2019-02-08 17:45:25 +00:00
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2016-06-01 21:42:22 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function getGroupName() {
|
|
|
|
return 'changes';
|
|
|
|
}
|
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
/**
|
|
|
|
* Main routine
|
|
|
|
*
|
|
|
|
* $parameter string is converted into the $args array, which can come in
|
|
|
|
* three shapes:
|
|
|
|
*
|
|
|
|
* An array of size 2: only if the URL is like Special:AbuseLog/private/id
|
|
|
|
* where id is the log identifier. In this case, the private details of the
|
|
|
|
* log (e.g. IP address) will be shown.
|
|
|
|
*
|
|
|
|
* An array of size 1: either the URL is like Special:AbuseLog/id where
|
|
|
|
* the id is log identifier, in which case the details of the log except for
|
2020-12-06 22:59:14 +00:00
|
|
|
* private bits (e.g. IP address) are shown, or Special:AbuseLog/hide for hiding entries,
|
|
|
|
* or the URL is incomplete as in Special:AbuseLog/private (without speciying id),
|
|
|
|
* in which case a warning is shown to the user
|
2016-12-12 16:30:06 +00:00
|
|
|
*
|
|
|
|
* An array of size 0 when URL is like Special:AbuseLog or an array of size
|
|
|
|
* 1 when the URL is like Special:AbuseFilter/ (i.e. without anything after
|
2020-12-06 22:59:14 +00:00
|
|
|
* the slash). Otherwise, the abuse logs are shown as a list, with a search form above the list.
|
2016-12-12 16:30:06 +00:00
|
|
|
*
|
2019-05-15 15:34:57 +00:00
|
|
|
* @param string|null $parameter URL parameters
|
2016-12-12 16:30:06 +00:00
|
|
|
*/
|
2009-10-07 13:57:06 +00:00
|
|
|
public function execute( $parameter ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-02-08 17:45:25 +00:00
|
|
|
$this->addNavigationLinks( 'log' );
|
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
|
|
|
$this->loadParameters();
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->enableClientCache( false );
|
2009-01-26 19:23:27 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addModuleStyles( 'ext.abuseFilter' );
|
2009-01-27 17:32:30 +00:00
|
|
|
|
2019-01-11 16:34:08 +00:00
|
|
|
$this->checkPermissions();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
$args = explode( '/', $parameter );
|
2011-07-04 22:00:06 +00:00
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
if ( count( $args ) === 2 && $args[0] === 'private' ) {
|
2019-12-07 17:20:10 +00:00
|
|
|
$this->showPrivateDetails( (int)$args[1] );
|
2016-12-12 16:30:06 +00:00
|
|
|
} elseif ( count( $args ) === 1 && $args[0] !== '' ) {
|
|
|
|
if ( $args[0] === 'private' ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-invalid-request-noid' );
|
2020-12-06 22:59:14 +00:00
|
|
|
} elseif ( $args[0] === 'hide' ) {
|
|
|
|
$this->showHideView();
|
2016-12-12 16:30:06 +00:00
|
|
|
} else {
|
|
|
|
$this->showDetails( $args[0] );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
} else {
|
2019-01-23 11:01:06 +00:00
|
|
|
$this->searchForm();
|
|
|
|
$this->showList();
|
2009-03-22 23:33:27 +00:00
|
|
|
}
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Loads parameters from request
|
|
|
|
*/
|
|
|
|
public function loadParameters() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-05 10:23:57 +00:00
|
|
|
$searchUsername = trim( $request->getText( 'wpSearchUser' ) );
|
|
|
|
$userTitle = Title::newFromText( $searchUsername, NS_USER );
|
|
|
|
$this->mSearchUser = $userTitle ? $userTitle->getText() : null;
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $this->getConfig()->get( 'AbuseFilterIsCentral' ) ) {
|
2012-08-03 21:55:35 +00:00
|
|
|
$this->mSearchWiki = $request->getText( 'wpSearchWiki' );
|
|
|
|
}
|
2009-04-01 03:38:57 +00:00
|
|
|
|
2018-06-28 14:45:30 +00:00
|
|
|
$this->mSearchPeriodStart = $request->getText( 'wpSearchPeriodStart' );
|
|
|
|
$this->mSearchPeriodEnd = $request->getText( 'wpSearchPeriodEnd' );
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->mSearchTitle = $request->getText( 'wpSearchTitle' );
|
2020-10-09 12:55:44 +00:00
|
|
|
|
2009-08-04 17:56:18 +00:00
|
|
|
$this->mSearchFilter = null;
|
2020-10-09 12:55:44 +00:00
|
|
|
$this->mSearchGroup = null;
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $this->afPermissionManager->canSeeLogDetails( $this->getUser() ) ) {
|
2013-07-09 22:49:19 +00:00
|
|
|
$this->mSearchFilter = $request->getText( 'wpSearchFilter' );
|
2020-10-09 12:55:44 +00:00
|
|
|
if ( count( $this->getConfig()->get( 'AbuseFilterValidGroups' ) ) > 1 ) {
|
|
|
|
$this->mSearchGroup = $request->getText( 'wpSearchGroup' );
|
|
|
|
}
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2017-07-28 08:49:19 +00:00
|
|
|
|
2020-10-09 12:55:44 +00:00
|
|
|
$this->mSearchAction = $request->getText( 'wpSearchAction' );
|
|
|
|
$this->mSearchActionTaken = $request->getText( 'wpSearchActionTaken' );
|
2017-07-28 08:49:19 +00:00
|
|
|
$this->mSearchEntries = $request->getText( 'wpSearchEntries' );
|
2017-08-24 08:52:06 +00:00
|
|
|
$this->mSearchImpact = $request->getText( 'wpSearchImpact' );
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-04 14:02:45 +00:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
private function getAllFilterableActions() {
|
|
|
|
return [
|
|
|
|
'edit',
|
|
|
|
'move',
|
|
|
|
'upload',
|
|
|
|
'stashupload',
|
|
|
|
'delete',
|
|
|
|
'createaccount',
|
|
|
|
'autocreateaccount',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Builds the search form
|
|
|
|
*/
|
|
|
|
public function searchForm() {
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
2017-06-15 14:23:34 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
'SearchUser' => [
|
2016-04-10 10:05:01 +00:00
|
|
|
'label-message' => 'abusefilter-log-search-user',
|
|
|
|
'type' => 'user',
|
2018-04-05 10:23:57 +00:00
|
|
|
'ipallowed' => true,
|
2016-04-10 10:05:01 +00:00
|
|
|
'default' => $this->mSearchUser,
|
2017-06-15 14:23:34 +00:00
|
|
|
],
|
2018-06-28 14:45:30 +00:00
|
|
|
'SearchPeriodStart' => [
|
|
|
|
'label-message' => 'abusefilter-test-period-start',
|
|
|
|
'type' => 'datetime',
|
|
|
|
'default' => $this->mSearchPeriodStart
|
|
|
|
],
|
|
|
|
'SearchPeriodEnd' => [
|
|
|
|
'label-message' => 'abusefilter-test-period-end',
|
|
|
|
'type' => 'datetime',
|
|
|
|
'default' => $this->mSearchPeriodEnd
|
|
|
|
],
|
2017-06-15 14:23:34 +00:00
|
|
|
'SearchTitle' => [
|
2016-04-10 10:05:01 +00:00
|
|
|
'label-message' => 'abusefilter-log-search-title',
|
|
|
|
'type' => 'title',
|
|
|
|
'default' => $this->mSearchTitle,
|
2018-05-10 20:20:05 +00:00
|
|
|
'required' => false
|
2017-08-24 08:52:06 +00:00
|
|
|
],
|
|
|
|
'SearchImpact' => [
|
|
|
|
'label-message' => 'abusefilter-log-search-impact',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => [
|
|
|
|
$this->msg( 'abusefilter-log-search-impact-all' )->text() => 0,
|
|
|
|
$this->msg( 'abusefilter-log-search-impact-saved' )->text() => 1,
|
|
|
|
$this->msg( 'abusefilter-log-search-impact-not-saved' )->text() => 2,
|
|
|
|
],
|
|
|
|
],
|
2017-06-15 14:23:34 +00:00
|
|
|
];
|
2018-03-04 14:02:45 +00:00
|
|
|
$filterableActions = $this->getAllFilterableActions();
|
|
|
|
$actions = array_combine( $filterableActions, $filterableActions );
|
2020-06-16 17:18:49 +00:00
|
|
|
ksort( $actions );
|
|
|
|
$actions = array_merge(
|
|
|
|
[ $this->msg( 'abusefilter-log-search-action-any' )->text() => 'any' ],
|
|
|
|
$actions,
|
|
|
|
[ $this->msg( 'abusefilter-log-search-action-other' )->text() => 'other' ]
|
|
|
|
);
|
2018-03-04 14:02:45 +00:00
|
|
|
$formDescriptor['SearchAction'] = [
|
|
|
|
'label-message' => 'abusefilter-log-search-action-label',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $actions,
|
|
|
|
'default' => 'any',
|
|
|
|
];
|
2020-06-16 17:18:49 +00:00
|
|
|
$options = [];
|
2020-08-25 19:33:37 +00:00
|
|
|
$context = $this->getContext();
|
2020-11-29 22:55:34 +00:00
|
|
|
foreach ( $this->consequencesRegistry->getAllActionNames() as $action ) {
|
2020-08-25 19:33:37 +00:00
|
|
|
$key = AbuseFilter::getActionDisplay( $action, $context );
|
2018-02-24 13:49:39 +00:00
|
|
|
$options[$key] = $action;
|
|
|
|
}
|
|
|
|
ksort( $options );
|
2020-06-16 17:18:49 +00:00
|
|
|
$options = array_merge(
|
|
|
|
[ $this->msg( 'abusefilter-log-search-action-taken-any' )->text() => '' ],
|
|
|
|
$options,
|
|
|
|
[ $this->msg( 'abusefilter-log-noactions-filter' )->text() => 'noactions' ]
|
|
|
|
);
|
2018-02-24 13:49:39 +00:00
|
|
|
$formDescriptor['SearchActionTaken'] = [
|
|
|
|
'label-message' => 'abusefilter-log-search-action-taken-label',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $options,
|
|
|
|
];
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $this->afPermissionManager->canSeeHiddenLogEntries( $user ) ) {
|
2017-07-28 08:49:19 +00:00
|
|
|
$formDescriptor['SearchEntries'] = [
|
|
|
|
'type' => 'select',
|
|
|
|
'label-message' => 'abusefilter-log-search-entries-label',
|
|
|
|
'options' => [
|
|
|
|
$this->msg( 'abusefilter-log-search-entries-all' )->text() => 0,
|
|
|
|
$this->msg( 'abusefilter-log-search-entries-hidden' )->text() => 1,
|
|
|
|
$this->msg( 'abusefilter-log-search-entries-visible' )->text() => 2,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2019-01-17 17:34:07 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $this->afPermissionManager->canSeeLogDetails( $user ) ) {
|
2020-10-09 12:55:44 +00:00
|
|
|
$groups = $this->getConfig()->get( 'AbuseFilterValidGroups' );
|
|
|
|
if ( count( $groups ) > 1 ) {
|
|
|
|
$options = array_merge(
|
|
|
|
[ $this->msg( 'abusefilter-log-search-group-any' )->text() => 0 ],
|
|
|
|
array_combine( $groups, $groups )
|
|
|
|
);
|
|
|
|
$formDescriptor['SearchGroup'] = [
|
|
|
|
'label-message' => 'abusefilter-log-search-group',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $options
|
|
|
|
];
|
|
|
|
}
|
2019-11-18 03:08:28 +00:00
|
|
|
$helpmsg = $this->getConfig()->get( 'AbuseFilterIsCentral' )
|
2020-09-29 12:58:37 +00:00
|
|
|
? $this->msg( 'abusefilter-log-search-filter-help-central' )->escaped()
|
|
|
|
: $this->msg( 'abusefilter-log-search-filter-help' )
|
2020-12-02 22:47:40 +00:00
|
|
|
->params( GlobalNameUtils::GLOBAL_FILTER_PREFIX )->escaped();
|
2018-02-25 00:04:31 +00:00
|
|
|
$formDescriptor['SearchFilter'] = [
|
|
|
|
'label-message' => 'abusefilter-log-search-filter',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => $this->mSearchFilter,
|
2019-11-18 03:08:28 +00:00
|
|
|
'help' => $helpmsg
|
2018-02-25 00:04:31 +00:00
|
|
|
];
|
|
|
|
}
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $this->getConfig()->get( 'AbuseFilterIsCentral' ) ) {
|
2019-01-17 17:34:07 +00:00
|
|
|
// @todo Add free form input for wiki name. Would be nice to generate
|
2018-02-25 00:04:31 +00:00
|
|
|
// a select with unique names in the db at some point.
|
|
|
|
$formDescriptor['SearchWiki'] = [
|
|
|
|
'label-message' => 'abusefilter-log-search-wiki',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => $this->mSearchWiki,
|
|
|
|
];
|
|
|
|
}
|
2012-08-03 21:55:35 +00:00
|
|
|
|
2018-04-29 17:52:45 +00:00
|
|
|
HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
|
2017-08-04 06:43:40 +00:00
|
|
|
->setWrapperLegendMsg( 'abusefilter-log-search' )
|
2017-08-24 07:46:27 +00:00
|
|
|
->setSubmitTextMsg( 'abusefilter-log-search-submit' )
|
2016-04-10 10:05:01 +00:00
|
|
|
->setMethod( 'get' )
|
2020-05-14 18:54:45 +00:00
|
|
|
->setCollapsibleOptions( true )
|
2016-04-10 10:05:01 +00:00
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2020-12-06 22:59:14 +00:00
|
|
|
private function showHideView() {
|
|
|
|
$view = new HideAbuseLog(
|
|
|
|
$this->afPermissionManager,
|
|
|
|
$this->getContext(),
|
|
|
|
$this->getLinkRenderer(),
|
|
|
|
'AbuseLog'
|
2010-08-19 21:12:09 +00:00
|
|
|
);
|
2020-12-06 22:59:14 +00:00
|
|
|
$view->show();
|
2010-06-25 20:04:55 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the results list
|
|
|
|
*/
|
|
|
|
public function showList() {
|
2018-09-11 16:57:49 +00:00
|
|
|
$aflFilterMigrationStage = $this->getConfig()->get( 'AbuseFilterAflFilterMigrationStage' );
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
2019-01-23 10:34:43 +00:00
|
|
|
$this->outputHeader( 'abusefilter-log-summary' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-06-27 06:18:51 +00:00
|
|
|
// Generate conditions list.
|
2017-06-15 14:23:34 +00:00
|
|
|
$conds = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
if ( $this->mSearchUser ) {
|
2019-08-27 09:40:01 +00:00
|
|
|
$searchedUser = User::newFromName( $this->mSearchUser );
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( !$searchedUser ) {
|
2010-06-25 00:06:07 +00:00
|
|
|
$conds['afl_user'] = 0;
|
|
|
|
$conds['afl_user_text'] = $this->mSearchUser;
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2019-08-27 09:40:01 +00:00
|
|
|
$conds['afl_user'] = $searchedUser->getId();
|
|
|
|
$conds['afl_user_text'] = $searchedUser->getName();
|
2010-06-25 00:06:07 +00:00
|
|
|
}
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-05-26 13:08:15 +00:00
|
|
|
|
2018-06-28 14:45:30 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
if ( $this->mSearchPeriodStart ) {
|
|
|
|
$conds[] = 'afl_timestamp >= ' .
|
|
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mSearchPeriodStart ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->mSearchPeriodEnd ) {
|
|
|
|
$conds[] = 'afl_timestamp <= ' .
|
|
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mSearchPeriodEnd ) ) );
|
|
|
|
}
|
|
|
|
|
2012-08-03 21:55:35 +00:00
|
|
|
if ( $this->mSearchWiki ) {
|
2020-01-08 13:33:10 +00:00
|
|
|
if ( $this->mSearchWiki === WikiMap::getCurrentWikiDbDomain()->getId() ) {
|
2014-12-25 18:29:00 +00:00
|
|
|
$conds['afl_wiki'] = null;
|
|
|
|
} else {
|
|
|
|
$conds['afl_wiki'] = $this->mSearchWiki;
|
|
|
|
}
|
2012-08-03 21:55:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 17:34:07 +00:00
|
|
|
$groupFilters = [];
|
|
|
|
if ( $this->mSearchGroup ) {
|
|
|
|
$groupFilters = $dbr->selectFieldValues(
|
|
|
|
'abuse_filter',
|
|
|
|
'af_id',
|
|
|
|
[ 'af_group' => $this->mSearchGroup ],
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$searchFilters = [];
|
2009-05-26 13:08:15 +00:00
|
|
|
if ( $this->mSearchFilter ) {
|
2019-03-28 19:59:53 +00:00
|
|
|
$rawFilters = array_map( 'trim', explode( '|', $this->mSearchFilter ) );
|
|
|
|
// Map of [ [ id, global ], ... ]
|
|
|
|
$filtersList = [];
|
|
|
|
$foundInvalid = false;
|
|
|
|
foreach ( $rawFilters as $filter ) {
|
|
|
|
try {
|
2020-12-02 22:47:40 +00:00
|
|
|
$filtersList[] = GlobalNameUtils::splitGlobalName( $filter );
|
2019-03-28 19:59:53 +00:00
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
$foundInvalid = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 09:23:31 +00:00
|
|
|
// @phan-suppress-next-line PhanImpossibleCondition
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( $foundInvalid ) {
|
2018-09-11 16:57:49 +00:00
|
|
|
// @todo Tell what the invalid IDs are
|
2019-03-28 19:59:53 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Html::rawElement(
|
|
|
|
'p',
|
|
|
|
[],
|
|
|
|
Html::warningBox( $this->msg( 'abusefilter-log-invalid-filter' )->escaped() )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
// if a filter is hidden, users who can't view private filters should
|
|
|
|
// not be able to find log entries generated by it.
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( !$this->afPermissionManager->canViewPrivateFiltersLogs( $user ) ) {
|
2014-01-05 21:06:24 +00:00
|
|
|
$searchedForPrivate = false;
|
2019-03-28 19:59:53 +00:00
|
|
|
foreach ( $filtersList as $index => $filterData ) {
|
2020-10-17 08:27:02 +00:00
|
|
|
if ( AbuseFilterServices::getFilterLookup()->getFilter( ...$filterData )->isHidden() ) {
|
2019-03-28 19:59:53 +00:00
|
|
|
unset( $filtersList[$index] );
|
2014-01-05 21:06:24 +00:00
|
|
|
$searchedForPrivate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $searchedForPrivate ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-log-private-not-included' );
|
|
|
|
}
|
2012-01-03 17:29:10 +00:00
|
|
|
}
|
2019-03-28 19:59:53 +00:00
|
|
|
|
|
|
|
foreach ( $filtersList as $filterData ) {
|
2020-12-02 22:47:40 +00:00
|
|
|
$searchFilters[] = GlobalNameUtils::buildGlobalName( ...$filterData );
|
2019-03-28 19:59:53 +00:00
|
|
|
}
|
2019-01-17 17:34:07 +00:00
|
|
|
}
|
2015-09-28 18:03:35 +00:00
|
|
|
|
2019-01-17 17:34:07 +00:00
|
|
|
$searchIDs = null;
|
|
|
|
if ( $this->mSearchGroup && !$this->mSearchFilter ) {
|
|
|
|
$searchIDs = $groupFilters;
|
|
|
|
} elseif ( !$this->mSearchGroup && $this->mSearchFilter ) {
|
|
|
|
$searchIDs = $searchFilters;
|
|
|
|
} elseif ( $this->mSearchGroup && $this->mSearchFilter ) {
|
|
|
|
$searchIDs = array_intersect( $groupFilters, $searchFilters );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $searchIDs !== null ) {
|
|
|
|
if ( !count( $searchIDs ) ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-log-noresults' );
|
2014-01-05 21:06:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-17 17:34:07 +00:00
|
|
|
|
2018-09-11 16:57:49 +00:00
|
|
|
if ( $aflFilterMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
|
|
|
|
$filterConds = [ 'local' => [], 'global' => [] ];
|
|
|
|
foreach ( $searchIDs as $filter ) {
|
2020-12-02 22:47:40 +00:00
|
|
|
list( $filterID, $isGlobal ) = GlobalNameUtils::splitGlobalName( $filter );
|
2018-09-11 16:57:49 +00:00
|
|
|
$key = $isGlobal ? 'global' : 'local';
|
|
|
|
$filterConds[$key][] = $filterID;
|
|
|
|
}
|
|
|
|
$filterWhere = [];
|
|
|
|
// @phan-suppress-next-line PhanImpossibleCondition False positive
|
|
|
|
if ( $filterConds['local'] ) {
|
|
|
|
$filterWhere[] = $dbr->makeList(
|
|
|
|
[ 'afl_global' => 0, 'afl_filter_id' => $filterConds['local'] ],
|
|
|
|
LIST_AND
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// @phan-suppress-next-line PhanImpossibleCondition False positive
|
|
|
|
if ( $filterConds['global'] ) {
|
|
|
|
$filterWhere[] = $dbr->makeList(
|
|
|
|
[ 'afl_global' => 1, 'afl_filter_id' => $filterConds['global'] ],
|
|
|
|
LIST_AND
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$conds[] = $dbr->makeList( $filterWhere, LIST_OR );
|
|
|
|
} else {
|
|
|
|
// SCHEMA_COMPAT_READ_OLD
|
|
|
|
$conds[ 'afl_filter' ] = $searchIDs;
|
|
|
|
}
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-06-27 06:18:51 +00:00
|
|
|
$searchTitle = Title::newFromText( $this->mSearchTitle );
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( $this->mSearchTitle && $searchTitle ) {
|
2008-06-27 06:18:51 +00:00
|
|
|
$conds['afl_namespace'] = $searchTitle->getNamespace();
|
2009-05-24 08:33:57 +00:00
|
|
|
$conds['afl_title'] = $searchTitle->getDBkey();
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $this->afPermissionManager->canSeeHiddenLogEntries( $user ) ) {
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $this->mSearchEntries === '1' ) {
|
2017-07-28 08:49:19 +00:00
|
|
|
$conds['afl_deleted'] = 1;
|
2018-08-26 08:34:42 +00:00
|
|
|
} elseif ( $this->mSearchEntries === '2' ) {
|
2019-02-09 10:17:09 +00:00
|
|
|
$conds['afl_deleted'] = 0;
|
2017-08-24 08:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( in_array( $this->mSearchImpact, [ '1', '2' ] ) ) {
|
2019-03-28 13:55:37 +00:00
|
|
|
$unsuccessfulActionConds = 'afl_rev_id IS NULL';
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $this->mSearchImpact === '1' ) {
|
2017-08-24 08:52:06 +00:00
|
|
|
$conds[] = "NOT ( $unsuccessfulActionConds )";
|
|
|
|
} else {
|
|
|
|
$conds[] = $unsuccessfulActionConds;
|
2017-07-28 08:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 13:49:39 +00:00
|
|
|
if ( $this->mSearchActionTaken ) {
|
2020-11-29 22:55:34 +00:00
|
|
|
if ( in_array( $this->mSearchActionTaken, $this->consequencesRegistry->getAllActionNames() ) ) {
|
2018-03-16 14:47:01 +00:00
|
|
|
$list = [ 'afl_actions' => $this->mSearchActionTaken ];
|
|
|
|
$list[] = 'afl_actions' . $dbr->buildLike(
|
|
|
|
$this->mSearchActionTaken, ',', $dbr->anyString() );
|
|
|
|
$list[] = 'afl_actions' . $dbr->buildLike(
|
|
|
|
$dbr->anyString(), ',', $this->mSearchActionTaken );
|
|
|
|
$list[] = 'afl_actions' . $dbr->buildLike(
|
|
|
|
$dbr->anyString(),
|
|
|
|
',', $this->mSearchActionTaken, ',',
|
|
|
|
$dbr->anyString()
|
|
|
|
);
|
|
|
|
$conds[] = $dbr->makeList( $list, LIST_OR );
|
2018-02-24 13:49:39 +00:00
|
|
|
} elseif ( $this->mSearchActionTaken === 'noactions' ) {
|
|
|
|
$conds['afl_actions'] = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 14:02:45 +00:00
|
|
|
if ( $this->mSearchAction ) {
|
|
|
|
$filterableActions = $this->getAllFilterableActions();
|
|
|
|
if ( in_array( $this->mSearchAction, $filterableActions ) ) {
|
|
|
|
$conds['afl_action'] = $this->mSearchAction;
|
|
|
|
} elseif ( $this->mSearchAction === 'other' ) {
|
|
|
|
$list = $dbr->makeList( [ 'afl_action' => $filterableActions ], LIST_OR );
|
|
|
|
$conds[] = "NOT ( $list )";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 14:30:33 +00:00
|
|
|
$pager = new AbuseLogPager(
|
2020-12-07 13:56:16 +00:00
|
|
|
$this->getContext(),
|
|
|
|
$this->getLinkRenderer(),
|
2018-03-11 14:30:33 +00:00
|
|
|
$conds,
|
|
|
|
$this->linkBatchFactory,
|
2020-12-07 13:56:16 +00:00
|
|
|
$this->permissionManager,
|
|
|
|
$this->afPermissionManager,
|
|
|
|
$this->getName()
|
2018-03-11 14:30:33 +00:00
|
|
|
);
|
2011-07-05 00:09:09 +00:00
|
|
|
$pager->doQuery();
|
2011-07-04 22:00:06 +00:00
|
|
|
$result = $pager->getResult();
|
2019-01-23 11:01:06 +00:00
|
|
|
|
|
|
|
$form = Xml::tags(
|
|
|
|
'form',
|
|
|
|
[
|
|
|
|
'method' => 'GET',
|
2018-10-16 19:58:22 +00:00
|
|
|
'action' => $this->getPageTitle( 'hide' )->getLocalURL()
|
2019-01-23 11:01:06 +00:00
|
|
|
],
|
2018-10-16 19:58:22 +00:00
|
|
|
$this->getDeleteButton() .
|
|
|
|
Xml::tags( 'ul', [ 'class' => 'plainlinks' ], $pager->getBody() ) .
|
|
|
|
$this->getDeleteButton()
|
2019-01-23 11:01:06 +00:00
|
|
|
);
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( $result && $result->numRows() !== 0 ) {
|
2019-01-23 11:01:06 +00:00
|
|
|
$out->addHTML( $pager->getNavigationBar() . $form . $pager->getNavigationBar() );
|
2011-06-06 23:46:13 +00:00
|
|
|
} else {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-noresults' );
|
2011-06-06 23:46:13 +00:00
|
|
|
}
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-10-16 19:58:22 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML for a button to hide selected entries
|
|
|
|
*
|
|
|
|
* @return string|ButtonInputWidget
|
|
|
|
*/
|
|
|
|
private function getDeleteButton() {
|
|
|
|
if ( !$this->afPermissionManager->canHideAbuseLog( $this->getUser() ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return new ButtonInputWidget( [
|
|
|
|
'label' => $this->msg( 'abusefilter-log-hide-entries' )->text(),
|
|
|
|
'type' => 'submit'
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @param string|int $id
|
2020-09-16 20:17:12 +00:00
|
|
|
* @suppress SecurityCheck-SQLInjection
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function showDetails( $id ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
2018-09-11 16:57:49 +00:00
|
|
|
$aflFilterMigrationStage = $this->getConfig()->get( 'AbuseFilterAflFilterMigrationStage' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-11 14:30:33 +00:00
|
|
|
$pager = new AbuseLogPager(
|
2020-12-07 13:56:16 +00:00
|
|
|
$this->getContext(),
|
|
|
|
$this->getLinkRenderer(),
|
2018-03-11 14:30:33 +00:00
|
|
|
[],
|
|
|
|
$this->linkBatchFactory,
|
2020-12-07 13:56:16 +00:00
|
|
|
$this->permissionManager,
|
|
|
|
$this->afPermissionManager,
|
|
|
|
$this->getName()
|
2018-03-11 14:30:33 +00:00
|
|
|
);
|
2020-09-16 20:17:12 +00:00
|
|
|
|
|
|
|
[
|
|
|
|
'tables' => $tables,
|
|
|
|
'fields' => $fields,
|
|
|
|
'join_conds' => $join_conds,
|
|
|
|
] = $pager->getQueryInfo();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-16 20:17:12 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2010-08-19 21:12:09 +00:00
|
|
|
$row = $dbr->selectRow(
|
2020-09-16 20:17:12 +00:00
|
|
|
$tables,
|
|
|
|
$fields,
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'afl_id' => $id ],
|
2010-08-19 21:12:09 +00:00
|
|
|
__METHOD__,
|
2017-06-15 14:23:34 +00:00
|
|
|
[],
|
2020-09-16 20:17:12 +00:00
|
|
|
$join_conds
|
2010-08-19 21:12:09 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = null;
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !$row ) {
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = 'abusefilter-log-nonexistent';
|
2012-01-03 17:29:10 +00:00
|
|
|
} else {
|
2018-09-11 16:57:49 +00:00
|
|
|
if ( $aflFilterMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
|
|
|
|
$filterID = $row->afl_filter_id;
|
|
|
|
$global = $row->afl_global;
|
|
|
|
} else {
|
|
|
|
// SCHEMA_COMPAT_READ_OLD
|
2020-12-02 22:47:40 +00:00
|
|
|
list( $filterID, $global ) = GlobalNameUtils::splitGlobalName( $row->afl_filter );
|
2018-09-11 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( $global ) {
|
2020-11-18 19:24:02 +00:00
|
|
|
$filter_hidden = AbuseFilterServices::getFilterLookup()->getFilter( $filterID, $global )->isHidden();
|
2018-11-19 14:58:53 +00:00
|
|
|
} else {
|
|
|
|
$filter_hidden = $row->af_hidden;
|
|
|
|
}
|
2015-09-28 18:03:35 +00:00
|
|
|
|
2020-10-27 19:21:44 +00:00
|
|
|
if ( !$this->afPermissionManager->canSeeLogDetailsForFilter( $user, $filter_hidden ) ) {
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = 'abusefilter-log-cannot-see-details';
|
2020-09-18 14:49:13 +00:00
|
|
|
} elseif (
|
|
|
|
self::isHidden( $row ) === true &&
|
|
|
|
!$this->afPermissionManager->canSeeHiddenLogEntries( $user )
|
|
|
|
) {
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = 'abusefilter-log-details-hidden';
|
|
|
|
} elseif ( self::isHidden( $row ) === 'implicit' ) {
|
2020-01-08 16:46:24 +00:00
|
|
|
$revRec = MediaWikiServices::getInstance()
|
|
|
|
->getRevisionLookup()
|
|
|
|
->getRevisionById( (int)$row->afl_rev_id );
|
|
|
|
if ( !AbuseFilter::userCanViewRev( $revRec, $user ) ) {
|
|
|
|
// The log is visible, but refers to a deleted revision
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = 'abusefilter-log-details-hidden-implicit';
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 17:29:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-19 14:58:53 +00:00
|
|
|
if ( $error ) {
|
|
|
|
$out->addWikiMsg( $error );
|
2018-07-13 22:34:54 +00:00
|
|
|
return;
|
2010-06-25 20:04:55 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-07-09 22:49:19 +00:00
|
|
|
$output = Xml::element(
|
2012-09-02 11:07:02 +00:00
|
|
|
'legend',
|
|
|
|
null,
|
2017-11-01 00:22:14 +00:00
|
|
|
$this->msg( 'abusefilter-log-details-legend' )
|
|
|
|
->numParams( $id )
|
|
|
|
->text()
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
2020-12-07 13:56:16 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $pager->doFormatRow( $row, false ) );
|
2009-03-22 23:33:27 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
// Load data
|
2009-02-27 03:06:19 +00:00
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addJsConfigVars( 'wgAbuseFilterVariables', $vars->dumpAllVars( true ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-18 05:45:36 +00:00
|
|
|
// Diff, if available
|
2020-03-03 18:03:02 +00:00
|
|
|
if ( $row->afl_action === 'edit' ) {
|
2019-08-11 13:11:20 +00:00
|
|
|
$vars->setLogger( LoggerFactory::getInstance( 'AbuseFilter' ) );
|
2020-10-03 23:18:14 +00:00
|
|
|
// GET_BC because these variables may be unset in case of data corruption (T264513)
|
|
|
|
$old_wikitext = $vars->getVar( 'old_wikitext', AbuseFilterVariableHolder::GET_BC )->toString();
|
|
|
|
$new_wikitext = $vars->getVar( 'new_wikitext', AbuseFilterVariableHolder::GET_BC )->toString();
|
2009-05-26 13:08:15 +00:00
|
|
|
|
2013-06-10 19:53:33 +00:00
|
|
|
$diffEngine = new DifferenceEngine( $this->getContext() );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
$diffEngine->showDiffStyle();
|
2013-06-10 16:57:27 +00:00
|
|
|
|
2018-08-20 14:48:54 +00:00
|
|
|
$formattedDiff = $diffEngine->addHeader(
|
|
|
|
$diffEngine->generateTextDiffBody( $old_wikitext, $new_wikitext ),
|
|
|
|
'', ''
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$output .=
|
|
|
|
Xml::tags(
|
|
|
|
'h3',
|
|
|
|
null,
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-log-details-diff' )->parse()
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2009-03-18 05:45:36 +00:00
|
|
|
$output .= $formattedDiff;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$output .= Xml::element( 'h3', null, $this->msg( 'abusefilter-log-details-vars' )->text() );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-22 23:33:27 +00:00
|
|
|
// Build a table.
|
2016-09-17 07:03:42 +00:00
|
|
|
$output .= AbuseFilter::buildVarDumpTable( $vars, $this->getContext() );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $this->afPermissionManager->canSeePrivateDetails( $user ) ) {
|
2016-12-12 16:30:06 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
'Reason' => [
|
2019-01-07 15:23:21 +00:00
|
|
|
'label-message' => 'abusefilter-view-privatedetails-reason',
|
2016-12-12 16:30:06 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'size' => 45,
|
|
|
|
],
|
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-02 16:58:43 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
2019-01-07 15:23:21 +00:00
|
|
|
$htmlForm->setWrapperLegendMsg( 'abusefilter-view-privatedetails-legend' )
|
2016-12-12 16:30:06 +00:00
|
|
|
->setAction( $this->getPageTitle( 'private/' . $id )->getLocalURL() )
|
2019-01-07 15:23:21 +00:00
|
|
|
->setSubmitTextMsg( 'abusefilter-view-privatedetails-submit' )
|
2016-12-12 16:30:06 +00:00
|
|
|
->setMethod( 'post' )
|
|
|
|
->prepareForm();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
$output .= $htmlForm->getHTML( false );
|
2008-06-27 08:11:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-08-20 14:48:54 +00:00
|
|
|
$out->addHTML( Xml::tags( 'fieldset', null, $output ) );
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
/**
|
2018-12-04 09:37:48 +00:00
|
|
|
* Helper function to select a row with private details and some more context
|
|
|
|
* for an AbuseLog entry.
|
|
|
|
*
|
2019-08-27 09:40:01 +00:00
|
|
|
* @param User $user The user who's trying to view the row
|
2018-12-04 09:37:48 +00:00
|
|
|
* @param int $id The ID of the log entry
|
|
|
|
* @return Status A status object with the requested row stored in the value property,
|
|
|
|
* or an error and no row.
|
2016-12-12 16:30:06 +00:00
|
|
|
*/
|
2019-08-27 09:40:01 +00:00
|
|
|
public static function getPrivateDetailsRow( User $user, $id ) {
|
2018-09-11 16:57:49 +00:00
|
|
|
global $wgAbuseFilterAflFilterMigrationStage;
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2016-12-12 16:30:06 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2018-09-11 16:57:49 +00:00
|
|
|
$fields = [ 'afl_id', 'afl_user_text', 'afl_timestamp', 'afl_ip', 'af_id',
|
|
|
|
'af_public_comments', 'af_hidden' ];
|
|
|
|
if ( $wgAbuseFilterAflFilterMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
|
|
|
|
$fields[] = 'afl_filter_id';
|
|
|
|
$fields[] = 'afl_global';
|
|
|
|
$join = [ 'af_id=afl_filter_id', 'afl_global' => 0 ];
|
|
|
|
} else {
|
|
|
|
// SCHEMA_COMPAT_READ_OLD
|
|
|
|
$fields[] = 'afl_filter';
|
|
|
|
$join = 'af_id=afl_filter';
|
|
|
|
}
|
|
|
|
|
2016-12-12 16:30:06 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[ 'abuse_filter_log', 'abuse_filter' ],
|
2018-09-11 16:57:49 +00:00
|
|
|
$fields,
|
2016-12-12 16:30:06 +00:00
|
|
|
[ 'afl_id' => $id ],
|
|
|
|
__METHOD__,
|
|
|
|
[],
|
2018-09-11 16:57:49 +00:00
|
|
|
[ 'abuse_filter' => [ 'LEFT JOIN', $join ] ]
|
2016-12-12 16:30:06 +00:00
|
|
|
);
|
|
|
|
|
2018-12-04 09:37:48 +00:00
|
|
|
$status = Status::newGood();
|
2016-12-12 16:30:06 +00:00
|
|
|
if ( !$row ) {
|
2018-12-04 09:37:48 +00:00
|
|
|
$status->fatal( 'abusefilter-log-nonexistent' );
|
|
|
|
return $status;
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 16:57:49 +00:00
|
|
|
if ( $wgAbuseFilterAflFilterMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
|
|
|
|
$filterID = $row->afl_filter_id;
|
|
|
|
$global = $row->afl_global;
|
|
|
|
} else {
|
|
|
|
// SCHEMA_COMPAT_READ_OLD
|
2020-12-02 22:47:40 +00:00
|
|
|
list( $filterID, $global ) = GlobalNameUtils::splitGlobalName( $row->afl_filter );
|
2018-09-11 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 09:37:48 +00:00
|
|
|
if ( $global ) {
|
2020-11-18 19:24:02 +00:00
|
|
|
$lookup = AbuseFilterServices::getFilterLookup();
|
|
|
|
$filterHidden = $lookup->getFilter( $filterID, $global )->isHidden();
|
2018-12-04 09:37:48 +00:00
|
|
|
} else {
|
|
|
|
$filterHidden = $row->af_hidden;
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 19:21:44 +00:00
|
|
|
if ( !$afPermManager->canSeeLogDetailsForFilter( $user, $filterHidden ) ) {
|
2018-12-04 09:37:48 +00:00
|
|
|
$status->fatal( 'abusefilter-log-cannot-see-details' );
|
|
|
|
return $status;
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
2018-12-04 09:37:48 +00:00
|
|
|
$status->setResult( true, $row );
|
|
|
|
return $status;
|
|
|
|
}
|
2016-12-12 16:30:06 +00:00
|
|
|
|
2018-12-04 09:37:48 +00:00
|
|
|
/**
|
|
|
|
* Builds an HTML table with the private details for a given abuseLog entry.
|
|
|
|
*
|
|
|
|
* @param stdClass $row The row, as returned by self::getPrivateDetailsRow()
|
|
|
|
* @return string The HTML output
|
|
|
|
*/
|
|
|
|
protected function buildPrivateDetailsTable( $row ) {
|
2016-12-12 16:30:06 +00:00
|
|
|
$output = Xml::element(
|
|
|
|
'legend',
|
|
|
|
null,
|
2019-01-07 15:23:21 +00:00
|
|
|
$this->msg( 'abusefilter-log-details-privatedetails' )->text()
|
2016-12-12 16:30:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$header =
|
|
|
|
Xml::element( 'th', null, $this->msg( 'abusefilter-log-details-var' )->text() ) .
|
|
|
|
Xml::element( 'th', null, $this->msg( 'abusefilter-log-details-val' )->text() );
|
|
|
|
|
|
|
|
$output .=
|
|
|
|
Xml::openElement( 'table',
|
|
|
|
[
|
|
|
|
'class' => 'wikitable mw-abuselog-private',
|
|
|
|
'style' => 'width: 80%;'
|
|
|
|
]
|
|
|
|
) .
|
|
|
|
Xml::openElement( 'tbody' );
|
|
|
|
$output .= $header;
|
|
|
|
|
|
|
|
// Log ID
|
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-log-details-id' )->text()
|
|
|
|
) .
|
|
|
|
Xml::openElement( 'td' ) .
|
|
|
|
$linkRenderer->makeKnownLink(
|
|
|
|
$this->getPageTitle( $row->afl_id ),
|
2018-12-04 09:37:48 +00:00
|
|
|
$this->getLanguage()->formatNum( $row->afl_id )
|
2016-12-12 16:30:06 +00:00
|
|
|
) .
|
|
|
|
Xml::closeElement( 'td' )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Timestamp
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-edit-builder-vars-timestamp-expanded' )->text()
|
|
|
|
) .
|
|
|
|
Xml::element( 'td',
|
|
|
|
null,
|
2018-12-04 09:37:48 +00:00
|
|
|
$this->getLanguage()->timeanddate( $row->afl_timestamp, true )
|
2016-12-12 16:30:06 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// User
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-edit-builder-vars-user-name' )->text()
|
|
|
|
) .
|
|
|
|
Xml::element( 'td',
|
|
|
|
null,
|
|
|
|
$row->afl_user_text
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Filter ID
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-list-id' )->text()
|
|
|
|
) .
|
|
|
|
Xml::openElement( 'td' ) .
|
|
|
|
$linkRenderer->makeKnownLink(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseFilter', $row->af_id ),
|
2018-12-04 09:37:48 +00:00
|
|
|
$this->getLanguage()->formatNum( $row->af_id )
|
2016-12-12 16:30:06 +00:00
|
|
|
) .
|
|
|
|
Xml::closeElement( 'td' )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Filter description
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-list-public' )->text()
|
|
|
|
) .
|
|
|
|
Xml::element( 'td',
|
|
|
|
null,
|
|
|
|
$row->af_public_comments
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// IP address
|
2018-03-01 10:31:25 +00:00
|
|
|
if ( $row->afl_ip !== '' ) {
|
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'CheckUser' ) &&
|
2020-09-17 06:54:06 +00:00
|
|
|
$this->permissionManager->userHasRight( $this->getUser(), 'checkuser' )
|
|
|
|
) {
|
|
|
|
$CULink = ' · ' . $linkRenderer->makeKnownLink(
|
|
|
|
SpecialPage::getTitleFor(
|
|
|
|
'CheckUser',
|
|
|
|
$row->afl_ip
|
|
|
|
),
|
|
|
|
$this->msg( 'abusefilter-log-details-checkuser' )->text()
|
|
|
|
);
|
2018-03-01 10:31:25 +00:00
|
|
|
} else {
|
|
|
|
$CULink = '';
|
|
|
|
}
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-log-details-ip' )->text()
|
|
|
|
) .
|
|
|
|
Xml::tags(
|
|
|
|
'td',
|
|
|
|
null,
|
2018-03-09 08:26:58 +00:00
|
|
|
self::getUserLinks( 0, $row->afl_ip ) . $CULink
|
2018-03-01 10:31:25 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$output .=
|
|
|
|
Xml::tags( 'tr', null,
|
|
|
|
Xml::element( 'td',
|
|
|
|
[ 'style' => 'width: 30%;' ],
|
|
|
|
$this->msg( 'abusefilter-log-details-ip' )->text()
|
|
|
|
) .
|
|
|
|
Xml::element(
|
|
|
|
'td',
|
|
|
|
null,
|
|
|
|
$this->msg( 'abusefilter-log-ip-not-available' )->text()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-12-12 16:30:06 +00:00
|
|
|
|
|
|
|
$output .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
|
|
|
|
|
|
|
|
$output = Xml::tags( 'fieldset', null, $output );
|
2018-12-04 09:37:48 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @param int $id
|
2018-12-04 09:37:48 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function showPrivateDetails( $id ) {
|
|
|
|
$out = $this->getOutput();
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( !$this->afPermissionManager->canSeePrivateDetails( $user ) ) {
|
2020-08-28 21:29:25 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-cannot-see-privatedetails' );
|
2018-12-04 09:37:48 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
// Make sure it is a valid request
|
|
|
|
$token = $request->getVal( 'wpEditToken' );
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( !$request->wasPosted() || !$user->matchEditToken( $token ) ) {
|
2018-12-04 09:37:48 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Xml::tags(
|
|
|
|
'p',
|
|
|
|
null,
|
|
|
|
Html::errorBox( $this->msg( 'abusefilter-invalid-request' )->params( $id )->parse() )
|
|
|
|
)
|
|
|
|
);
|
2016-12-12 16:30:06 +00:00
|
|
|
|
2018-12-04 09:37:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reason = $request->getText( 'wpReason' );
|
|
|
|
if ( !self::checkPrivateDetailsAccessReason( $reason ) ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-noreason' );
|
|
|
|
$this->showDetails( $id );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
$status = self::getPrivateDetailsRow( $user, $id );
|
2018-12-04 09:37:48 +00:00
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
$out->addWikiMsg( $status->getErrors()[0] );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$row = $status->getValue();
|
|
|
|
|
|
|
|
// Log accessing private details
|
|
|
|
if ( $this->getConfig()->get( 'AbuseFilterLogPrivateDetailsAccess' ) ) {
|
2019-08-27 09:40:01 +00:00
|
|
|
self::addPrivateDetailsAccessLogEntry( $id, $reason, $user );
|
2018-12-04 09:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show private details (IP).
|
|
|
|
$table = $this->buildPrivateDetailsTable( $row );
|
|
|
|
$out->addHTML( $table );
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If specifying a reason for viewing private details of abuse log is required
|
|
|
|
* then it makes sure that a reason is provided.
|
|
|
|
*
|
|
|
|
* @param string $reason
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-01-07 15:23:21 +00:00
|
|
|
public static function checkPrivateDetailsAccessReason( $reason ) {
|
|
|
|
global $wgAbuseFilterPrivateDetailsForceReason;
|
|
|
|
return ( !$wgAbuseFilterPrivateDetailsForceReason || strlen( $reason ) > 0 );
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $logID int The ID of the AbuseFilter log that was accessed
|
|
|
|
* @param string $reason The reason provided for accessing private details
|
|
|
|
* @param User $user The user who accessed the private details
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-07 15:23:21 +00:00
|
|
|
public static function addPrivateDetailsAccessLogEntry( $logID, $reason, User $user ) {
|
2019-12-07 17:20:10 +00:00
|
|
|
$target = self::getTitleFor( 'AbuseLog', (string)$logID );
|
2016-12-12 16:30:06 +00:00
|
|
|
|
|
|
|
$logEntry = new ManualLogEntry( 'abusefilterprivatedetails', 'access' );
|
|
|
|
$logEntry->setPerformer( $user );
|
|
|
|
$logEntry->setTarget( $target );
|
|
|
|
$logEntry->setParameters( [
|
|
|
|
'4::logid' => $logID,
|
|
|
|
] );
|
|
|
|
$logEntry->setComment( $reason );
|
|
|
|
|
|
|
|
$logEntry->insert();
|
|
|
|
}
|
|
|
|
|
2017-10-20 17:46:31 +00:00
|
|
|
/**
|
|
|
|
* @param int $userId
|
|
|
|
* @param string $userName
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-12-07 13:56:16 +00:00
|
|
|
public static function getUserLinks( $userId, $userName ) {
|
2017-06-15 14:23:34 +00:00
|
|
|
static $cache = [];
|
2016-08-15 10:08:17 +00:00
|
|
|
|
|
|
|
if ( !isset( $cache[$userName][$userId] ) ) {
|
|
|
|
$cache[$userName][$userId] = Linker::userLink( $userId, $userName ) .
|
|
|
|
Linker::userToolLinks( $userId, $userName, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cache[$userName][$userId];
|
|
|
|
}
|
|
|
|
|
2012-02-10 23:41:05 +00:00
|
|
|
/**
|
|
|
|
* Given a log entry row, decides whether or not it can be viewed by the public.
|
|
|
|
*
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param stdClass $row The abuse_filter_log row object.
|
2012-02-10 23:41:05 +00:00
|
|
|
*
|
2018-10-16 21:04:20 +00:00
|
|
|
* @return bool|string true if the item is explicitly hidden, false if it is not.
|
2015-09-28 18:03:35 +00:00
|
|
|
* The string 'implicit' if it is hidden because the corresponding revision is hidden.
|
2012-02-10 23:41:05 +00:00
|
|
|
*/
|
|
|
|
public static function isHidden( $row ) {
|
2018-08-19 16:22:07 +00:00
|
|
|
// First, check if the entry is hidden. Since this is an oversight-level deletion,
|
|
|
|
// it's more important than the associated revision being deleted.
|
|
|
|
if ( $row->afl_deleted ) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-10 23:41:05 +00:00
|
|
|
if ( $row->afl_rev_id ) {
|
2020-01-08 16:46:24 +00:00
|
|
|
$revision = MediaWikiServices::getInstance()
|
|
|
|
->getRevisionLookup()
|
|
|
|
->getRevisionById( $row->afl_rev_id );
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $revision && $revision->getVisibility() !== 0 ) {
|
2012-02-10 23:41:05 +00:00
|
|
|
return 'implicit';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-19 16:22:07 +00:00
|
|
|
return false;
|
2012-02-10 23:41:05 +00:00
|
|
|
}
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|