2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
|
|
|
* @param SpecialPage $page
|
|
|
|
* @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();
|
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-02-08 01:02:11 +00:00
|
|
|
$origActions = $newRow->mOriginalActions;
|
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
|
|
|
|
global $wgAbuseFilterRestrictedActions;
|
2012-02-08 01:02:11 +00:00
|
|
|
$allActions = array_keys( array_merge(
|
|
|
|
array_filter( $actions ),
|
|
|
|
array_filter( $origActions )
|
|
|
|
) );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if (
|
2012-02-08 01:02:11 +00:00
|
|
|
count( array_intersect(
|
|
|
|
$wgAbuseFilterRestrictedActions,
|
|
|
|
$allActions
|
|
|
|
) )
|
|
|
|
&& !$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
|
|
|
|
2012-02-29 15:36:10 +00:00
|
|
|
$dbw->begin( __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.
|
|
|
|
|
|
|
|
$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
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
|
|
|
$deadActions = array();
|
|
|
|
$actionsRows = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $wgAbuseFilterAvailableActions 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__ );
|
|
|
|
|
2012-02-29 15:36:10 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-08-03 21:55:35 +00:00
|
|
|
// Reset Memcache if this was a global rule
|
|
|
|
if ( $newRow['af_global'] ) {
|
|
|
|
global $wgMemc;
|
|
|
|
$group = 'default';
|
|
|
|
if ( isset( $newRow['af_group'] ) && $newRow['af_group'] != '' ) {
|
|
|
|
$group = $newRow['af_group'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$memcacheRules = array();
|
|
|
|
$res = $dbw->select(
|
|
|
|
'abuse_filter',
|
|
|
|
'*',
|
|
|
|
array(
|
|
|
|
'af_enabled' => 1,
|
|
|
|
'af_deleted' => 0,
|
|
|
|
'af_global' => 1,
|
|
|
|
'af_group' => $group,
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$memcacheRules[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgMemc->set( AbuseFilter::getGlobalRulesKey( $group ), $memcacheRules );
|
|
|
|
}
|
|
|
|
|
2009-03-11 07:12:42 +00:00
|
|
|
// Logging
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-03 12:48:28 +00:00
|
|
|
$lp = new LogPage( 'abusefilter' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-03 12:48:28 +00:00
|
|
|
$lp->addEntry( 'modify', $this->getTitle( $new_id ), '', array( $history_id, $new_id ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-30 23:24:29 +00:00
|
|
|
// Special-case stuff for tags -- purge the tag list cache.
|
|
|
|
if ( isset( $actions['tag'] ) ) {
|
|
|
|
global $wgMemc;
|
|
|
|
$wgMemc->delete( wfMemcKey( 'valid-tags' ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-19 02:40:48 +00:00
|
|
|
AbuseFilter::resetFilterProfile( $new_id );
|
2009-01-30 23:24:29 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->redirect(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->getTitle()->getLocalURL( 'result=success&changedfilter=' . $new_id ) );
|
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
|
|
|
|
* @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-09-02 11:07:02 +00:00
|
|
|
$out->setSubtitle( $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
|
|
|
|
|
|
|
if ( !$this->canEdit() ) {
|
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'] =
|
2012-09-02 11:07:02 +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;
|
|
|
|
if ( count($wgAbuseFilterValidGroups) > 1 ) {
|
|
|
|
$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 ) {
|
2012-05-06 06:44:45 +00:00
|
|
|
$groupSelector->setDefault($row->af_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $wgAbuseFilterValidGroups as $group ) {
|
|
|
|
$groupSelector->addOption( AbuseFilter::nameGroup($group), $group );
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
2011-11-16 05:34:24 +00:00
|
|
|
global $wgMemc;
|
2009-01-23 19:23:19 +00:00
|
|
|
$matches_count = $wgMemc->get( AbuseFilter::filterMatchesKey( $filter ) );
|
|
|
|
$total = $wgMemc->get( AbuseFilter::filterUsedKey() );
|
|
|
|
|
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 );
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' )
|
|
|
|
->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile )
|
|
|
|
->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,
|
|
|
|
$this->canEdit()
|
|
|
|
);
|
|
|
|
$fields['abusefilter-edit-notes'] = Xml::textarea(
|
|
|
|
'wpFilterNotes',
|
|
|
|
( isset( $row->af_comments ) ? $row->af_comments . "\n" : "\n" ),
|
|
|
|
40, 5,
|
|
|
|
$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
|
|
|
|
$emergencyDisableThreshold = AbuseFilter::getEmergencyValue( $wgAbuseFilterEmergencyDisableThreshold, $row->af_group );
|
|
|
|
|
|
|
|
$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
|
|
|
|
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 =
|
2012-03-11 20:51:54 +00:00
|
|
|
Linker::userLink( $row->af_user, $row->af_user_text ) .
|
|
|
|
Linker::userToolLinks( $row->af_user, $row->af_user_text );
|
2011-11-27 08:58:46 +00:00
|
|
|
$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
|
2009-06-02 12:59:05 +00:00
|
|
|
$exportText = json_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
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->canEdit() ) {
|
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 ) {
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$setActions = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$setActions[$action] = array_key_exists( $action, $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
|
|
|
$output .= $this->buildConsequenceSelector(
|
2012-06-06 05:18:31 +00:00
|
|
|
$action, $setActions[$action], @$actions[$action]['parameters'], $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 ) {
|
2009-01-23 19:23:44 +00:00
|
|
|
global $wgAbuseFilterAvailableActions;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
if ( !in_array( $action, $wgAbuseFilterAvailableActions ) ) {
|
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
|
|
|
|
|
|
|
if ( !$this->canEdit() ) {
|
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
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
switch( $action ) {
|
|
|
|
case 'throttle':
|
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,
|
2009-07-03 13:54:08 +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 &&
|
2012-06-06 05:18:31 +00:00
|
|
|
isset($wgAbuseFilterDefaultWarningMessage[$row->af_group] )
|
|
|
|
) {
|
|
|
|
$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,
|
|
|
|
$warnMsg ? $warnMsg : 'abusefilter-warning-',
|
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:
|
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();
|
2010-08-19 21:12:09 +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;
|
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.
|
|
|
|
$dbr = wfGetDB( DB_MASTER );
|
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__
|
|
|
|
);
|
2010-08-19 21:12:09 +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 ) {
|
|
|
|
$data = json_decode( $import );
|
|
|
|
|
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
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
|
|
|
$actions = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $wgAbuseFilterAvailableActions 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
|
|
|
|
|
|
|
if ( $specMsg == 'other' )
|
2011-11-16 05:34:24 +00:00
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessageOther' );
|
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
|
2012-05-06 05:59:35 +00:00
|
|
|
* @return array In the usual format:
|
|
|
|
* 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
|
|
|
|
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;
|
|
|
|
$wgOut->addJsConfigVars( 'wgAbuseFilterDefaultWarningMessage', $wgAbuseFilterDefaultWarningMessage );
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|