Add import/export interface for filters so that filters can be copied across wikis

This commit is contained in:
Andrew Garrett 2009-04-23 04:23:56 +00:00
parent 7e70a0d197
commit 1a0fc0fea9
7 changed files with 124 additions and 53 deletions

View file

@ -126,6 +126,7 @@ class AbuseFilter {
'examine' => 'Special:AbuseFilter/examine',
'log' => 'Special:AbuseLog',
'tools' => 'Special:AbuseFilter/tools',
'import' => 'Special:AbuseFilter/import',
);
// Save some translator work

View file

@ -209,6 +209,7 @@ Please ask a user with permission to add restricted actions to make the change f
'abusefilter-edit-tools' => 'Tools:',
'abusefilter-edit-test-link' => 'Test this filter against recent edits',
'abusefilter-edit-global' => 'Apply this filter globally',
'abusefilter-edit-export' => 'Export this filter to another wiki',
// Filter editing helpers
'abusefilter-edit-builder-select' => 'Select an option to add it at the cursor',
@ -411,6 +412,7 @@ You can receive a full explanation by clicking the "Check Syntax" button.',
'abusefilter-topnav-examine' => 'Examine past edits',
'abusefilter-topnav-log' => 'Abuse Log',
'abusefilter-topnav-tools' => 'Debugging tools',
'abusefilter-topnav-import' => 'Import filter',
// Logging
'abusefilter-log-name' => 'Abuse Filter log',
@ -426,6 +428,12 @@ For full details, see [[Special:AbuseFilter/history|the list]] of recent filter
'abusefilter-diff-pattern' => 'Filter conditions',
'abusefilter-diff-invalid' => 'Unable to fetch the requested versions',
'abusefilter-diff-backhistory' => 'Back to filter history',
// Import interface
'abusefilter-import-intro' => 'You can use this interface to import filters from other wikis.
On the source wiki, click "export this filter to another wiki" under "tools" on the editing interface.
Copy from the textbox that appears, and paste it into this textbox, then click "Import",',
'abusefilter-import-submit' => 'Import data',
);
/** Message documentation (Message documentation)

View file

@ -43,6 +43,7 @@ $wgAutoloadClasses['AbuseFilterViewTestBatch'] = "$dir/Views/AbuseFilterViewTest
$wgAutoloadClasses['AbuseFilterViewExamine'] = "$dir/Views/AbuseFilterViewExamine.php";
$wgAutoloadClasses['AbuseFilterChangesList'] = "$dir/Views/AbuseFilterViewExamine.php";
$wgAutoloadClasses['AbuseFilterViewDiff'] = "$dir/Views/AbuseFilterViewDiff.php";
$wgAutoloadClasses['AbuseFilterViewImport'] = "$dir/Views/AbuseFilterViewImport.php";
$wgAutoloadClasses['AbuseFilterVariableHolder'] = "$dir/AbuseFilterVariableHolder.php";
$wgAutoloadClasses['AFComputedVariable'] = "$dir/AbuseFilterVariableHolder.php";
@ -102,7 +103,7 @@ $wgAjaxExportList[] = 'AbuseFilter::ajaxGetFilter';
$wgAjaxExportList[] = 'AbuseFilter::ajaxCheckFilterWithVars';
// Bump the version number every time you change any of the .css/.js files
$wgAbuseFilterStyleVersion = 8;
$wgAbuseFilterStyleVersion = 9;
$wgAbuseFilterRestrictedActions = array( 'block', 'degroup' );

View file

@ -90,6 +90,11 @@ class SpecialAbuseFilter extends SpecialPage {
$pageType = 'edit';
}
if ( $subpage == 'import' ) {
$view = 'AbuseFilterViewImport';
$pageType = 'import';
}
// Links at the top
AbuseFilter::addNavigationLinks( $wgOut, $this->mSkin, $pageType );

View file

@ -360,10 +360,16 @@ class AbuseFilterViewEdit extends AbuseFilterView {
$fields['abusefilter-edit-history'] =
$sk->makeKnownLinkObj( $this->getTitle( 'history/'.$filter ), $history_display );
}
// Add export
$exportText = serialize( array( 'row' => $row, 'actions' => $actions ) );
$tools .= Xml::tags( 'a', array( 'href' => 'javascript:afShowExport();' ),
wfMsgExt( 'abusefilter-edit-export', 'parseinline' ) );
$tools .= Xml::element( 'textarea',
array( 'readonly' => 'readonly', 'id' => 'mw-abusefilter-export' ),
$exportText );
if ($tools) {
$fields['abusefilter-edit-tools'] = $tools;
}
$fields['abusefilter-edit-tools'] = $tools;
$form = Xml::buildForm( $fields );
$form = Xml::fieldset( wfMsg( 'abusefilter-edit-main' ), $form );
@ -660,55 +666,77 @@ class AbuseFilterViewEdit extends AbuseFilterView {
$row->mOriginalRow = clone $row;
$row->mOriginalActions = $origActions;
$textLoads = array(
'af_public_comments' => 'wpFilterDescription',
'af_pattern' => 'wpFilterRules',
'af_comments' => 'wpFilterNotes' );
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' );
global $wgAbuseFilterIsCentral;
$row->af_global = $wgRequest->getBool( 'wpFilterGlobal' ) && $wgAbuseFilterIsCentral;
// 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' );
$throttleGroups = explode( "\n",
trim( $wgRequest->getText( 'wpFilterThrottleGroups' ) ) );
$parameters[0] = $this->mFilter; // For now, anyway
$parameters[1] = "$throttleCount,$throttlePeriod";
$parameters = array_merge( $parameters, $throttleGroups );
} elseif ($action == 'warn') {
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessage' );
if ($specMsg == 'other')
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessageOther' );
$parameters[0] = $specMsg;
} elseif ($action == 'tag') {
$parameters = explode("\n", $wgRequest->getText( 'wpFilterTags' ) );
// Check for importing
$import = $wgRequest->getVal( 'wpImportText' );
if ($import) {
$data = unserialize($import);
$importRow = $data['row'];
$actions = $data['actions'];
$copy = array(
'af_public_comments',
'af_pattern',
'af_comments',
'af_deleted',
'af_enabled',
'af_hidden',
);
foreach( $copy as $name ) {
$row->$name = $importRow->$name;
}
} else {
$textLoads = array(
'af_public_comments' => 'wpFilterDescription',
'af_pattern' => 'wpFilterRules',
'af_comments' => 'wpFilterNotes' );
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' );
global $wgAbuseFilterIsCentral;
$row->af_global = $wgRequest->getBool( 'wpFilterGlobal' ) && $wgAbuseFilterIsCentral;
// 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' );
$throttleGroups = explode( "\n",
trim( $wgRequest->getText( 'wpFilterThrottleGroups' ) ) );
$parameters[0] = $this->mFilter; // For now, anyway
$parameters[1] = "$throttleCount,$throttlePeriod";
$parameters = array_merge( $parameters, $throttleGroups );
} elseif ($action == 'warn') {
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessage' );
if ($specMsg == 'other')
$specMsg = $wgRequest->getVal( 'wpFilterWarnMessageOther' );
$parameters[0] = $specMsg;
} elseif ($action == 'tag') {
$parameters = explode("\n", $wgRequest->getText( 'wpFilterTags' ) );
}
$thisAction = array( 'action' => $action, 'parameters' => $parameters );
$actions[$action] = $thisAction;
}
$thisAction = array( 'action' => $action, 'parameters' => $parameters );
$actions[$action] = $thisAction;
}
}

View file

@ -0,0 +1,18 @@
<?php
class AbuseFilterViewImport extends AbuseFilterView {
function show( ) {
global $wgOut;
$wgOut->addWikiMsg( 'abusefilter-import-intro' );
$html = Xml::textarea( 'wpImportText', '', 40, 20 );
$html .= Xml::submitButton( wfMsg( 'abusefilter-import-submit' ) );
$url = SpecialPage::getTitleFor( 'AbuseFilter', 'new' )->getFullURL();
$html = Xml::tags( 'form', array( 'method' => 'post', 'action' => $url ), $html );
$wgOut->addHTML( $html );
}
}

12
edit.js
View file

@ -144,6 +144,10 @@ function editWarnMessage() {
window.location = wgScript + '?title=MediaWiki:'+encodeURIComponent( message )+'&action=edit';
}
function afShowExport() {
document.getElementById( 'mw-abusefilter-export' ).style.display = 'block';
}
addOnloadHook( function() {
addHandler( document.getElementById( wgFilterBoxName ), 'keyup', function() {
el = document.getElementById( 'mw-abusefilter-syntaxresult' );
@ -168,4 +172,10 @@ addOnloadHook( function() {
}
setupActions();
} );
var exporter = document.getElementById( 'mw-abusefilter-export' );
if (exporter ) {
exporter.style.display = 'none';
}
} );