2008-06-27 06:18:51 +00:00
|
|
|
<?php
|
|
|
|
|
2020-08-07 21:48:47 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
2018-03-11 14:30:33 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
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;
|
2019-09-18 21:48:40 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
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;
|
|
|
|
|
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
|
2019-01-11 16:34:08 +00:00
|
|
|
*/
|
2020-09-17 06:54:06 +00:00
|
|
|
public function __construct( LinkBatchFactory $linkBatchFactory, PermissionManager $permissionManager ) {
|
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;
|
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
|
|
|
|
* private bits (e.g. IP address) are shown, or the URL is incomplete as in
|
|
|
|
* Special:AbuseLog/private (without speciying id), in which case a warning
|
|
|
|
* is shown to the user
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the slash). In this case, if the parameter `hide` was passed, it will be
|
|
|
|
* used as the identifier of the log entry that we want to hide; otherwise,
|
|
|
|
* the abuse logs are shown as a list, with a search form above the list.
|
|
|
|
*
|
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
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$hideid = $request->getIntOrNull( 'hide' );
|
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' );
|
|
|
|
} else {
|
|
|
|
$this->showDetails( $args[0] );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
} else {
|
2016-12-12 16:30:06 +00:00
|
|
|
if ( $hideid ) {
|
|
|
|
$this->showHideForm( $hideid );
|
|
|
|
} else {
|
|
|
|
$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;
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::canSeeDetails( $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-02-24 13:49:39 +00:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
private function getAllActions() {
|
2018-03-10 21:47:33 +00:00
|
|
|
$config = $this->getConfig();
|
2018-02-24 13:49:39 +00:00
|
|
|
return array_unique(
|
|
|
|
array_merge(
|
2018-03-10 21:47:33 +00:00
|
|
|
array_keys( $config->get( 'AbuseFilterActions' ) ),
|
|
|
|
array_keys( $config->get( 'AbuseFilterCustomActionsHandlers' ) )
|
2018-02-24 13:49:39 +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();
|
2018-02-24 13:49:39 +00:00
|
|
|
foreach ( $this->getAllActions() 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,
|
|
|
|
];
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::canSeeHidden( $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
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::canSeeDetails( $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' )
|
|
|
|
->params( AbuseFilter::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
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @param int $id
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function showHideForm( $id ) {
|
2018-08-21 17:19:10 +00:00
|
|
|
$output = $this->getOutput();
|
2020-09-17 06:54:06 +00:00
|
|
|
if ( !$this->permissionManager->userHasRight( $this->getUser(), 'abusefilter-hide-log' ) ) {
|
2018-08-21 17:19:10 +00:00
|
|
|
$output->addWikiMsg( 'abusefilter-log-hide-forbidden' );
|
2015-09-28 18:03:35 +00:00
|
|
|
|
2010-06-25 20:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2010-06-25 20:04:55 +00:00
|
|
|
|
2019-03-28 19:59:53 +00:00
|
|
|
$deleted = $dbr->selectField(
|
|
|
|
'abuse_filter_log',
|
2018-02-05 10:48:58 +00:00
|
|
|
'afl_deleted',
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'afl_id' => $id ],
|
2019-03-28 19:59:53 +00:00
|
|
|
__METHOD__
|
2010-08-19 21:12:09 +00:00
|
|
|
);
|
2010-06-25 20:04:55 +00:00
|
|
|
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( $deleted === false ) {
|
|
|
|
$output->addWikiMsg( 'abusefilter-log-nonexistent' );
|
2010-06-25 20:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2018-03-23 19:21:45 +00:00
|
|
|
$hideReasonsOther = $this->msg( 'revdelete-reasonotherlist' )->text();
|
2020-02-24 13:01:36 +00:00
|
|
|
$hideReasons = $this->msg( 'revdelete-reason-dropdown-suppress' )->inContentLanguage()->text();
|
2018-03-23 19:21:45 +00:00
|
|
|
$hideReasons = Xml::listDropDownOptions( $hideReasons, [ 'other' => $hideReasonsOther ] );
|
|
|
|
|
2017-06-15 14:23:34 +00:00
|
|
|
$formInfo = [
|
|
|
|
'logid' => [
|
2010-06-25 20:04:55 +00:00
|
|
|
'type' => 'info',
|
2018-03-23 19:21:45 +00:00
|
|
|
'default' => (string)$id,
|
2010-06-25 20:04:55 +00:00
|
|
|
'label-message' => 'abusefilter-log-hide-id',
|
2017-06-15 14:23:34 +00:00
|
|
|
],
|
2018-03-23 19:21:45 +00:00
|
|
|
'dropdownreason' => [
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $hideReasons,
|
|
|
|
'label-message' => 'abusefilter-log-hide-reason'
|
|
|
|
],
|
2017-06-15 14:23:34 +00:00
|
|
|
'reason' => [
|
2010-06-25 20:04:55 +00:00
|
|
|
'type' => 'text',
|
2018-03-23 19:21:45 +00:00
|
|
|
'label-message' => 'abusefilter-log-hide-reason-other',
|
2017-06-15 14:23:34 +00:00
|
|
|
],
|
|
|
|
'hidden' => [
|
2010-06-25 20:04:55 +00:00
|
|
|
'type' => 'toggle',
|
2019-03-28 19:59:53 +00:00
|
|
|
'default' => $deleted,
|
2010-06-25 20:04:55 +00:00
|
|
|
'label-message' => 'abusefilter-log-hide-hidden',
|
2017-06-15 14:23:34 +00:00
|
|
|
],
|
|
|
|
];
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2018-03-23 19:21:45 +00:00
|
|
|
HTMLForm::factory( 'ooui', $formInfo, $this->getContext() )
|
|
|
|
->setTitle( $this->getPageTitle() )
|
|
|
|
->setWrapperLegend( $this->msg( 'abusefilter-log-hide-legend' )->text() )
|
|
|
|
->addHiddenField( 'hide', $id )
|
|
|
|
->setSubmitCallback( [ $this, 'saveHideForm' ] )
|
|
|
|
->show();
|
2018-08-21 17:19:10 +00:00
|
|
|
|
|
|
|
// Show suppress log for this entry
|
|
|
|
$suppressLogPage = new LogPage( 'suppress' );
|
|
|
|
$output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" );
|
2019-12-07 17:20:10 +00:00
|
|
|
LogEventsList::showLogExtract( $output, 'suppress', $this->getPageTitle( (string)$id ) );
|
2010-06-25 20:04:55 +00:00
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param array $fields
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function saveHideForm( $fields ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$logid = $this->getRequest()->getVal( 'hide' );
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2010-06-25 20:04:55 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2010-08-19 21:12:09 +00:00
|
|
|
|
|
|
|
$dbw->update(
|
|
|
|
'abuse_filter_log',
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'afl_deleted' => $fields['hidden'] ],
|
|
|
|
[ 'afl_id' => $logid ],
|
2010-08-19 21:12:09 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2011-07-04 22:00:06 +00:00
|
|
|
|
2018-03-23 19:21:45 +00:00
|
|
|
$reason = $fields['dropdownreason'];
|
|
|
|
if ( $reason === 'other' ) {
|
|
|
|
$reason = $fields['reason'];
|
|
|
|
} elseif ( $fields['reason'] !== '' ) {
|
|
|
|
$reason .=
|
|
|
|
$this->msg( 'colon-separator' )->inContentLanguage()->text() . $fields['reason'];
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:25:19 +00:00
|
|
|
$action = $fields['hidden'] ? 'hide-afl' : 'unhide-afl';
|
2017-02-15 18:12:31 +00:00
|
|
|
$logEntry = new ManualLogEntry( 'suppress', $action );
|
|
|
|
$logEntry->setPerformer( $this->getUser() );
|
|
|
|
$logEntry->setTarget( $this->getPageTitle( $logid ) );
|
|
|
|
$logEntry->setComment( $reason );
|
|
|
|
$logEntry->insert();
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->redirect( SpecialPage::getTitleFor( 'AbuseLog' )->getFullURL() );
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2010-06-25 20:04:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the results list
|
|
|
|
*/
|
|
|
|
public function showList() {
|
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 {
|
|
|
|
$filtersList[] = AbuseFilter::splitGlobalName( $filter );
|
|
|
|
} 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 ) {
|
|
|
|
$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.
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( !AbuseFilter::canViewPrivate( $user )
|
2020-09-17 06:54:06 +00:00
|
|
|
&& !$this->permissionManager->userHasRight( $user, 'abusefilter-log-private' )
|
2015-09-28 18:03:35 +00:00
|
|
|
) {
|
2014-01-05 21:06:24 +00:00
|
|
|
$searchedForPrivate = false;
|
2019-03-28 19:59:53 +00:00
|
|
|
foreach ( $filtersList as $index => $filterData ) {
|
|
|
|
if ( AbuseFilter::filterHidden( ...$filterData ) ) {
|
|
|
|
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 ) {
|
|
|
|
$searchFilters[] = AbuseFilter::buildGlobalName( ...$filterData );
|
|
|
|
}
|
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
|
|
|
|
|
|
|
$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
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::canSeeHidden( $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 ) {
|
|
|
|
if ( in_array( $this->mSearchActionTaken, $this->getAllActions() ) ) {
|
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(
|
|
|
|
$this,
|
|
|
|
$conds,
|
|
|
|
$this->linkBatchFactory,
|
|
|
|
$this->canSeeUndeleteDiffs()
|
|
|
|
);
|
2011-07-05 00:09:09 +00:00
|
|
|
$pager->doQuery();
|
2011-07-04 22:00:06 +00:00
|
|
|
$result = $pager->getResult();
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( $result && $result->numRows() !== 0 ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $pager->getNavigationBar() .
|
2017-06-15 14:23:34 +00:00
|
|
|
Xml::tags( 'ul', [ 'class' => 'plainlinks' ], $pager->getBody() ) .
|
2015-09-28 18:03:35 +00:00
|
|
|
$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
|
|
|
|
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();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-11 14:30:33 +00:00
|
|
|
$pager = new AbuseLogPager(
|
|
|
|
$this,
|
|
|
|
[],
|
|
|
|
$this->linkBatchFactory,
|
|
|
|
$this->canSeeUndeleteDiffs()
|
|
|
|
);
|
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 {
|
2019-03-28 19:59:53 +00:00
|
|
|
list( $filterID, $global ) = AbuseFilter::splitGlobalName( $row->afl_filter );
|
|
|
|
if ( $global ) {
|
2018-11-19 14:58:53 +00:00
|
|
|
$filter_hidden = null;
|
|
|
|
} else {
|
|
|
|
$filter_hidden = $row->af_hidden;
|
|
|
|
}
|
2015-09-28 18:03:35 +00:00
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( !self::canSeeDetails( $user, $filterID, $global, $filter_hidden ) ) {
|
2018-11-19 14:58:53 +00:00
|
|
|
$error = 'abusefilter-log-cannot-see-details';
|
2019-08-27 09:40:01 +00:00
|
|
|
} elseif ( self::isHidden( $row ) === true && !self::canSeeHidden( $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
|
|
|
);
|
2008-10-21 15:14:30 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $this->formatRow( $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' ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
$old_wikitext = $vars->getVar( 'old_wikitext' )->toString();
|
|
|
|
$new_wikitext = $vars->getVar( 'new_wikitext' )->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
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::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
|
|
|
|
2018-03-11 14:30:33 +00:00
|
|
|
/**
|
|
|
|
* Can this user see diffs generated by Special:Undelete?
|
|
|
|
* @see \SpecialUndelete
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function canSeeUndeleteDiffs() : bool {
|
|
|
|
if ( !$this->permissionManager->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->permissionManager->userHasAnyRight(
|
|
|
|
$this->getUser(), 'deletedtext', 'undelete' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can this user see diffs generated by Special:Undelete for the page?
|
|
|
|
* @see \SpecialUndelete
|
|
|
|
* @param LinkTarget $page
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function canSeeUndeleteDiffForPage( LinkTarget $page ) : bool {
|
|
|
|
if ( !$this->canSeeUndeleteDiffs() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( [ 'deletedtext', 'undelete' ] as $action ) {
|
|
|
|
if ( $this->permissionManager->userCan(
|
|
|
|
$action, $this->getUser(), $page, PermissionManager::RIGOR_QUICK
|
|
|
|
) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2016-12-12 16:30:06 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[ 'abuse_filter_log', 'abuse_filter' ],
|
2018-03-09 08:26:58 +00:00
|
|
|
[ 'afl_id', 'afl_filter', 'afl_user_text', 'afl_timestamp', 'afl_ip', 'af_id',
|
|
|
|
'af_public_comments', 'af_hidden' ],
|
2016-12-12 16:30:06 +00:00
|
|
|
[ 'afl_id' => $id ],
|
|
|
|
__METHOD__,
|
|
|
|
[],
|
2019-04-18 11:50:32 +00:00
|
|
|
[ 'abuse_filter' => [ 'LEFT JOIN', 'af_id=afl_filter' ] ]
|
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-12-04 09:37:48 +00:00
|
|
|
list( $filterID, $global ) = AbuseFilter::splitGlobalName( $row->afl_filter );
|
|
|
|
if ( $global ) {
|
|
|
|
$filterHidden = null;
|
|
|
|
} else {
|
|
|
|
$filterHidden = $row->af_hidden;
|
2016-12-12 16:30:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( !self::canSeeDetails( $user, $filterID, $global, $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();
|
|
|
|
|
|
|
|
if ( !self::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();
|
|
|
|
}
|
|
|
|
|
2011-07-25 22:09:05 +00:00
|
|
|
/**
|
2019-08-27 09:40:01 +00:00
|
|
|
* @param User $user
|
2019-03-28 19:59:53 +00:00
|
|
|
* @param int|null $id The ID of the filter
|
|
|
|
* @param bool|int|null $global Whether the filter is global
|
|
|
|
* @param bool|int|null $hidden Whether the filter is hidden
|
2011-07-25 22:09:05 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2019-08-27 09:40:01 +00:00
|
|
|
public static function canSeeDetails( User $user, $id = null, $global = false, $hidden = null ) {
|
2019-09-18 21:48:40 +00:00
|
|
|
$pm = MediaWikiServices::getInstance()->getPermissionManager();
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( $id !== null ) {
|
|
|
|
if ( $hidden === null ) {
|
|
|
|
$hidden = AbuseFilter::filterHidden( $id, $global );
|
2012-01-03 17:29:10 +00:00
|
|
|
}
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( $hidden ) {
|
2019-09-18 21:48:40 +00:00
|
|
|
return $pm->userHasRight( $user, 'abusefilter-log-detail' )
|
|
|
|
&& ( AbuseFilter::canViewPrivate( $user ) ||
|
|
|
|
$pm->userHasRight( $user, 'abusefilter-log-private' ) );
|
2012-01-03 17:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 21:48:40 +00:00
|
|
|
return $pm->userHasRight( $user, 'abusefilter-log-detail' );
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-07-25 22:09:05 +00:00
|
|
|
/**
|
2019-09-18 21:48:40 +00:00
|
|
|
* @param UserIdentity $user
|
2011-07-25 22:09:05 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2019-09-18 21:48:40 +00:00
|
|
|
public static function canSeePrivateDetails( UserIdentity $user ) {
|
|
|
|
return MediaWikiServices::getInstance()->getPermissionManager()
|
|
|
|
->userHasRight( $user, 'abusefilter-privatedetails' );
|
2010-06-25 20:04:55 +00:00
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2011-07-25 22:09:05 +00:00
|
|
|
/**
|
2019-08-27 09:40:01 +00:00
|
|
|
* @param User $user
|
2011-07-25 22:09:05 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2019-08-27 09:40:01 +00:00
|
|
|
public static function canSeeHidden( User $user ) {
|
2019-09-18 21:48:40 +00:00
|
|
|
return MediaWikiServices::getInstance()->getPermissionManager()
|
|
|
|
->userHasRight( $user, 'abusefilter-hidden-log' );
|
2008-06-27 08:11:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param stdClass $row
|
|
|
|
* @param bool $isListItem
|
2020-03-20 15:59:49 +00:00
|
|
|
* @return string
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function formatRow( $row, $isListItem = true ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2017-06-15 14:23:34 +00:00
|
|
|
$actionLinks = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-06-27 06:18:51 +00:00
|
|
|
$title = Title::makeTitle( $row->afl_namespace, $row->afl_title );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-02-10 23:41:05 +00:00
|
|
|
$diffLink = false;
|
2016-08-15 10:08:17 +00:00
|
|
|
$isHidden = self::isHidden( $row );
|
2012-02-10 23:41:05 +00:00
|
|
|
|
2019-09-19 13:59:32 +00:00
|
|
|
// @todo T224203 Try to show the details if the revision is deleted but the AbuseLog entry
|
|
|
|
// is not. However, watch out to avoid showing too much stuff.
|
|
|
|
if ( !self::canSeeHidden( $user ) && $isHidden ) {
|
2012-02-10 23:41:05 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-12-04 15:13:16 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
|
|
|
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !$row->afl_wiki ) {
|
2020-03-13 15:25:46 +00:00
|
|
|
$pageLink = $linkRenderer->makeLink(
|
|
|
|
$title,
|
|
|
|
null,
|
|
|
|
[],
|
|
|
|
[ 'redirect' => 'no' ]
|
|
|
|
);
|
2020-09-16 20:17:12 +00:00
|
|
|
if ( $row->rev_id ) {
|
2016-12-10 13:59:43 +00:00
|
|
|
$diffLink = $linkRenderer->makeKnownLink(
|
|
|
|
$title,
|
2016-12-04 15:13:16 +00:00
|
|
|
new HtmlArmor( $this->msg( 'abusefilter-log-diff' )->parse() ),
|
2017-06-15 14:23:34 +00:00
|
|
|
[],
|
2020-09-16 20:17:12 +00:00
|
|
|
[ 'diff' => 'prev', 'oldid' => $row->rev_id ]
|
|
|
|
);
|
2018-03-11 14:30:33 +00:00
|
|
|
} elseif (
|
|
|
|
isset( $row->ar_timestamp ) && $row->ar_timestamp
|
|
|
|
&& $this->canSeeUndeleteDiffForPage( $title )
|
|
|
|
) {
|
|
|
|
$diffLink = $linkRenderer->makeKnownLink(
|
|
|
|
SpecialPage::getTitleFor( 'Undelete' ),
|
|
|
|
new HtmlArmor( $this->msg( 'abusefilter-log-diff' )->parse() ),
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'diff' => 'prev',
|
|
|
|
'target' => $title->getPrefixedText(),
|
|
|
|
'timestamp' => $row->ar_timestamp,
|
|
|
|
]
|
|
|
|
);
|
2012-02-10 23:41:05 +00:00
|
|
|
}
|
2009-03-30 06:12:12 +00:00
|
|
|
} else {
|
|
|
|
$pageLink = WikiMap::makeForeignLink( $row->afl_wiki, $row->afl_title );
|
2012-02-10 23:41:05 +00:00
|
|
|
|
|
|
|
if ( $row->afl_rev_id ) {
|
|
|
|
$diffUrl = WikiMap::getForeignURL( $row->afl_wiki, $row->afl_title );
|
|
|
|
$diffUrl = wfAppendQuery( $diffUrl,
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'diff' => 'prev', 'oldid' => $row->afl_rev_id ] );
|
2012-02-10 23:41:05 +00:00
|
|
|
|
|
|
|
$diffLink = Linker::makeExternalLink( $diffUrl,
|
2019-03-11 12:23:49 +00:00
|
|
|
$this->msg( 'abusefilter-log-diff' )->text() );
|
2012-02-10 23:41:05 +00:00
|
|
|
}
|
2009-03-30 06:12:12 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !$row->afl_wiki ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
// Local user
|
2016-08-15 10:08:17 +00:00
|
|
|
$userLink = self::getUserLinks( $row->afl_user, $row->afl_user_text );
|
2009-03-30 06:12:12 +00:00
|
|
|
} else {
|
2013-06-26 22:58:36 +00:00
|
|
|
$userLink = WikiMap::foreignUserLink( $row->afl_wiki, $row->afl_user_text );
|
2011-11-16 05:34:24 +00:00
|
|
|
$userLink .= ' (' . WikiMap::getWikiName( $row->afl_wiki ) . ')';
|
2009-03-30 06:12:12 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-06-02 08:13:17 +00:00
|
|
|
$timestamp = htmlspecialchars( $lang->timeanddate( $row->afl_timestamp, true ) );
|
2009-02-26 21:45:07 +00:00
|
|
|
|
2020-06-02 08:13:17 +00:00
|
|
|
$actions_takenRaw = $row->afl_actions;
|
|
|
|
if ( !strlen( trim( $actions_takenRaw ) ) ) {
|
2018-05-01 12:13:57 +00:00
|
|
|
$actions_taken = $this->msg( 'abusefilter-log-noactions' )->escaped();
|
2009-01-28 01:26:38 +00:00
|
|
|
} else {
|
2020-06-02 08:13:17 +00:00
|
|
|
$actions = explode( ',', $actions_takenRaw );
|
2017-06-15 14:23:34 +00:00
|
|
|
$displayActions = [];
|
2009-01-28 01:26:38 +00:00
|
|
|
|
2020-08-25 19:33:37 +00:00
|
|
|
$context = $this->getContext();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action ) {
|
2020-08-25 19:33:37 +00:00
|
|
|
$displayActions[] = AbuseFilter::getActionDisplay( $action, $context );
|
2009-01-28 01:26:38 +00:00
|
|
|
}
|
2011-11-16 05:34:24 +00:00
|
|
|
$actions_taken = $lang->commaList( $displayActions );
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-06-17 10:54:00 +00:00
|
|
|
list( $filterID, $global ) = AbuseFilter::splitGlobalName( $row->afl_filter );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-02-06 12:59:34 +00:00
|
|
|
if ( $global ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
// Pull global filter description
|
2018-03-10 12:18:49 +00:00
|
|
|
$escaped_comments = Sanitizer::escapeHtmlAllowEntities(
|
2019-06-17 10:54:00 +00:00
|
|
|
AbuseFilter::getGlobalFilterDescription( $filterID ) );
|
2012-01-03 17:29:10 +00:00
|
|
|
$filter_hidden = null;
|
2009-03-30 06:12:12 +00:00
|
|
|
} else {
|
2018-03-10 12:18:49 +00:00
|
|
|
$escaped_comments = Sanitizer::escapeHtmlAllowEntities(
|
|
|
|
$row->af_public_comments );
|
2012-01-03 17:29:10 +00:00
|
|
|
$filter_hidden = $row->af_hidden;
|
2009-03-30 06:12:12 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-08-27 09:40:01 +00:00
|
|
|
if ( self::canSeeDetails( $user, $filterID, $global, $filter_hidden ) ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( $isListItem ) {
|
2016-12-04 15:13:16 +00:00
|
|
|
$detailsLink = $linkRenderer->makeKnownLink(
|
2015-09-28 18:03:35 +00:00
|
|
|
$this->getPageTitle( $row->afl_id ),
|
2016-12-04 15:13:16 +00:00
|
|
|
$this->msg( 'abusefilter-log-detailslink' )->text()
|
2014-01-06 20:16:27 +00:00
|
|
|
);
|
|
|
|
$actionLinks[] = $detailsLink;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$examineTitle = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/log/' . $row->afl_id );
|
2016-12-04 15:13:16 +00:00
|
|
|
$examineLink = $linkRenderer->makeKnownLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
$examineTitle,
|
2016-12-04 15:13:16 +00:00
|
|
|
new HtmlArmor( $this->msg( 'abusefilter-changeslist-examine' )->parse() )
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2010-06-25 20:04:55 +00:00
|
|
|
$actionLinks[] = $examineLink;
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2016-01-06 20:17:41 +00:00
|
|
|
if ( $diffLink ) {
|
2012-02-10 23:41:05 +00:00
|
|
|
$actionLinks[] = $diffLink;
|
2016-01-06 20:17:41 +00:00
|
|
|
}
|
2012-02-10 23:41:05 +00:00
|
|
|
|
2020-09-17 06:54:06 +00:00
|
|
|
if ( $this->permissionManager->userHasRight( $user, 'abusefilter-hide-log' ) ) {
|
2016-12-04 15:13:16 +00:00
|
|
|
$hideLink = $linkRenderer->makeKnownLink(
|
2013-12-27 06:36:34 +00:00
|
|
|
$this->getPageTitle(),
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-log-hidelink' )->text(),
|
2017-06-15 14:23:34 +00:00
|
|
|
[],
|
|
|
|
[ 'hide' => $row->afl_id ]
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2010-06-25 20:04:55 +00:00
|
|
|
$actionLinks[] = $hideLink;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-02-06 12:59:34 +00:00
|
|
|
if ( $global ) {
|
2018-03-10 21:47:33 +00:00
|
|
|
$globalURL = WikiMap::getForeignURL(
|
|
|
|
$this->getConfig()->get( 'AbuseFilterCentralDB' ),
|
2019-06-17 10:54:00 +00:00
|
|
|
'Special:AbuseFilter/' . $filterID
|
2018-03-10 21:47:33 +00:00
|
|
|
);
|
2016-06-01 12:43:37 +00:00
|
|
|
$linkText = $this->msg( 'abusefilter-log-detailedentry-global' )
|
2019-06-17 10:54:00 +00:00
|
|
|
->numParams( $filterID )->text();
|
2012-03-11 20:51:54 +00:00
|
|
|
$filterLink = Linker::makeExternalLink( $globalURL, $linkText );
|
2009-03-30 06:12:12 +00:00
|
|
|
} else {
|
2019-03-28 19:59:53 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'AbuseFilter', $filterID );
|
2016-06-01 12:43:37 +00:00
|
|
|
$linkText = $this->msg( 'abusefilter-log-detailedentry-local' )
|
2019-03-28 19:59:53 +00:00
|
|
|
->numParams( $filterID )->text();
|
2016-12-04 15:13:16 +00:00
|
|
|
$filterLink = $linkRenderer->makeKnownLink( $title, $linkText );
|
2009-03-30 06:12:12 +00:00
|
|
|
}
|
2012-09-02 11:07:02 +00:00
|
|
|
$description = $this->msg( 'abusefilter-log-detailedentry-meta' )->rawParams(
|
|
|
|
$timestamp,
|
|
|
|
$userLink,
|
|
|
|
$filterLink,
|
2020-06-02 08:13:17 +00:00
|
|
|
htmlspecialchars( $row->afl_action ),
|
2012-09-02 11:07:02 +00:00
|
|
|
$pageLink,
|
|
|
|
$actions_taken,
|
2018-03-10 12:18:49 +00:00
|
|
|
$escaped_comments,
|
2016-06-04 11:59:56 +00:00
|
|
|
$lang->pipeList( $actionLinks )
|
|
|
|
)->params( $row->afl_user_text )->parse();
|
2008-06-27 06:18:51 +00:00
|
|
|
} else {
|
2014-01-06 03:53:05 +00:00
|
|
|
if ( $diffLink ) {
|
|
|
|
$msg = 'abusefilter-log-entry-withdiff';
|
|
|
|
} else {
|
|
|
|
$msg = 'abusefilter-log-entry';
|
|
|
|
}
|
|
|
|
$description = $this->msg( $msg )->rawParams(
|
2012-09-02 11:07:02 +00:00
|
|
|
$timestamp,
|
|
|
|
$userLink,
|
2020-06-02 08:13:17 +00:00
|
|
|
htmlspecialchars( $row->afl_action ),
|
2013-07-09 16:04:53 +00:00
|
|
|
$pageLink,
|
2012-09-02 11:07:02 +00:00
|
|
|
$actions_taken,
|
2018-03-10 12:18:49 +00:00
|
|
|
$escaped_comments,
|
2018-04-04 21:14:25 +00:00
|
|
|
// Passing $7 to 'abusefilter-log-entry' will do nothing, as it's not used.
|
|
|
|
$diffLink
|
2016-06-04 12:41:37 +00:00
|
|
|
)->params( $row->afl_user_text )->parse();
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2019-01-23 10:34:43 +00:00
|
|
|
$attribs = null;
|
2016-08-15 10:08:17 +00:00
|
|
|
if ( $isHidden === true ) {
|
2019-01-23 10:34:43 +00:00
|
|
|
$attribs = [ 'class' => 'mw-abusefilter-log-hidden-entry' ];
|
2016-08-15 10:08:17 +00:00
|
|
|
} elseif ( $isHidden === 'implicit' ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
$description .= ' ' .
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-log-hidden-implicit' )->parse();
|
2010-06-25 20:04:55 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2014-01-06 20:16:27 +00:00
|
|
|
if ( $isListItem ) {
|
2019-01-23 10:34:43 +00:00
|
|
|
return Xml::tags( 'li', $attribs, $description );
|
2013-03-28 14:09:52 +00:00
|
|
|
} else {
|
2019-01-23 10:34:43 +00:00
|
|
|
return Xml::tags( 'span', $attribs, $description );
|
2013-03-28 14:09:52 +00:00
|
|
|
}
|
2008-06-27 06:18:51 +00:00
|
|
|
}
|
2011-07-04 22:00:06 +00:00
|
|
|
|
2017-10-20 17:46:31 +00:00
|
|
|
/**
|
|
|
|
* @param int $userId
|
|
|
|
* @param string $userName
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-08-15 10:08:17 +00:00
|
|
|
protected 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
|
|
|
}
|