2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
2013-10-15 13:22:05 +00:00
|
|
|
* @param SpecialAbuseFilter $page
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param array $params
|
|
|
|
*/
|
2009-01-23 19:23:19 +00:00
|
|
|
function __construct( $page, $params ) {
|
|
|
|
parent::__construct( $page, $params );
|
|
|
|
$this->mFilter = $page->mFilter;
|
|
|
|
$this->mHistoryID = $page->mHistoryID;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
2012-12-15 10:18:25 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-edit' ) );
|
2015-03-29 12:38:53 +00:00
|
|
|
$out->addHelpLink( 'Extension:AbuseFilter/Rules format' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$filter = $this->mFilter;
|
|
|
|
$history_id = $this->mHistoryID;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-06-06 05:18:31 +00:00
|
|
|
// Add default warning messages
|
|
|
|
$this->exposeWarningMessages();
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( $filter == 'new' && !$user->isAllowed( 'abusefilter-modify' ) ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed' );
|
2009-09-18 10:05:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$editToken = $request->getVal( 'wpEditToken' );
|
2010-02-13 14:10:36 +00:00
|
|
|
$didEdit = $this->canEdit()
|
2011-11-16 05:34:24 +00:00
|
|
|
&& $user->matchEditToken( $editToken, array( 'abusefilter', $filter ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( $didEdit ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Check syntax
|
2011-11-16 05:34:24 +00:00
|
|
|
$syntaxerr = AbuseFilter::checkSyntax( $request->getVal( 'wpFilterRules' ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $syntaxerr !== true ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-02-07 09:34:11 +00:00
|
|
|
$this->buildFilterEditor(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-badsyntax',
|
|
|
|
array( $syntaxerr[0] )
|
2012-09-02 11:07:02 +00:00
|
|
|
)->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$filter, $history_id
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $newRow, $actions ) = $this->loadRequest( $filter );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$differences = AbuseFilter::compareVersions(
|
|
|
|
array( $newRow, $actions ),
|
|
|
|
array( $newRow->mOriginalRow, $newRow->mOriginalActions )
|
|
|
|
);
|
2009-01-26 22:31:02 +00:00
|
|
|
|
2012-09-12 15:31:24 +00:00
|
|
|
// Don't allow adding a new global rule, or updating a
|
|
|
|
// rule that is currently global, without permissions.
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $newRow ) || !$this->canEditFilter( $newRow->mOriginalRow ) ) {
|
2012-09-12 15:31:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed-global' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 21:57:20 +00:00
|
|
|
// Don't allow custom messages on global rules
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( $newRow->af_global == 1 &&
|
|
|
|
$request->getVal( 'wpFilterWarnMessage' ) !== 'abusefilter-warning'
|
|
|
|
) {
|
2013-06-26 21:57:20 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed-global-custom-msg' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-08 01:02:11 +00:00
|
|
|
$origActions = $newRow->mOriginalActions;
|
2016-08-10 17:05:27 +00:00
|
|
|
$wasGlobal = (bool)$newRow->mOriginalRow->af_global;
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
unset( $newRow->mOriginalRow );
|
|
|
|
unset( $newRow->mOriginalActions );
|
2009-01-26 22:30:42 +00:00
|
|
|
|
2009-01-27 19:51:38 +00:00
|
|
|
// Check for non-changes
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !count( $differences ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->redirect( $this->getTitle()->getLocalURL() );
|
2009-01-26 22:30:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-27 19:51:38 +00:00
|
|
|
// Check for restricted actions
|
2016-06-03 18:01:56 +00:00
|
|
|
global $wgAbuseFilterRestrictions;
|
|
|
|
if ( count( array_intersect_key(
|
|
|
|
array_filter( $wgAbuseFilterRestrictions ),
|
|
|
|
array_merge(
|
|
|
|
array_filter( $actions ),
|
|
|
|
array_filter( $origActions )
|
|
|
|
)
|
2012-02-08 01:02:11 +00:00
|
|
|
) )
|
|
|
|
&& !$user->isAllowed( 'abusefilter-modify-restricted' )
|
|
|
|
) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildFilterEditor(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-restricted' )->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter,
|
|
|
|
$history_id
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-17 15:37:03 +00:00
|
|
|
// If we've activated the 'tag' option, check the arguments for validity.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !empty( $actions['tag'] ) ) {
|
2009-07-17 15:37:03 +00:00
|
|
|
$bad = false;
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions['tag']['parameters'] as $tag ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$t = Title::makeTitleSafe( NS_MEDIAWIKI, 'tag-' . $tag );
|
|
|
|
if ( !$t ) {
|
2009-07-17 15:37:03 +00:00
|
|
|
$bad = true;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $bad ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildFilterEditor(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-bad-tags' )->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter,
|
|
|
|
$history_id
|
|
|
|
)
|
|
|
|
);
|
2009-07-17 15:37:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-27 19:51:38 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$newRow = get_object_vars( $newRow ); // Convert from object to array
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Set last modifier.
|
|
|
|
$newRow['af_timestamp'] = $dbw->timestamp( wfTimestampNow() );
|
2011-11-16 05:34:24 +00:00
|
|
|
$newRow['af_user'] = $user->getId();
|
|
|
|
$newRow['af_user_text'] = $user->getName();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2015-10-08 05:54:58 +00:00
|
|
|
$dbw->startAtomic( __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Insert MAIN row.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter == 'new' ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$new_id = $dbw->nextSequenceValue( 'abuse_filter_af_id_seq' );
|
|
|
|
$is_new = true;
|
|
|
|
} else {
|
|
|
|
$new_id = $this->mFilter;
|
|
|
|
$is_new = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset throttled marker, if we're re-enabling it.
|
|
|
|
$newRow['af_throttled'] = $newRow['af_throttled'] && !$newRow['af_enabled'];
|
|
|
|
$newRow['af_id'] = $new_id; // ID.
|
|
|
|
|
2014-05-27 13:29:27 +00:00
|
|
|
// T67807
|
|
|
|
// integer 1's & 0's might be better understood than booleans
|
|
|
|
$newRow['af_enabled'] = (int) $newRow['af_enabled'];
|
|
|
|
$newRow['af_hidden'] = (int) $newRow['af_hidden'];
|
|
|
|
$newRow['af_throttled'] = (int) $newRow['af_throttled'];
|
|
|
|
$newRow['af_deleted'] = (int) $newRow['af_deleted'];
|
|
|
|
$newRow['af_global'] = (int) $newRow['af_global'];
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$dbw->replace( 'abuse_filter', array( 'af_id' ), $newRow, __METHOD__ );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $is_new ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$new_id = $dbw->insertId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
2016-06-03 18:01:56 +00:00
|
|
|
global $wgAbuseFilterActions;
|
2009-01-23 19:23:19 +00:00
|
|
|
$deadActions = array();
|
|
|
|
$actionsRows = array();
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( array_filter( $wgAbuseFilterActions ) as $action => $_ ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Check if it's set
|
2010-02-13 14:10:36 +00:00
|
|
|
$enabled = isset( $actions[$action] ) && (bool)$actions[$action];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $enabled ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$parameters = $actions[$action]['parameters'];
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$thisRow = array(
|
|
|
|
'afa_filter' => $new_id,
|
|
|
|
'afa_consequence' => $action,
|
|
|
|
'afa_parameters' => implode( "\n", $parameters )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$actionsRows[] = $thisRow;
|
|
|
|
} else {
|
|
|
|
$deadActions[] = $action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a history row
|
|
|
|
$afh_row = array();
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( AbuseFilter::$history_mappings as $af_col => $afh_col ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$afh_row[$afh_col] = $newRow[$af_col];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
$displayActions = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$displayActions[$action['action']] = $action['parameters'];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$afh_row['afh_actions'] = serialize( $displayActions );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
$afh_row['afh_changed_fields'] = implode( ',', $differences );
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Flags
|
|
|
|
$flags = array();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $newRow['af_hidden'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'hidden';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_enabled'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'enabled';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_deleted'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'deleted';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_global'] ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
$flags[] = 'global';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
$afh_row['afh_flags'] = implode( ',', $flags );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$afh_row['afh_filter'] = $new_id;
|
2010-10-29 21:55:29 +00:00
|
|
|
$afh_row['afh_id'] = $dbw->nextSequenceValue( 'abuse_filter_af_id_seq' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Do the update
|
|
|
|
$dbw->insert( 'abuse_filter_history', $afh_row, __METHOD__ );
|
2009-03-11 07:12:42 +00:00
|
|
|
$history_id = $dbw->insertId();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $filter != 'new' ) {
|
|
|
|
$dbw->delete(
|
|
|
|
'abuse_filter_action',
|
|
|
|
array( 'afa_filter' => $filter ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
$dbw->insert( 'abuse_filter_action', $actionsRows, __METHOD__ );
|
|
|
|
|
2015-10-08 05:54:58 +00:00
|
|
|
$dbw->endAtomic( __METHOD__ );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-08-10 17:05:27 +00:00
|
|
|
// Invalidate cache if this was a global rule
|
|
|
|
if ( $wasGlobal || $newRow['af_global'] ) {
|
2012-08-03 21:55:35 +00:00
|
|
|
$group = 'default';
|
|
|
|
if ( isset( $newRow['af_group'] ) && $newRow['af_group'] != '' ) {
|
|
|
|
$group = $newRow['af_group'];
|
|
|
|
}
|
|
|
|
|
2015-05-13 05:46:33 +00:00
|
|
|
$globalRulesKey = AbuseFilter::getGlobalRulesKey( $group );
|
|
|
|
ObjectCache::getMainWANInstance()->touchCheckKey( $globalRulesKey );
|
2012-08-03 21:55:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 07:12:42 +00:00
|
|
|
// Logging
|
2009-07-03 12:48:28 +00:00
|
|
|
$lp = new LogPage( 'abusefilter' );
|
|
|
|
$lp->addEntry( 'modify', $this->getTitle( $new_id ), '', array( $history_id, $new_id ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2015-04-29 22:42:14 +00:00
|
|
|
// Purge the tag list cache so the fetchAllTags hook applies tag changes
|
2009-01-30 23:24:29 +00:00
|
|
|
if ( isset( $actions['tag'] ) ) {
|
2015-04-29 22:42:14 +00:00
|
|
|
ChangeTags::purgeTagCacheAll();
|
2009-01-30 23:24:29 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-04-08 13:51:54 +00:00
|
|
|
AbuseFilter::resetFilterProfile( $new_id );
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->redirect(
|
2013-10-06 02:30:37 +00:00
|
|
|
$this->getTitle()->getLocalURL(
|
|
|
|
array(
|
|
|
|
'result' => 'success',
|
|
|
|
'changedfilter' => $new_id,
|
|
|
|
'changeid' => $history_id,
|
2013-10-07 17:05:49 +00:00
|
|
|
)
|
2013-10-06 02:30:37 +00:00
|
|
|
)
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
} else {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $history_id ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg(
|
2009-02-07 09:34:11 +00:00
|
|
|
'abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $this->buildFilterEditor( null, $this->mFilter, $history_id ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $history_id ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg(
|
2009-02-07 09:34:11 +00:00
|
|
|
'abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Builds the full form for edit filters.
|
|
|
|
* Loads data either from the database or from the HTTP request.
|
|
|
|
* The request takes precedence over the database
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $error string An error message to show above the filter box.
|
|
|
|
* @param $filter int The filter ID
|
|
|
|
* @param $history_id int The history ID of the filter, if applicable. Otherwise null
|
2015-09-28 18:03:35 +00:00
|
|
|
* @return bool|string False if there is a failure building the editor,
|
|
|
|
* otherwise the HTML text for the editor.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2009-10-07 13:57:06 +00:00
|
|
|
function buildFilterEditor( $error, $filter, $history_id = null ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $filter === null ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the edit form
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load from request OR database.
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $row, $actions ) = $this->loadRequest( $filter, $history_id );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !$row ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-badfilter' );
|
2012-09-02 11:07:02 +00:00
|
|
|
$out->addHTML( Linker::link( $this->getTitle(), $this->msg( 'abusefilter-return' )->text() ) );
|
|
|
|
return false;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 10:18:25 +00:00
|
|
|
$out->addSubtitle( $this->msg(
|
2012-06-09 15:10:36 +00:00
|
|
|
$filter === 'new' ? 'abusefilter-edit-subtitle-new' : 'abusefilter-edit-subtitle',
|
2012-10-26 07:40:14 +00:00
|
|
|
$this->getLanguage()->formatNum( $filter ), $history_id
|
2012-09-02 11:07:02 +00:00
|
|
|
)->text() );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Hide hidden filters.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( ( ( isset( $row->af_hidden ) && $row->af_hidden ) ||
|
2009-08-07 16:13:06 +00:00
|
|
|
AbuseFilter::filterHidden( $filter ) )
|
|
|
|
&& !$this->canViewPrivate() ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
return $this->msg( 'abusefilter-edit-denied' )->text();
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $error ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( "<span class=\"error\">$error</span>" );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
// Read-only attribute
|
|
|
|
$readOnlyAttrib = array();
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib = array(); // For checkboxes
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $row ) ) {
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib['disabled'] = 'disabled';
|
2009-04-01 04:34:21 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$fields = array();
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$fields['abusefilter-edit-id'] =
|
2015-09-28 18:03:35 +00:00
|
|
|
$this->mFilter == 'new' ?
|
|
|
|
$this->msg( 'abusefilter-edit-new' )->text() :
|
|
|
|
$lang->formatNum( $filter );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-description'] =
|
|
|
|
Xml::input(
|
|
|
|
'wpFilterDescription',
|
|
|
|
45,
|
2009-04-01 04:34:21 +00:00
|
|
|
isset( $row->af_public_comments ) ? $row->af_public_comments : '',
|
|
|
|
$readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2012-05-06 06:44:45 +00:00
|
|
|
global $wgAbuseFilterValidGroups;
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( count( $wgAbuseFilterValidGroups ) > 1 ) {
|
2012-05-06 06:44:45 +00:00
|
|
|
$groupSelector = new XmlSelect(
|
|
|
|
'wpFilterGroup',
|
2012-06-06 05:18:31 +00:00
|
|
|
'mw-abusefilter-edit-group-input',
|
2012-05-06 06:44:45 +00:00
|
|
|
'default'
|
|
|
|
);
|
|
|
|
|
2012-09-27 10:10:10 +00:00
|
|
|
if ( isset( $row->af_group ) && $row->af_group ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
$groupSelector->setDefault( $row->af_group );
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
foreach ( $wgAbuseFilterValidGroups as $group ) {
|
|
|
|
$groupSelector->addOption( AbuseFilter::nameGroup( $group ), $group );
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$fields['abusefilter-edit-group'] = $groupSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Hit count display
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !empty( $row->af_hit_count ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$count_display = $this->msg( 'abusefilter-hitcount' )
|
|
|
|
->numParams( (int) $row->af_hit_count )->escaped();
|
|
|
|
$hitCount = Linker::linkKnown(
|
2009-10-07 13:57:06 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$count_display,
|
2012-09-02 11:07:02 +00:00
|
|
|
array(),
|
|
|
|
array( 'wpSearchFilter' => $row->af_id )
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$fields['abusefilter-edit-hitcount'] = $hitCount;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter !== 'new' ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Statistics
|
2016-04-13 18:06:24 +00:00
|
|
|
global $wgAbuseFilterProfile;
|
|
|
|
$stash = ObjectCache::getMainStashInstance();
|
|
|
|
$matches_count = $stash->get( AbuseFilter::filterMatchesKey( $filter ) );
|
|
|
|
$total = $stash->get( AbuseFilter::filterUsedKey( $row->af_group ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $total > 0 ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
|
2016-04-08 16:22:39 +00:00
|
|
|
if ( $wgAbuseFilterProfile ) {
|
|
|
|
list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter );
|
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status-profile' )
|
|
|
|
->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile )
|
|
|
|
->escaped();
|
|
|
|
} else {
|
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' )
|
|
|
|
->numParams( $total, $matches_count, $matches_percent )
|
|
|
|
->escaped();
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$fields['abusefilter-edit-rules'] = AbuseFilter::buildEditBox(
|
|
|
|
$row->af_pattern,
|
|
|
|
'wpFilterRules',
|
|
|
|
true,
|
2013-07-09 13:35:06 +00:00
|
|
|
$this->canEditFilter( $row )
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
|
|
|
$fields['abusefilter-edit-notes'] = Xml::textarea(
|
|
|
|
'wpFilterNotes',
|
|
|
|
( isset( $row->af_comments ) ? $row->af_comments . "\n" : "\n" ),
|
2014-01-10 14:39:12 +00:00
|
|
|
40, 15,
|
2012-09-02 11:07:02 +00:00
|
|
|
$readOnlyAttrib
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Build checkboxen
|
|
|
|
$checkboxes = array( 'hidden', 'enabled', 'deleted' );
|
|
|
|
$flags = '';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-30 06:12:12 +00:00
|
|
|
global $wgAbuseFilterIsCentral;
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $wgAbuseFilterIsCentral ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
$checkboxes[] = 'global';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( isset( $row->af_throttled ) && $row->af_throttled ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
global $wgAbuseFilterEmergencyDisableThreshold;
|
2012-10-23 13:14:34 +00:00
|
|
|
|
|
|
|
// determine emergency disable value for this action
|
2015-09-28 18:03:35 +00:00
|
|
|
$emergencyDisableThreshold = AbuseFilter::getEmergencyValue(
|
|
|
|
$wgAbuseFilterEmergencyDisableThreshold,
|
|
|
|
$row->af_group
|
|
|
|
);
|
2012-10-23 13:14:34 +00:00
|
|
|
|
|
|
|
$threshold_percent = sprintf( '%.2f', $emergencyDisableThreshold * 100 );
|
2011-11-16 05:34:24 +00:00
|
|
|
$flags .= $out->parse(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-throttled' )->numParams( $threshold_percent )->text()
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $checkboxes as $checkboxId ) {
|
2012-09-04 08:37:12 +00:00
|
|
|
// Messages that can be used here:
|
|
|
|
// * abusefilter-edit-enabled
|
|
|
|
// * abusefilter-edit-deleted
|
|
|
|
// * abusefilter-edit-hidden
|
|
|
|
// * abusefilter-edit-global
|
2009-01-23 19:23:19 +00:00
|
|
|
$message = "abusefilter-edit-$checkboxId";
|
|
|
|
$dbField = "af_$checkboxId";
|
2009-10-07 13:57:06 +00:00
|
|
|
$postVar = 'wpFilter' . ucfirst( $checkboxId );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2012-09-12 15:31:24 +00:00
|
|
|
if ( $checkboxId == 'global' && !$this->canEditGlobal() ) {
|
|
|
|
$cbReadOnlyAttrib['disabled'] = 'disabled';
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( $message )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$postVar,
|
|
|
|
$postVar,
|
2009-04-01 04:34:21 +00:00
|
|
|
isset( $row->$dbField ) ? $row->$dbField : false,
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$checkbox = Xml::tags( 'p', null, $checkbox );
|
|
|
|
$flags .= $checkbox;
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$fields['abusefilter-edit-flags'] = $flags;
|
2009-01-30 19:30:51 +00:00
|
|
|
$tools = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( $filter != 'new' && $user->isAllowed( 'abusefilter-revert' ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
2012-03-11 20:51:54 +00:00
|
|
|
Linker::link(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->getTitle( 'revert/' . $filter ),
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-revert' )->text()
|
2009-10-07 13:57:06 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:10:35 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter != 'new' ) {
|
2009-01-30 19:30:51 +00:00
|
|
|
// Test link
|
2009-10-07 13:57:06 +00:00
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
2012-03-11 20:51:54 +00:00
|
|
|
Linker::link(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->getTitle( "test/$filter" ),
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-test-link' )->parse()
|
2010-02-13 14:10:36 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
// Last modification details
|
2009-10-07 13:57:06 +00:00
|
|
|
$userLink =
|
2013-06-26 22:58:36 +00:00
|
|
|
Linker::userLink( $row->af_user, $row->af_user_text ) .
|
|
|
|
Linker::userToolLinks( $row->af_user, $row->af_user_text );
|
|
|
|
$userName = $row->af_user_text;
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-lastmod'] =
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-lastmod-text' )
|
|
|
|
->rawParams(
|
|
|
|
$lang->timeanddate( $row->af_timestamp, true ),
|
|
|
|
$userLink,
|
|
|
|
$lang->date( $row->af_timestamp, true ),
|
|
|
|
$lang->time( $row->af_timestamp, true ),
|
|
|
|
$userName
|
|
|
|
)->parse();
|
|
|
|
$history_display = $this->msg( 'abusefilter-edit-viewhistory' )->parse();
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-history'] =
|
2012-09-02 11:07:02 +00:00
|
|
|
Linker::linkKnown( $this->getTitle( 'history/' . $filter ), $history_display );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Add export
|
2014-02-27 16:38:07 +00:00
|
|
|
$exportText = FormatJson::encode( array( 'row' => $row, 'actions' => $actions ) );
|
2011-08-26 20:12:34 +00:00
|
|
|
$tools .= Xml::tags( 'a', array( 'href' => '#', 'id' => 'mw-abusefilter-export-link' ),
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-export' )->parse() );
|
2009-04-23 04:23:56 +00:00
|
|
|
$tools .= Xml::element( 'textarea',
|
2009-10-07 13:57:06 +00:00
|
|
|
array( 'readonly' => 'readonly', 'id' => 'mw-abusefilter-export' ),
|
|
|
|
$exportText
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$fields['abusefilter-edit-tools'] = $tools;
|
2009-01-30 19:30:51 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$form = Xml::buildForm( $fields );
|
2012-09-02 11:07:02 +00:00
|
|
|
$form = Xml::fieldset( $this->msg( 'abusefilter-edit-main' )->text(), $form );
|
2009-10-07 13:57:06 +00:00
|
|
|
$form .= Xml::fieldset(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-consequences' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildConsequenceEditor( $row, $actions )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( $this->canEditFilter( $row ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$form .= Xml::submitButton(
|
|
|
|
$this->msg( 'abusefilter-edit-save' )->text(),
|
|
|
|
array( 'accesskey' => 's' )
|
|
|
|
);
|
2010-10-29 15:32:44 +00:00
|
|
|
$form .= Html::hidden(
|
2010-02-13 14:10:36 +00:00
|
|
|
'wpEditToken',
|
2011-11-16 05:34:24 +00:00
|
|
|
$user->getEditToken( array( 'abusefilter', $filter ) )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$form = Xml::tags( 'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( $filter )->getFullURL(),
|
|
|
|
'method' => 'post'
|
|
|
|
),
|
|
|
|
$form
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$output .= $form;
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Builds the "actions" editor for a given filter.
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $row stdClass A row from the abuse_filter table.
|
2012-05-06 05:59:35 +00:00
|
|
|
* @param $actions Array of rows from the abuse_filter_action table
|
|
|
|
* corresponding to the abuse filter held in $row.
|
|
|
|
* @return HTML text for an action editor.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2009-01-23 19:23:19 +00:00
|
|
|
function buildConsequenceEditor( $row, $actions ) {
|
2016-06-03 18:01:56 +00:00
|
|
|
global $wgAbuseFilterActions;
|
|
|
|
|
|
|
|
$enabledActions = array_filter( $wgAbuseFilterActions );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$setActions = array();
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( $enabledActions as $action => $_ ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$setActions[$action] = array_key_exists( $action, $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( $enabledActions as $action => $_ ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
MediaWiki\suppressWarnings();
|
|
|
|
$params = $actions[$action]['parameters'];
|
|
|
|
MediaWiki\restoreWarnings();
|
2010-02-13 14:10:36 +00:00
|
|
|
$output .= $this->buildConsequenceSelector(
|
2015-09-28 18:03:35 +00:00
|
|
|
$action, $setActions[$action], $params, $row );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $action string The action to build an editor for
|
|
|
|
* @param $set bool Whether or not the action is activated
|
|
|
|
* @param $parameters array Action parameters
|
|
|
|
* @param $row stdClass abuse_filter row object
|
2012-06-06 05:18:31 +00:00
|
|
|
* @return string
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2012-06-06 05:18:31 +00:00
|
|
|
function buildConsequenceSelector( $action, $set, $parameters, $row ) {
|
2016-06-03 18:01:56 +00:00
|
|
|
global $wgAbuseFilterActions, $wgMainCacheType;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2016-06-03 18:01:56 +00:00
|
|
|
if ( empty( $wgAbuseFilterActions[$action] ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
return '';
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib = array();
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib = array(); // For checkboxes
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $row ) ) {
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib['disabled'] = 'disabled';
|
2009-04-01 04:34:21 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $action ) {
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'throttle':
|
2013-10-28 05:47:14 +00:00
|
|
|
// Throttling is only available via object caching
|
|
|
|
if ( $wgMainCacheType === CACHE_NONE ) {
|
|
|
|
return '';
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleSettings = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-throttle' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterActionThrottle',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2015-09-28 18:03:35 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib );
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleFields = array();
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $set ) {
|
2009-01-23 19:23:44 +00:00
|
|
|
array_shift( $parameters );
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleRate = explode( ',', $parameters[0] );
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleCount = $throttleRate[0];
|
|
|
|
$throttlePeriod = $throttleRate[1];
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleGroups = implode( "\n", array_slice( $parameters, 1 ) );
|
2009-01-23 19:23:44 +00:00
|
|
|
} else {
|
|
|
|
$throttleCount = 3;
|
|
|
|
$throttlePeriod = 60;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleGroups = "user\n";
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-count'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::input( 'wpFilterThrottleCount', 20, $throttleCount, $readOnlyAttrib );
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-period'] =
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-throttle-seconds' )
|
|
|
|
->rawParams( Xml::input( 'wpFilterThrottlePeriod', 20, $throttlePeriod,
|
|
|
|
$readOnlyAttrib )
|
|
|
|
)->parse();
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-groups'] =
|
|
|
|
Xml::textarea( 'wpFilterThrottleGroups', $throttleGroups . "\n",
|
2009-04-01 04:34:21 +00:00
|
|
|
40, 5, $readOnlyAttrib );
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleSettings .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-throttle-parameters' ),
|
|
|
|
Xml::buildForm( $throttleFields )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:40:15 +00:00
|
|
|
return $throttleSettings;
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'flag':
|
2010-02-13 14:10:36 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-flag' )->text(),
|
2010-02-13 14:10:36 +00:00
|
|
|
'wpFilterActionFlag',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
true,
|
2009-02-07 09:34:11 +00:00
|
|
|
array( 'disabled' => '1', 'class' => 'mw-abusefilter-action-checkbox' ) );
|
2009-01-23 19:23:44 +00:00
|
|
|
return Xml::tags( 'p', null, $checkbox );
|
|
|
|
case 'warn':
|
2012-06-06 05:18:31 +00:00
|
|
|
global $wgAbuseFilterDefaultWarningMessage;
|
2009-01-23 19:23:44 +00:00
|
|
|
$output = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-warn' )->text(),
|
2010-02-13 14:10:36 +00:00
|
|
|
'wpFilterActionWarn',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2009-07-03 13:54:08 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib );
|
2009-01-23 19:23:44 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
2012-06-06 05:18:31 +00:00
|
|
|
if ( $set ) {
|
|
|
|
$warnMsg = $parameters[0];
|
|
|
|
} elseif (
|
|
|
|
$row &&
|
2012-09-27 10:10:10 +00:00
|
|
|
isset( $row->af_group ) && $row->af_group &&
|
2015-09-28 18:03:35 +00:00
|
|
|
isset( $wgAbuseFilterDefaultWarningMessage[$row->af_group] )
|
2012-06-06 05:18:31 +00:00
|
|
|
) {
|
|
|
|
$warnMsg = $wgAbuseFilterDefaultWarningMessage[$row->af_group];
|
|
|
|
} else {
|
|
|
|
$warnMsg = 'abusefilter-warning';
|
|
|
|
}
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-message'] =
|
2009-02-07 09:34:11 +00:00
|
|
|
$this->getExistingSelector( $warnMsg );
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-other-label'] =
|
2010-02-13 14:10:36 +00:00
|
|
|
Xml::input(
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterWarnMessageOther',
|
|
|
|
45,
|
2014-10-04 14:53:20 +00:00
|
|
|
$warnMsg,
|
2009-07-03 13:54:08 +00:00
|
|
|
array( 'id' => 'mw-abusefilter-warn-message-other' ) + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$previewButton = Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-preview-button',
|
2012-09-02 11:07:02 +00:00
|
|
|
'value' => $this->msg( 'abusefilter-edit-warn-preview' )->text()
|
2009-07-27 10:48:07 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$editButton = Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-edit-button',
|
2012-09-02 11:07:02 +00:00
|
|
|
'value' => $this->msg( 'abusefilter-edit-warn-edit' )->text()
|
2009-07-27 10:48:07 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$previewHolder = Xml::element(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-warn-preview' ), ''
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-actions'] =
|
2009-02-07 09:34:11 +00:00
|
|
|
Xml::tags( 'p', null, "$previewButton $editButton" ) . "\n$previewHolder";
|
2009-10-07 13:57:06 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-warn-parameters' ),
|
|
|
|
Xml::buildForm( $warnFields )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
2009-01-28 19:08:18 +00:00
|
|
|
case 'tag':
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $set ) {
|
2009-01-28 19:08:18 +00:00
|
|
|
$tags = $parameters;
|
|
|
|
} else {
|
|
|
|
$tags = array();
|
|
|
|
}
|
|
|
|
$output = '';
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-tag' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterActionTag',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$tagFields['abusefilter-edit-tag-tag'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::textarea( 'wpFilterTags', implode( "\n", $tags ), 40, 5, $readOnlyAttrib );
|
2009-10-07 13:57:06 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags( 'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-tag-parameters' ),
|
|
|
|
Xml::buildForm( $tagFields )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
return $output;
|
2009-01-23 19:23:44 +00:00
|
|
|
default:
|
2013-03-07 00:04:39 +00:00
|
|
|
// Give grep a chance to find the usages:
|
|
|
|
// abusefilter-edit-action-warn, abusefilter-edit-action-disallow
|
|
|
|
// abusefilter-edit-action-flag, abusefilter-edit-action-blockautopromote
|
|
|
|
// abusefilter-edit-action-degroup, abusefilter-edit-action-block
|
|
|
|
// abusefilter-edit-action-throttle, abusefilter-edit-action-rangeblock
|
|
|
|
// abusefilter-edit-action-tag
|
2009-10-07 13:57:06 +00:00
|
|
|
$message = 'abusefilter-edit-action-' . $action;
|
|
|
|
$form_field = 'wpFilterAction' . ucfirst( $action );
|
2009-01-23 19:23:44 +00:00
|
|
|
$status = $set;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$thisAction = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( $message )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$form_field,
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$status,
|
2009-07-03 13:54:08 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
$thisAction = Xml::tags( 'p', null, $thisAction );
|
|
|
|
return $thisAction;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
|
|
|
* @param $warnMsg
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-02-03 22:45:42 +00:00
|
|
|
function getExistingSelector( $warnMsg ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$existingSelector = new XmlSelect(
|
|
|
|
'wpFilterWarnMessage',
|
|
|
|
'mw-abusefilter-warn-message-existing',
|
|
|
|
$warnMsg == 'abusefilter-warning' ? 'abusefilter-warning' : 'other'
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
// Find other messages.
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'page',
|
|
|
|
array( 'page_title' ),
|
|
|
|
array(
|
|
|
|
'page_namespace' => 8,
|
|
|
|
'page_title LIKE ' . $dbr->addQuotes( 'Abusefilter-warning%' )
|
|
|
|
),
|
|
|
|
__METHOD__
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
$existingSelector->addOption( 'abusefilter-warning' );
|
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2015-09-28 18:03:35 +00:00
|
|
|
foreach ( $res as $row ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( $lang->lcfirst( $row->page_title ) == $lang->lcfirst( $warnMsg ) ) {
|
|
|
|
$existingSelector->setDefault( $lang->lcfirst( $warnMsg ) );
|
2009-02-03 22:45:42 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $row->page_title != 'Abusefilter-warning' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$existingSelector->addOption( $lang->lcfirst( $row->page_title ) );
|
2009-02-03 22:45:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$existingSelector->addOption( $this->msg( 'abusefilter-edit-warn-other' )->text(), 'other' );
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
return $existingSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Loads filter data from the database by ID.
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $id int The filter's ID number
|
2012-05-06 05:59:35 +00:00
|
|
|
* @return array|null Either an associative array representing the filter,
|
|
|
|
* or NULL if the filter does not exist.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2009-01-23 19:23:19 +00:00
|
|
|
function loadFilterData( $id ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $id == 'new' ) {
|
2009-01-25 04:55:02 +00:00
|
|
|
$obj = new stdClass;
|
|
|
|
$obj->af_pattern = '';
|
|
|
|
$obj->af_enabled = 1;
|
|
|
|
$obj->af_hidden = 0;
|
2009-03-30 06:12:12 +00:00
|
|
|
$obj->af_global = 0;
|
2014-05-27 13:01:34 +00:00
|
|
|
$obj->af_throttled = 0;
|
2009-01-25 04:55:02 +00:00
|
|
|
return array( $obj, array() );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 11:50:26 +00:00
|
|
|
// Load from master to avoid unintended reversions where there's replication lag.
|
2016-04-28 20:50:08 +00:00
|
|
|
$dbr = $this->getRequest()->wasPosted()
|
|
|
|
? wfGetDB( DB_MASTER )
|
|
|
|
: wfGetDB( DB_SLAVE );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-06-17 11:50:26 +00:00
|
|
|
// Load certain fields only. This prevents a condition seen on Wikimedia where
|
2009-10-07 13:57:06 +00:00
|
|
|
// a schema change adding a new field caused that extra field to be selected.
|
|
|
|
// Since the selected row may be inserted back into the database, this will cause
|
|
|
|
// an SQL error if, say, one server has the updated schema but another does not.
|
2009-06-17 11:50:26 +00:00
|
|
|
$loadFields = array(
|
|
|
|
'af_id',
|
|
|
|
'af_pattern',
|
|
|
|
'af_user',
|
|
|
|
'af_user_text',
|
|
|
|
'af_timestamp',
|
|
|
|
'af_enabled',
|
|
|
|
'af_comments',
|
|
|
|
'af_public_comments',
|
|
|
|
'af_hidden',
|
|
|
|
'af_hit_count',
|
|
|
|
'af_throttled',
|
|
|
|
'af_deleted',
|
|
|
|
'af_actions',
|
|
|
|
'af_global',
|
2012-05-06 06:44:45 +00:00
|
|
|
'af_group',
|
2009-06-17 11:50:26 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load the main row
|
2009-06-17 11:50:26 +00:00
|
|
|
$row = $dbr->selectRow( 'abuse_filter', $loadFields, array( 'af_id' => $id ), __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !isset( $row ) || !isset( $row->af_id ) || !$row->af_id ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return null;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load the actions
|
|
|
|
$actions = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $dbr->select( 'abuse_filter_action',
|
|
|
|
'*',
|
|
|
|
array( 'afa_filter' => $id ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2015-09-28 18:03:35 +00:00
|
|
|
|
|
|
|
foreach ( $res as $actionRow ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$thisAction = array();
|
|
|
|
$thisAction['action'] = $actionRow->afa_consequence;
|
|
|
|
$thisAction['parameters'] = explode( "\n", $actionRow->afa_parameters );
|
|
|
|
|
|
|
|
$actions[$actionRow->afa_consequence] = $thisAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array( $row, $actions );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Load filter data to show in the edit view.
|
|
|
|
* Either from the HTTP request or from the filter/history_id given.
|
|
|
|
* The HTTP request always takes precedence.
|
|
|
|
* Includes caching.
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $filter int The filter ID being requested.
|
|
|
|
* @param $history_id int If any, the history ID being requested.
|
2012-05-06 05:59:35 +00:00
|
|
|
* @return Array with filter data if available, otherwise null.
|
|
|
|
* The first element contains the abuse_filter database row,
|
|
|
|
* the second element is an array of related abuse_filter_action rows.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2009-01-23 19:23:19 +00:00
|
|
|
function loadRequest( $filter, $history_id = null ) {
|
|
|
|
static $row = null;
|
|
|
|
static $actions = null;
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !is_null( $actions ) && !is_null( $row ) ) {
|
|
|
|
return array( $row, $actions );
|
2011-11-16 05:34:24 +00:00
|
|
|
} elseif ( $request->wasPosted() ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
# Nothing, we do it all later
|
2009-01-23 19:23:19 +00:00
|
|
|
} elseif ( $history_id ) {
|
|
|
|
return $this->loadHistoryItem( $history_id );
|
|
|
|
} else {
|
|
|
|
return $this->loadFilterData( $filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need some details like last editor
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $row, $origActions ) = $this->loadFilterData( $filter );
|
2009-01-26 22:30:42 +00:00
|
|
|
|
|
|
|
$row->mOriginalRow = clone $row;
|
|
|
|
$row->mOriginalActions = $origActions;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Check for importing
|
2011-11-16 05:34:24 +00:00
|
|
|
$import = $request->getVal( 'wpImportText' );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $import ) {
|
2014-02-27 16:38:07 +00:00
|
|
|
$data = FormatJson::decode( $import );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-06-02 12:59:05 +00:00
|
|
|
$importRow = $data->row;
|
|
|
|
$actions = wfObjectToArray( $data->actions );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$copy = array(
|
2009-10-07 13:57:06 +00:00
|
|
|
'af_public_comments',
|
|
|
|
'af_pattern',
|
|
|
|
'af_comments',
|
|
|
|
'af_deleted',
|
|
|
|
'af_enabled',
|
|
|
|
'af_hidden',
|
|
|
|
);
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $copy as $name ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
$row->$name = $importRow->$name;
|
|
|
|
}
|
|
|
|
} else {
|
2009-10-07 13:57:06 +00:00
|
|
|
$textLoads = array(
|
|
|
|
'af_public_comments' => 'wpFilterDescription',
|
|
|
|
'af_pattern' => 'wpFilterRules',
|
2012-05-06 06:44:45 +00:00
|
|
|
'af_comments' => 'wpFilterNotes',
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $textLoads as $col => $field ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$row->$col = trim( $request->getVal( $field ) );
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-05-06 06:44:45 +00:00
|
|
|
$row->af_group = $request->getVal( 'wpFilterGroup', 'default' );
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$row->af_deleted = $request->getBool( 'wpFilterDeleted' );
|
|
|
|
$row->af_enabled = $request->getBool( 'wpFilterEnabled' ) && !$row->af_deleted;
|
|
|
|
$row->af_hidden = $request->getBool( 'wpFilterHidden' );
|
2009-04-23 04:23:56 +00:00
|
|
|
global $wgAbuseFilterIsCentral;
|
2011-11-16 05:34:24 +00:00
|
|
|
$row->af_global = $request->getBool( 'wpFilterGlobal' ) && $wgAbuseFilterIsCentral;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Actions
|
2016-06-03 18:01:56 +00:00
|
|
|
global $wgAbuseFilterActions;
|
2009-04-23 04:23:56 +00:00
|
|
|
$actions = array();
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( array_filter( $wgAbuseFilterActions ) as $action => $_ ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
// Check if it's set
|
2011-11-16 05:34:24 +00:00
|
|
|
$enabled = $request->getBool( 'wpFilterAction' . ucfirst( $action ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $enabled ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
$parameters = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $action == 'throttle' ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
// We need to load the parameters
|
2011-11-16 05:34:24 +00:00
|
|
|
$throttleCount = $request->getIntOrNull( 'wpFilterThrottleCount' );
|
|
|
|
$throttlePeriod = $request->getIntOrNull( 'wpFilterThrottlePeriod' );
|
2010-02-13 14:10:36 +00:00
|
|
|
$throttleGroups = explode( "\n",
|
2011-11-16 05:34:24 +00:00
|
|
|
trim( $request->getText( 'wpFilterThrottleGroups' ) ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$parameters[0] = $this->mFilter; // For now, anyway
|
|
|
|
$parameters[1] = "$throttleCount,$throttlePeriod";
|
|
|
|
$parameters = array_merge( $parameters, $throttleGroups );
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( $action == 'warn' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessage' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-01-06 20:17:41 +00:00
|
|
|
if ( $specMsg == 'other' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessageOther' );
|
2016-01-06 20:17:41 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$parameters[0] = $specMsg;
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( $action == 'tag' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$parameters = explode( "\n", $request->getText( 'wpFilterTags' ) );
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$thisAction = array( 'action' => $action, 'parameters' => $parameters );
|
|
|
|
$actions[$action] = $thisAction;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-27 18:32:17 +00:00
|
|
|
$row->af_actions = implode( ',', array_keys( array_filter( $actions ) ) );
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
return array( $row, $actions );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Loads historical data in a form that the editor can understand.
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $id int History ID
|
2016-04-02 22:11:29 +00:00
|
|
|
* @return array|bool False if the history ID is not valid, otherwise array in the usual format:
|
2012-05-06 05:59:35 +00:00
|
|
|
* First element contains the abuse_filter row (as it was).
|
|
|
|
* Second element contains an array of abuse_filter_action rows.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2009-01-23 19:23:19 +00:00
|
|
|
function loadHistoryItem( $id ) {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
// Load the row.
|
2009-10-07 13:57:06 +00:00
|
|
|
$row = $dbr->selectRow( 'abuse_filter_history',
|
|
|
|
'*',
|
|
|
|
array( 'afh_id' => $id ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2016-04-02 22:11:29 +00:00
|
|
|
if ( !$row ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
return AbuseFilter::translateFromHistory( $row );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2012-06-06 05:18:31 +00:00
|
|
|
|
|
|
|
protected function exposeWarningMessages() {
|
|
|
|
global $wgOut, $wgAbuseFilterDefaultWarningMessage;
|
2015-09-28 18:03:35 +00:00
|
|
|
$wgOut->addJsConfigVars(
|
|
|
|
'wgAbuseFilterDefaultWarningMessage',
|
|
|
|
$wgAbuseFilterDefaultWarningMessage
|
|
|
|
);
|
2012-06-06 05:18:31 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|