2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!defined( 'MEDIAWIKI' ))
|
|
|
|
die();
|
|
|
|
|
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
|
|
|
|
|
|
|
function __construct( $page, $params ) {
|
|
|
|
parent::__construct( $page, $params );
|
|
|
|
$this->mFilter = $page->mFilter;
|
|
|
|
$this->mHistoryID = $page->mHistoryID;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show( ) {
|
|
|
|
global $wgRequest, $wgUser, $wgOut;
|
|
|
|
|
|
|
|
$filter = $this->mFilter;
|
|
|
|
$history_id = $this->mHistoryID;
|
|
|
|
$this->mSkin = $wgUser->getSkin();
|
|
|
|
|
|
|
|
$editToken = $wgRequest->getVal( 'wpEditToken' );
|
2009-02-07 09:34:11 +00:00
|
|
|
$didEdit = $this->canEdit()
|
|
|
|
&& $wgUser->matchEditToken( $editToken, array( 'abusefilter', $filter ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
if ($didEdit) {
|
|
|
|
// Check syntax
|
|
|
|
$syntaxerr = AbuseFilter::checkSyntax( $wgRequest->getVal( 'wpFilterRules' ) );
|
|
|
|
if ($syntaxerr !== true ) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->addHTML(
|
|
|
|
$this->buildFilterEditor(
|
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-edit-badsyntax',
|
|
|
|
array( 'parse' ),
|
|
|
|
array( $syntaxerr[0] )
|
|
|
|
),
|
|
|
|
$filter, $history_id
|
|
|
|
)
|
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
list ($newRow, $actions) = $this->loadRequest($filter);
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$differences = AbuseFilter::compareVersions(
|
|
|
|
array($newRow, $actions),
|
|
|
|
array( $newRow->mOriginalRow, $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-01-26 22:30:42 +00:00
|
|
|
if (!count($differences)) {
|
|
|
|
$wgOut->redirect( $this->getTitle()->getLocalURL() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-27 19:51:38 +00:00
|
|
|
// Check for restricted actions
|
|
|
|
global $wgAbuseFilterRestrictedActions;
|
2009-02-07 09:34:11 +00:00
|
|
|
if (
|
|
|
|
array_intersect(
|
|
|
|
$wgAbuseFilterRestrictedActions,
|
|
|
|
array_keys( array_filter( $actions ) ) )
|
|
|
|
&& !$wgUser->isAllowed( 'abusefilter-modify-restricted' ) )
|
|
|
|
{
|
|
|
|
$wgOut->addHTML(
|
|
|
|
$this->buildFilterEditor(
|
|
|
|
wfMsgExt( 'abusefilter-edit-restricted', 'parse' ),
|
|
|
|
$this->mFilter,
|
|
|
|
$history_id
|
|
|
|
)
|
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$newRow = get_object_vars($newRow); // Convert from object to array
|
|
|
|
|
|
|
|
// Set last modifier.
|
|
|
|
$newRow['af_timestamp'] = $dbw->timestamp( wfTimestampNow() );
|
|
|
|
$newRow['af_user'] = $wgUser->getId();
|
|
|
|
$newRow['af_user_text'] = $wgUser->getName();
|
|
|
|
|
|
|
|
$dbw->begin();
|
|
|
|
|
|
|
|
// Insert MAIN row.
|
|
|
|
if ($filter == 'new') {
|
|
|
|
$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__ );
|
|
|
|
|
|
|
|
if ($is_new) {
|
|
|
|
$new_id = $dbw->insertId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
|
|
|
$deadActions = array();
|
|
|
|
$actionsRows = array();
|
|
|
|
foreach( $wgAbuseFilterAvailableActions as $action ) {
|
|
|
|
// Check if it's set
|
|
|
|
$enabled = isset($actions[$action]) && (bool)$actions[$action];
|
|
|
|
|
|
|
|
if ($enabled) {
|
|
|
|
$parameters = $actions[$action]['parameters'];
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$thisRow = array(
|
|
|
|
'afa_filter' => $new_id,
|
|
|
|
'afa_consequence' => $action,
|
|
|
|
'afa_parameters' => implode( "\n", $parameters )
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$actionsRows[] = $thisRow;
|
|
|
|
} else {
|
|
|
|
$deadActions[] = $action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a history row
|
|
|
|
$afh_row = array();
|
|
|
|
|
2009-01-26 22:31:02 +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();
|
|
|
|
foreach( $actions as $action ) {
|
|
|
|
$displayActions[$action['action']] = $action['parameters'];
|
|
|
|
}
|
|
|
|
$afh_row['afh_actions'] = serialize($displayActions);
|
|
|
|
|
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();
|
|
|
|
if ($newRow['af_hidden'])
|
|
|
|
$flags[] = 'hidden';
|
|
|
|
if ($newRow['af_enabled'])
|
|
|
|
$flags[] = 'enabled';
|
|
|
|
if ($newRow['af_deleted'])
|
|
|
|
$flags[] = 'deleted';
|
2009-03-30 06:12:12 +00:00
|
|
|
if ($newRow['af_global'])
|
|
|
|
$flags[] = 'global';
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$afh_row['afh_flags'] = implode( ",", $flags );
|
|
|
|
|
|
|
|
$afh_row['afh_filter'] = $new_id;
|
2009-03-11 07:12:42 +00:00
|
|
|
$afh_row['afh_id'] = $history_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();
|
2009-01-23 19:23:44 +00:00
|
|
|
$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__ );
|
|
|
|
|
|
|
|
$dbw->commit();
|
2009-03-11 07:12:42 +00:00
|
|
|
|
|
|
|
// Logging
|
|
|
|
|
2009-03-17 23:54:56 +00:00
|
|
|
## Broken until logging table is expanded to 32 chars.
|
|
|
|
# $lp = new LogPage( 'abusefilter' );
|
|
|
|
|
|
|
|
# $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-03-19 02:40:48 +00:00
|
|
|
|
|
|
|
AbuseFilter::resetFilterProfile( $new_id );
|
2009-01-30 23:24:29 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->redirect(
|
|
|
|
$this->getTitle()->getLocalURL( 'result=success&changedfilter='.$new_id ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
} else {
|
|
|
|
if ($history_id) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->addWikiMsg(
|
|
|
|
'abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$wgOut->addHTML( $this->buildFilterEditor( null, $this->mFilter, $history_id ) );
|
|
|
|
|
|
|
|
if ($history_id) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->addWikiMsg(
|
|
|
|
'abusefilter-edit-oldwarning', $this->mHistoryID, $this->mFilter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildFilterEditor( $error, $filter, $history_id=null ) {
|
|
|
|
if( $filter === null ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the edit form
|
|
|
|
global $wgOut,$wgLang,$wgUser;
|
|
|
|
$sk = $this->mSkin;
|
|
|
|
|
|
|
|
// Load from request OR database.
|
|
|
|
list ($row, $actions) = $this->loadRequest($filter, $history_id);
|
|
|
|
|
|
|
|
if( !$row ) {
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-edit-badfilter' );
|
|
|
|
$wgOut->addHTML( $sk->link( $this->getTitle(), wfMsg( 'abusefilter-return' ) ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgOut->setSubtitle( wfMsg( 'abusefilter-edit-subtitle', $filter, $history_id ) );
|
|
|
|
|
|
|
|
// Hide hidden filters.
|
|
|
|
if (isset($row->af_hidden) && $row->af_hidden && !$this->canEdit()) {
|
|
|
|
return wfMsg( 'abusefilter-edit-denied' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
if ($error) {
|
|
|
|
$wgOut->addHTML( "<span class=\"error\">$error</span>" );
|
|
|
|
}
|
2009-04-01 04:34:21 +00:00
|
|
|
|
|
|
|
// Read-only attribute
|
|
|
|
$readOnlyAttrib = array();
|
|
|
|
|
|
|
|
if (!$this->canEdit()) {
|
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
|
|
|
$readOnlyAttrib['disabled'] = 'disabled';
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$fields = array();
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$fields['abusefilter-edit-id'] =
|
|
|
|
$this->mFilter == 'new' ? wfMsg( 'abusefilter-edit-new' ) : $filter;
|
|
|
|
$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
|
|
|
|
|
|
|
// Hit count display
|
|
|
|
if( !empty($row->af_hit_count) ){
|
|
|
|
$count = (int)$row->af_hit_count;
|
|
|
|
$count_display = wfMsgExt( 'abusefilter-hitcount', array( 'parseinline' ),
|
|
|
|
$wgLang->formatNum( $count )
|
|
|
|
);
|
2009-02-07 09:34:11 +00:00
|
|
|
$hitCount = $sk->makeKnownLinkObj(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$count_display,
|
|
|
|
'wpSearchFilter='.$row->af_id );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$fields['abusefilter-edit-hitcount'] = $hitCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($filter !== 'new') {
|
|
|
|
// Statistics
|
|
|
|
global $wgMemc, $wgLang;
|
|
|
|
$matches_count = $wgMemc->get( AbuseFilter::filterMatchesKey( $filter ) );
|
|
|
|
$total = $wgMemc->get( AbuseFilter::filterUsedKey() );
|
|
|
|
|
|
|
|
if ($total > 0) {
|
|
|
|
$matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
|
2009-03-19 02:40:48 +00:00
|
|
|
$profile = AbuseFilter::getFilterProfile( $filter );
|
2009-01-23 19:23:19 +00:00
|
|
|
$fields['abusefilter-edit-status-label'] =
|
|
|
|
wfMsgExt( 'abusefilter-edit-status', array( 'parsemag', 'escape' ),
|
|
|
|
$wgLang->formatNum($total),
|
|
|
|
$wgLang->formatNum($matches_count),
|
2009-03-19 02:40:48 +00:00
|
|
|
$wgLang->formatNum($matches_percent),
|
|
|
|
$wgLang->formatNum($profile)
|
2009-01-23 19:23:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
$fields['abusefilter-edit-rules'] =
|
|
|
|
AbuseFilter::buildEditBox($row->af_pattern, 'wpFilterRules', true,
|
|
|
|
$this->canEdit() );
|
2009-02-07 09:34:11 +00:00
|
|
|
$fields['abusefilter-edit-notes'] =
|
|
|
|
Xml::textarea(
|
|
|
|
'wpFilterNotes',
|
2009-04-01 04:34:21 +00:00
|
|
|
( isset( $row->af_comments ) ? $row->af_comments."\n" : "\n" ),
|
|
|
|
40, 5,
|
|
|
|
$readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-30 19:19:03 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Build checkboxen
|
|
|
|
$checkboxes = array( 'hidden', 'enabled', 'deleted' );
|
|
|
|
$flags = '';
|
2009-03-30 06:12:12 +00:00
|
|
|
|
|
|
|
global $wgAbuseFilterIsCentral;
|
|
|
|
if ($wgAbuseFilterIsCentral)
|
|
|
|
$checkboxes[] = 'global';
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
if (isset($row->af_throttled) && $row->af_throttled) {
|
|
|
|
global $wgAbuseFilterEmergencyDisableThreshold;
|
|
|
|
$threshold_percent = sprintf( '%.2f', $wgAbuseFilterEmergencyDisableThreshold * 100 );
|
2009-02-07 09:34:11 +00:00
|
|
|
$flags .= $wgOut->parse(
|
|
|
|
wfMsg(
|
|
|
|
'abusefilter-edit-throttled',
|
|
|
|
$wgLang->formatNum( $threshold_percent )
|
|
|
|
) );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $checkboxes as $checkboxId ) {
|
|
|
|
$message = "abusefilter-edit-$checkboxId";
|
|
|
|
$dbField = "af_$checkboxId";
|
|
|
|
$postVar = "wpFilter".ucfirst($checkboxId);
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
wfMsg( $message ),
|
|
|
|
$postVar,
|
|
|
|
$postVar,
|
2009-04-01 04:34:21 +00:00
|
|
|
isset( $row->$dbField ) ? $row->$dbField : false,
|
|
|
|
$readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$checkbox = Xml::tags( 'p', null, $checkbox );
|
|
|
|
$flags .= $checkbox;
|
|
|
|
}
|
|
|
|
$fields['abusefilter-edit-flags'] = $flags;
|
2009-01-30 19:30:51 +00:00
|
|
|
$tools = '';
|
2009-01-28 19:12:57 +00:00
|
|
|
if ( $filter != 'new' && $wgUser->isAllowed( 'abusefilter-revert' ) ) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
|
|
|
$sk->link(
|
|
|
|
$this->getTitle( 'revert/'.$filter ),
|
|
|
|
wfMsg( 'abusefilter-edit-revert' )
|
|
|
|
)
|
|
|
|
);
|
2009-01-28 00:10:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
if ($filter != 'new') {
|
2009-01-30 19:30:51 +00:00
|
|
|
// Test link
|
2009-02-07 09:34:11 +00:00
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
|
|
|
$sk->link(
|
|
|
|
$this->getTitle( "test/$filter" ),
|
|
|
|
wfMsgExt( 'abusefilter-edit-test-link', 'parseinline' )
|
|
|
|
)
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
// Last modification details
|
2009-02-07 09:34:11 +00:00
|
|
|
$user =
|
|
|
|
$sk->userLink( $row->af_user, $row->af_user_text ) .
|
|
|
|
$sk->userToolLinks( $row->af_user, $row->af_user_text );
|
|
|
|
$fields['abusefilter-edit-lastmod'] =
|
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-edit-lastmod-text',
|
|
|
|
array( 'parseinline', 'replaceafter' ),
|
2009-03-11 18:58:38 +00:00
|
|
|
array( $wgLang->timeanddate( $row->af_timestamp, true ), $user )
|
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-02-07 09:34:11 +00:00
|
|
|
$fields['abusefilter-edit-history'] =
|
|
|
|
$sk->makeKnownLinkObj( $this->getTitle( 'history/'.$filter ), $history_display );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 23:52:08 +00:00
|
|
|
if ($tools) {
|
|
|
|
$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-02-07 09:34:11 +00:00
|
|
|
$form .= Xml::fieldset(
|
|
|
|
wfMsg(
|
|
|
|
'abusefilter-edit-consequences' ),
|
|
|
|
$this->buildConsequenceEditor( $row, $actions )
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
if ($this->canEdit()) {
|
|
|
|
$form .= Xml::submitButton( wfMsg( 'abusefilter-edit-save' ) );
|
2009-02-07 09:34:11 +00:00
|
|
|
$form .= Xml::hidden(
|
|
|
|
'wpEditToken',
|
|
|
|
$wgUser->editToken( array( 'abusefilter', $filter ) )
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 09:34:11 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildConsequenceEditor( $row, $actions ) {
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
|
|
|
$setActions = array();
|
|
|
|
foreach( $wgAbuseFilterAvailableActions as $action ) {
|
|
|
|
$setActions[$action] = array_key_exists( $action, $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
foreach( $wgAbuseFilterAvailableActions as $action ) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$output .= $this->buildConsequenceSelector(
|
|
|
|
$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
|
|
|
|
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-01-23 19:23:44 +00:00
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib = array();
|
|
|
|
|
|
|
|
if (!$this->canEdit()) {
|
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
|
|
|
$readOnlyAttrib['disabled'] = 'disabled';
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
switch( $action ) {
|
|
|
|
case 'throttle':
|
2009-02-07 09:34:11 +00:00
|
|
|
$throttleSettings = Xml::checkLabel(
|
|
|
|
wfMsg( 'abusefilter-edit-action-throttle' ),
|
|
|
|
'wpFilterActionThrottle',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2009-04-01 04:34:21 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $readOnlyAttrib );
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleFields = array();
|
|
|
|
|
|
|
|
if ($set) {
|
|
|
|
array_shift( $parameters );
|
|
|
|
$throttleRate = explode(',', $parameters[0]);
|
|
|
|
$throttleCount = $throttleRate[0];
|
|
|
|
$throttlePeriod = $throttleRate[1];
|
|
|
|
|
|
|
|
$throttleGroups = implode("\n", array_slice($parameters, 1 ) );
|
|
|
|
} 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-02-07 09:34:11 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-count'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::input( 'wpFilterThrottleCount', 20, $throttleCount, $readOnlyAttrib );
|
2009-02-07 09:34:11 +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
|
|
|
|
) )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
|
|
|
$throttleFields['abusefilter-edit-throttle-groups'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::textarea( 'wpFilterThrottleGroups', $throttleGroups."\n",
|
|
|
|
40, 5, $readOnlyAttrib );
|
2009-02-07 09:34:11 +00:00
|
|
|
$throttleSettings .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-throttle-parameters' ),
|
|
|
|
Xml::buildForm( $throttleFields )
|
|
|
|
);
|
2009-01-28 19:40:15 +00:00
|
|
|
return $throttleSettings;
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'flag':
|
2009-02-07 09:34:11 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
wfMsg( 'abusefilter-edit-action-flag' ),
|
|
|
|
'wpFilterActionFlag',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
true,
|
|
|
|
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 = '';
|
2009-02-07 09:34:11 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
wfMsg( 'abusefilter-edit-action-warn' ),
|
|
|
|
'wpFilterActionWarn',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2009-04-01 04:34:21 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $readOnlyAttrib );
|
2009-01-23 19:23:44 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
|
|
|
$warnMsg = empty($set) ? 'abusefilter-warning' : $parameters[0];
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-message'] =
|
|
|
|
$this->getExistingSelector( $warnMsg );
|
|
|
|
$warnFields['abusefilter-edit-warn-other-label'] =
|
|
|
|
Xml::input(
|
|
|
|
'wpFilterWarnMessageOther',
|
|
|
|
45,
|
|
|
|
$warnMsg ? $warnMsg : 'abusefilter-warning-',
|
2009-04-01 04:34:21 +00:00
|
|
|
array( 'id' => 'mw-abusefilter-warn-message-other' ) + $readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$previewButton = Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-preview-button',
|
|
|
|
'value' => wfMsg( 'abusefilter-edit-warn-preview' )
|
2009-04-01 04:34:21 +00:00
|
|
|
) + $readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
|
|
|
$editButton = Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-edit-button',
|
|
|
|
'value' => wfMsg( 'abusefilter-edit-warn-edit' )
|
2009-04-01 04:34:21 +00:00
|
|
|
) + $readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
|
|
|
$previewHolder = Xml::element(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-warn-preview' ), ''
|
|
|
|
);
|
|
|
|
$warnFields['abusefilter-edit-warn-actions'] =
|
|
|
|
Xml::tags( 'p', null, "$previewButton $editButton" ) . "\n$previewHolder";
|
|
|
|
$output .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-warn-parameters' ),
|
|
|
|
Xml::buildForm( $warnFields )
|
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
2009-01-28 19:08:18 +00:00
|
|
|
case 'tag':
|
|
|
|
if ($set) {
|
|
|
|
$tags = $parameters;
|
|
|
|
} else {
|
|
|
|
$tags = array();
|
|
|
|
}
|
|
|
|
$output = '';
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
wfMsg('abusefilter-edit-action-tag'),
|
|
|
|
'wpFilterActionTag',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2009-04-01 04:34:21 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $readOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
|
|
|
|
2009-02-07 09:34:11 +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-02-07 09:34:11 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags( 'div',
|
|
|
|
array( 'id' => 'mw-abusefilter-tag-parameters' ),
|
|
|
|
Xml::buildForm( $tagFields )
|
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
return $output;
|
2009-01-23 19:23:44 +00:00
|
|
|
default:
|
|
|
|
$message = 'abusefilter-edit-action-'.$action;
|
|
|
|
$form_field = 'wpFilterAction' . ucfirst($action);
|
|
|
|
$status = $set;
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$thisAction = Xml::checkLabel(
|
|
|
|
wfMsg( $message ),
|
|
|
|
$form_field,
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$status,
|
2009-04-01 04:34:21 +00:00
|
|
|
array( 'class' => 'mw-abusefilter-action-checkbox' ) + $readOnlyAttrib
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:45:42 +00:00
|
|
|
function getExistingSelector( $warnMsg ) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$existingSelector = new XmlSelect(
|
|
|
|
'wpFilterWarnMessage',
|
|
|
|
'mw-abusefilter-warn-message-existing',
|
|
|
|
$warnMsg == 'abusefilter-warning' ? 'abusefilter-warning' : 'other'
|
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
// Find other messages.
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2009-02-07 09:34:11 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'page',
|
|
|
|
array( 'page_title' ),
|
|
|
|
array(
|
|
|
|
'page_namespace' => 8,
|
|
|
|
'page_title LIKE '.$dbr->addQuotes( 'Abusefilter-warning%' )
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
$existingSelector->addOption( 'abusefilter-warning' );
|
|
|
|
|
|
|
|
global $wgLang;
|
|
|
|
while( $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
if ( $wgLang->lcfirst($row->page_title) == $wgLang->lcfirst($warnMsg) ) {
|
|
|
|
$existingSelector->setDefault( $wgLang->lcfirst($warnMsg) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($row->page_title != 'Abusefilter-warning') {
|
|
|
|
$existingSelector->addOption( $wgLang->lcfirst($row->page_title) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$existingSelector->addOption( wfMsg( 'abusefilter-edit-warn-other' ), 'other' );
|
|
|
|
|
|
|
|
return $existingSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
function loadFilterData( $id ) {
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
// Load the main row
|
|
|
|
$row = $dbr->selectRow( 'abuse_filter', '*', array( 'af_id' => $id ), __METHOD__ );
|
|
|
|
|
|
|
|
if (!isset($row) || !isset($row->af_id) || !$row->af_id)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// Load the actions
|
|
|
|
$actions = array();
|
2009-02-07 09:34:11 +00:00
|
|
|
$res = $dbr->select( 'abuse_filter_action', '*',
|
|
|
|
array( 'afa_filter' => $id), __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
while ( $actionRow = $dbr->fetchObject( $res ) ) {
|
|
|
|
$thisAction = array();
|
|
|
|
$thisAction['action'] = $actionRow->afa_consequence;
|
|
|
|
$thisAction['parameters'] = explode( "\n", $actionRow->afa_parameters );
|
|
|
|
|
|
|
|
$actions[$actionRow->afa_consequence] = $thisAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array( $row, $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadRequest( $filter, $history_id = null ) {
|
|
|
|
static $row = null;
|
|
|
|
static $actions = null;
|
|
|
|
global $wgRequest;
|
|
|
|
|
|
|
|
if (!is_null($actions) && !is_null($row)) {
|
|
|
|
return array($row,$actions);
|
|
|
|
} elseif ($wgRequest->wasPosted()) {
|
|
|
|
## Nothing, we do it all later
|
|
|
|
} elseif ( $history_id ) {
|
|
|
|
return $this->loadHistoryItem( $history_id );
|
|
|
|
} else {
|
|
|
|
return $this->loadFilterData( $filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need some details like last editor
|
2009-01-26 22:30:42 +00:00
|
|
|
list($row,$origActions) = $this->loadFilterData( $filter );
|
|
|
|
|
|
|
|
$row->mOriginalRow = clone $row;
|
|
|
|
$row->mOriginalActions = $origActions;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$textLoads = array(
|
|
|
|
'af_public_comments' => 'wpFilterDescription',
|
|
|
|
'af_pattern' => 'wpFilterRules',
|
|
|
|
'af_comments' => 'wpFilterNotes' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
foreach( $textLoads as $col => $field ) {
|
|
|
|
$row->$col = trim($wgRequest->getVal( $field ));
|
|
|
|
}
|
|
|
|
|
|
|
|
$row->af_deleted = $wgRequest->getBool( 'wpFilterDeleted' );
|
|
|
|
$row->af_enabled = $wgRequest->getBool( 'wpFilterEnabled' ) && !$row->af_deleted;
|
|
|
|
$row->af_hidden = $wgRequest->getBool( 'wpFilterHidden' );
|
2009-03-30 06:12:12 +00:00
|
|
|
global $wgAbuseFilterIsCentral;
|
|
|
|
$row->af_global = $wgRequest->getBool( 'wpFilterGlobal' ) && $wgAbuseFilterIsCentral;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
global $wgAbuseFilterAvailableActions;
|
|
|
|
$actions = array();
|
|
|
|
foreach( $wgAbuseFilterAvailableActions as $action ) {
|
|
|
|
// Check if it's set
|
|
|
|
$enabled = $wgRequest->getBool( 'wpFilterAction'.ucfirst($action) );
|
|
|
|
|
|
|
|
if ($enabled) {
|
|
|
|
$parameters = array();
|
|
|
|
|
|
|
|
if ($action == 'throttle') {
|
|
|
|
// We need to load the parameters
|
|
|
|
$throttleCount = $wgRequest->getIntOrNull( 'wpFilterThrottleCount' );
|
|
|
|
$throttlePeriod = $wgRequest->getIntOrNull( 'wpFilterThrottlePeriod' );
|
2009-02-07 09:34:11 +00:00
|
|
|
$throttleGroups = explode( "\n",
|
|
|
|
trim( $wgRequest->getText( 'wpFilterThrottleGroups' ) ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$parameters[0] = $this->mFilter; // For now, anyway
|
|
|
|
$parameters[1] = "$throttleCount,$throttlePeriod";
|
|
|
|
$parameters = array_merge( $parameters, $throttleGroups );
|
|
|
|
} elseif ($action == 'warn') {
|
2009-02-03 22:45:42 +00:00
|
|
|
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessage' );
|
|
|
|
|
|
|
|
if ($specMsg == 'other')
|
|
|
|
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessageOther' );
|
|
|
|
|
|
|
|
$parameters[0] = $specMsg;
|
2009-01-23 19:23:19 +00:00
|
|
|
} elseif ($action == 'tag') {
|
|
|
|
$parameters = explode("\n", $wgRequest->getText( 'wpFilterTags' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$thisAction = array( 'action' => $action, 'parameters' => $parameters );
|
|
|
|
$actions[$action] = $thisAction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadHistoryItem( $id ) {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
// Load the row.
|
2009-02-07 09:34:11 +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
|
|
|
}
|