2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
die();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
|
|
|
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
|
|
|
|
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(
|
2009-10-07 13:57:06 +00:00
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-edit-badsyntax',
|
|
|
|
array( 'parse' ),
|
|
|
|
array( $syntaxerr[0] )
|
|
|
|
),
|
|
|
|
$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(
|
|
|
|
wfMsgExt( 'abusefilter-edit-restricted', 'parse' ),
|
|
|
|
$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(
|
|
|
|
wfMsgExt( 'abusefilter-edit-bad-tags', 'parse' ),
|
|
|
|
$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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @param $error
|
|
|
|
* @param $filter
|
|
|
|
* @param $history_id null
|
|
|
|
* @return bool|String
|
|
|
|
*/
|
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-03-11 20:51:54 +00:00
|
|
|
$out->addHTML( Linker::link( $this->getTitle(), wfMsg( 'abusefilter-return' ) ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->setSubtitle( wfMsg( 'abusefilter-edit-subtitle', $filter, $history_id ) );
|
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() ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return wfMsg( 'abusefilter-edit-denied' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$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'] =
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->mFilter == 'new' ? wfMsg( 'abusefilter-edit-new' ) : $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',
|
|
|
|
'mw-abusefilter-edit-group',
|
|
|
|
'default'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $row->af_group ) {
|
|
|
|
$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 ) ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$count = (int)$row->af_hit_count;
|
|
|
|
$count_display = wfMsgExt( 'abusefilter-hitcount', array( 'parseinline' ),
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->formatNum( $count )
|
2009-01-23 19:23:19 +00:00
|
|
|
);
|
2012-03-11 20:51:54 +00:00
|
|
|
$hitCount = Linker::makeKnownLinkObj(
|
2009-10-07 13:57:06 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$count_display,
|
|
|
|
'wpSearchFilter=' . $row->af_id
|
|
|
|
);
|
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() );
|
|
|
|
|
2011-11-16 05:34:24 +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 );
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$fields['abusefilter-edit-status-label'] =
|
|
|
|
wfMsgExt( 'abusefilter-edit-status', array( 'parsemag', 'escape' ),
|
2009-10-07 13:57:06 +00:00
|
|
|
array(
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->formatNum( $total ),
|
|
|
|
$lang->formatNum( $matches_count ),
|
|
|
|
$lang->formatNum( $matches_percent ),
|
|
|
|
$lang->formatNum( $timeProfile ),
|
|
|
|
$lang->formatNum( $condProfile )
|
2009-07-03 13:46:51 +00:00
|
|
|
)
|
2009-01-23 19:23:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
$fields['abusefilter-edit-rules'] =
|
2009-10-07 13:57:06 +00:00
|
|
|
AbuseFilter::buildEditBox( $row->af_pattern, 'wpFilterRules', true,
|
2009-04-01 04:34:21 +00:00
|
|
|
$this->canEdit() );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-notes'] =
|
|
|
|
Xml::textarea(
|
|
|
|
'wpFilterNotes',
|
|
|
|
( isset( $row->af_comments ) ? $row->af_comments . "\n" : "\n" ),
|
2009-04-01 04:34:21 +00:00
|
|
|
40, 5,
|
|
|
|
$readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
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;
|
|
|
|
$threshold_percent = sprintf( '%.2f', $wgAbuseFilterEmergencyDisableThreshold * 100 );
|
2011-11-16 05:34:24 +00:00
|
|
|
$flags .= $out->parse(
|
2009-10-07 13:57:06 +00:00
|
|
|
wfMsg(
|
|
|
|
'abusefilter-edit-throttled',
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->formatNum( $threshold_percent )
|
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 ) {
|
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(
|
|
|
|
wfMsg( $message ),
|
|
|
|
$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 ),
|
|
|
|
wfMsg( 'abusefilter-edit-revert' )
|
|
|
|
)
|
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" ),
|
|
|
|
wfMsgExt( 'abusefilter-edit-test-link', 'parseinline' )
|
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'] =
|
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-edit-lastmod-text',
|
|
|
|
array( 'parseinline', 'replaceafter' ),
|
2011-11-16 05:34:24 +00:00
|
|
|
array( $lang->timeanddate( $row->af_timestamp, true ),
|
2009-10-07 13:57:06 +00:00
|
|
|
$userLink,
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->date( $row->af_timestamp, true ),
|
|
|
|
$lang->time( $row->af_timestamp, true ),
|
2011-11-27 08:58:46 +00:00
|
|
|
$userName
|
2010-02-13 14:10:36 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$history_display = wfMsgExt( 'abusefilter-edit-viewhistory', array( 'parseinline' ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-history'] =
|
2012-03-11 20:51:54 +00:00
|
|
|
Linker::makeKnownLinkObj( $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' ),
|
2009-04-23 04:23:56 +00:00
|
|
|
wfMsgExt( 'abusefilter-edit-export', 'parseinline' ) );
|
|
|
|
$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 );
|
|
|
|
$form = Xml::fieldset( wfMsg( 'abusefilter-edit-main' ), $form );
|
2009-10-07 13:57:06 +00:00
|
|
|
$form .= Xml::fieldset(
|
|
|
|
wfMsg( 'abusefilter-edit-consequences' ),
|
|
|
|
$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() ) {
|
2010-03-13 17:35:12 +00:00
|
|
|
$form .= Xml::submitButton( wfMsg( 'abusefilter-edit-save' ), 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
|
|
|
/**
|
|
|
|
* @param $row
|
|
|
|
* @param $actions
|
|
|
|
* @return string
|
|
|
|
*/
|
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(
|
2009-02-07 09:34:11 +00:00
|
|
|
$action, $setActions[$action], @$actions[$action]['parameters'] );
|
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
|
|
|
/**
|
|
|
|
* @param $action
|
|
|
|
* @param $set
|
|
|
|
* @param $parameters
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-01-23 19:23:44 +00:00
|
|
|
function buildConsequenceSelector( $action, $set, $parameters ) {
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
if ( !in_array( $action, $wgAbuseFilterAvailableActions ) ) {
|
|
|
|
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(
|
|
|
|
wfMsg( 'abusefilter-edit-action-throttle' ),
|
|
|
|
'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'] =
|
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-edit-throttle-seconds',
|
|
|
|
array( 'parseinline', 'replaceafter' ),
|
2009-04-01 04:34:21 +00:00
|
|
|
array(
|
|
|
|
Xml::input( 'wpFilterThrottlePeriod', 20, $throttlePeriod,
|
|
|
|
$readOnlyAttrib
|
2010-02-13 14:10:36 +00:00
|
|
|
) )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
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(
|
|
|
|
wfMsg( 'abusefilter-edit-action-flag' ),
|
|
|
|
'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':
|
|
|
|
$output = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
wfMsg( 'abusefilter-edit-action-warn' ),
|
|
|
|
'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 );
|
2010-02-13 14:10:36 +00:00
|
|
|
$warnMsg = empty( $set ) ? 'abusefilter-warning' : $parameters[0];
|
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',
|
|
|
|
'value' => wfMsg( 'abusefilter-edit-warn-preview' )
|
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',
|
|
|
|
'value' => wfMsg( 'abusefilter-edit-warn-edit' )
|
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(
|
|
|
|
wfMsg( 'abusefilter-edit-action-tag' ),
|
|
|
|
'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(
|
|
|
|
wfMsg( $message ),
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$existingSelector->addOption( wfMsg( 'abusefilter-edit-warn-other' ), 'other' );
|
|
|
|
|
|
|
|
return $existingSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return array|null
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* @param $filter
|
|
|
|
* @param null $history_id
|
|
|
|
* @return array|null
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return array
|
|
|
|
*/
|
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
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|