2009-01-29 22:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
2020-01-11 17:05:30 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\RCVariableGenerator;
|
2020-01-08 16:46:24 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-01-08 13:33:10 +00:00
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
class AbuseFilterViewExamine extends AbuseFilterView {
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The user whose entries we're examinating
|
|
|
|
*/
|
|
|
|
public $mSearchUser;
|
|
|
|
/**
|
|
|
|
* @var string The start time of the search period
|
|
|
|
*/
|
|
|
|
public $mSearchPeriodStart;
|
|
|
|
/**
|
|
|
|
* @var string The end time of the search period
|
|
|
|
*/
|
|
|
|
public $mSearchPeriodEnd;
|
|
|
|
/**
|
|
|
|
* @var string The ID of the filter we're examinating
|
|
|
|
*/
|
2018-03-30 00:57:57 +00:00
|
|
|
public $mTestFilter;
|
2013-10-15 13:22:05 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-examine' ) );
|
2020-10-03 13:05:20 +00:00
|
|
|
$out->addHelpLink( 'Extension:AbuseFilter/Rules format' );
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-examine-intro' );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$this->loadParameters();
|
|
|
|
|
|
|
|
// Check if we've got a subpage
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $this->mParams ) > 1 && is_numeric( $this->mParams[1] ) ) {
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminerForRC( $this->mParams[1] );
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( count( $this->mParams ) > 2
|
2018-08-26 08:34:42 +00:00
|
|
|
&& $this->mParams[1] === 'log'
|
2017-07-08 18:49:13 +00:00
|
|
|
&& is_numeric( $this->mParams[2] )
|
|
|
|
) {
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminerForLogEntry( $this->mParams[2] );
|
2009-01-29 22:44:31 +00:00
|
|
|
} else {
|
|
|
|
$this->showSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the search form
|
|
|
|
*/
|
|
|
|
public function showSearch() {
|
2018-03-09 11:27:18 +00:00
|
|
|
$RCMaxAge = $this->getConfig()->get( 'RCMaxAge' );
|
|
|
|
$min = wfTimestamp( TS_ISO_8601, time() - $RCMaxAge );
|
|
|
|
$max = wfTimestampNow();
|
2017-06-15 14:23:16 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
'SearchUser' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-user',
|
|
|
|
'type' => 'user',
|
2018-04-05 10:23:57 +00:00
|
|
|
'ipallowed' => true,
|
2016-04-10 13:12:43 +00:00
|
|
|
'default' => $this->mSearchUser,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'SearchPeriodStart' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-period-start',
|
2018-03-09 11:27:18 +00:00
|
|
|
'type' => 'datetime',
|
2016-04-10 13:12:43 +00:00
|
|
|
'default' => $this->mSearchPeriodStart,
|
2018-03-09 11:27:18 +00:00
|
|
|
'min' => $min,
|
|
|
|
'max' => $max,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'SearchPeriodEnd' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-period-end',
|
2018-03-09 11:27:18 +00:00
|
|
|
'type' => 'datetime',
|
2016-04-10 13:12:43 +00:00
|
|
|
'default' => $this->mSearchPeriodEnd,
|
2018-03-09 11:27:18 +00:00
|
|
|
'min' => $min,
|
|
|
|
'max' => $max,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
];
|
2018-03-09 10:45:50 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
2016-04-10 13:12:43 +00:00
|
|
|
$htmlForm->setWrapperLegendMsg( 'abusefilter-examine-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-examine-submit' )
|
2020-10-04 12:38:18 +00:00
|
|
|
->setFormIdentifier( 'examine-select-date' )
|
|
|
|
->setSubmitCallback( [ $this, 'showResults' ] )
|
|
|
|
->showAlways();
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2020-10-04 12:38:18 +00:00
|
|
|
* Show search results, called as submit callback by HTMLForm
|
|
|
|
* @param array $formData
|
|
|
|
* @param HTMLForm $form
|
|
|
|
* @return bool
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2020-10-04 12:38:18 +00:00
|
|
|
public function showResults( array $formData, HTMLForm $form ) : bool {
|
2018-02-04 18:50:43 +00:00
|
|
|
$changesList = new AbuseFilterChangesList( $this->getSkin(), $this->mTestFilter );
|
2009-03-12 11:38:21 +00:00
|
|
|
$pager = new AbuseFilterExaminePager( $this, $changesList );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-31 14:27:20 +00:00
|
|
|
$output = $changesList->beginRecentChangesList()
|
|
|
|
. $pager->getNavigationBar()
|
|
|
|
. $pager->getBody()
|
|
|
|
. $pager->getNavigationBar()
|
|
|
|
. $changesList->endRecentChangesList();
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2020-10-04 12:38:18 +00:00
|
|
|
$form->addPostText( $output );
|
|
|
|
return true;
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param int $rcid
|
|
|
|
*/
|
|
|
|
public function showExaminerForRC( $rcid ) {
|
2009-01-29 22:44:31 +00:00
|
|
|
// Get data
|
2020-05-28 18:09:17 +00:00
|
|
|
$rc = RecentChange::newFromId( $rcid );
|
2014-07-29 23:46:29 +00:00
|
|
|
$out = $this->getOutput();
|
2020-05-28 18:09:17 +00:00
|
|
|
if ( !$rc ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-examine-notfound' );
|
2009-01-29 22:44:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-28 18:09:17 +00:00
|
|
|
if ( !ChangesList::userCan( $rc, RevisionRecord::SUPPRESSED_ALL ) ) {
|
2018-10-16 21:04:20 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-details-hidden-implicit' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-25 16:39:57 +00:00
|
|
|
$vars = new AbuseFilterVariableHolder();
|
2020-09-20 22:07:57 +00:00
|
|
|
$varGenerator = new RCVariableGenerator( $vars, $rc, $this->getUser() );
|
2019-06-25 16:39:57 +00:00
|
|
|
$vars = $varGenerator->getVars();
|
2018-12-08 14:20:34 +00:00
|
|
|
$out->addJsConfigVars( [
|
2020-06-17 17:42:58 +00:00
|
|
|
'wgAbuseFilterVariables' => $vars ? $vars->dumpAllVars( true ) : [],
|
2018-12-08 14:20:34 +00:00
|
|
|
'abuseFilterExamine' => [ 'type' => 'rc', 'id' => $rcid ]
|
|
|
|
] );
|
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param int $logid
|
|
|
|
*/
|
|
|
|
public function showExaminerForLogEntry( $logid ) {
|
2009-02-04 19:51:03 +00:00
|
|
|
// Get data
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
$out = $this->getOutput();
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2019-08-27 09:40:01 +00:00
|
|
|
|
2018-02-05 10:48:58 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_log',
|
2018-07-13 22:34:54 +00:00
|
|
|
[
|
|
|
|
'afl_filter',
|
|
|
|
'afl_deleted',
|
|
|
|
'afl_var_dump',
|
|
|
|
'afl_rev_id'
|
|
|
|
],
|
2018-02-05 10:48:58 +00:00
|
|
|
[ 'afl_id' => $logid ],
|
|
|
|
__METHOD__
|
|
|
|
);
|
2009-02-04 19:51:03 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$row ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-examine-notfound' );
|
2009-02-04 19:51:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:24:02 +00:00
|
|
|
[ $filterID, $isGlobal ] = AbuseFilter::splitGlobalName( $row->afl_filter );
|
|
|
|
$isHidden = AbuseFilterServices::getFilterLookup()->getFilter( $filterID, $isGlobal )->isHidden();
|
2020-10-27 19:21:44 +00:00
|
|
|
if ( !$afPermManager->canSeeLogDetailsForFilter( $user, $isHidden ) ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-cannot-see-details' );
|
2011-12-27 23:35:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $row->afl_deleted && !$afPermManager->canSeeHiddenLogEntries( $user ) ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-details-hidden' );
|
2011-12-27 23:35:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:04:20 +00:00
|
|
|
if ( SpecialAbuseLog::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 ) ) {
|
2018-10-16 21:04:20 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-details-hidden-implicit' );
|
|
|
|
return;
|
|
|
|
}
|
2018-07-13 22:34:54 +00:00
|
|
|
}
|
2009-02-27 03:06:19 +00:00
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
2018-12-08 14:20:34 +00:00
|
|
|
$out->addJsConfigVars( [
|
|
|
|
'wgAbuseFilterVariables' => $vars->dumpAllVars( true ),
|
|
|
|
'abuseFilterExamine' => [ 'type' => 'log', 'id' => $logid ]
|
|
|
|
] );
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param AbuseFilterVariableHolder|null $vars
|
|
|
|
*/
|
|
|
|
public function showExaminer( $vars ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$output = $this->getOutput();
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2018-03-15 17:22:37 +00:00
|
|
|
$output->enableOOUI();
|
2009-02-04 19:51:03 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$vars ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$output->addWikiMsg( 'abusefilter-examine-incompatible' );
|
2009-01-29 22:44:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $vars instanceof AbuseFilterVariableHolder ) {
|
2009-03-25 02:53:23 +00:00
|
|
|
$vars = $vars->exportAllVars();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$html = '';
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$output->addModules( 'ext.abuseFilter.examine' );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Add test bit
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $afPermManager->canViewPrivateFilters( $this->getUser() ) ) {
|
2020-11-24 12:16:41 +00:00
|
|
|
$boxBuilderFactory = AbuseFilterServices::getEditBoxBuilderFactory();
|
|
|
|
$boxBuilder = $boxBuilderFactory->newEditBoxBuilder(
|
|
|
|
$this,
|
|
|
|
$this->getUser(),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$tester = Xml::tags( 'h2', null, $this->msg( 'abusefilter-examine-test' )->parse() );
|
2020-11-24 12:16:41 +00:00
|
|
|
$tester .= $boxBuilder->buildEditBox( $this->mTestFilter, false, false, false );
|
2018-12-09 13:33:30 +00:00
|
|
|
$tester .= $this->buildFilterLoader();
|
2017-06-15 14:23:16 +00:00
|
|
|
$html .= Xml::tags( 'div', [ 'id' => 'mw-abusefilter-examine-editor' ], $tester );
|
2011-11-22 16:08:18 +00:00
|
|
|
$html .= Xml::tags( 'p',
|
2009-10-07 13:57:06 +00:00
|
|
|
null,
|
2018-03-15 17:22:37 +00:00
|
|
|
new OOUI\ButtonInputWidget(
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2018-03-15 17:22:37 +00:00
|
|
|
'label' => $this->msg( 'abusefilter-examine-test-button' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'id' => 'mw-abusefilter-examine-test'
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
2009-03-31 15:13:26 +00:00
|
|
|
) .
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::element( 'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'id' => 'mw-abusefilter-syntaxresult',
|
|
|
|
'style' => 'display: none;'
|
2017-06-15 14:23:16 +00:00
|
|
|
], ' '
|
2009-10-07 13:57:06 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-03-31 15:13:26 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Variable dump
|
2012-09-02 11:07:02 +00:00
|
|
|
$html .= Xml::tags(
|
|
|
|
'h2',
|
|
|
|
null,
|
2017-08-20 12:48:51 +00:00
|
|
|
$this->msg( 'abusefilter-examine-vars' )->parse()
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
2016-09-17 07:03:42 +00:00
|
|
|
$html .= AbuseFilter::buildVarDumpTable( $vars, $this->getContext() );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$output->addHTML( $html );
|
2009-01-29 22:44:31 +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();
|
|
|
|
$this->mSearchPeriodStart = $request->getText( 'wpSearchPeriodStart' );
|
|
|
|
$this->mSearchPeriodEnd = $request->getText( 'wpSearchPeriodEnd' );
|
|
|
|
$this->mTestFilter = $request->getText( 'testfilter' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-25 02:33:09 +00:00
|
|
|
// Normalise username
|
2017-11-17 15:24:42 +00:00
|
|
|
$searchUsername = $request->getText( 'wpSearchUser' );
|
|
|
|
$userTitle = Title::newFromText( $searchUsername, NS_USER );
|
|
|
|
$this->mSearchUser = $userTitle ? $userTitle->getText() : '';
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|