mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-01 09:06:22 +00:00
ed5b83e6ac
Recommit of r66254 to trunk. This was just find extensions phase3 -iname '*.php' \! -iname '*.i18n.php' \! -iname 'Messages*.php' \! -iname '*_Messages.php' -exec sed -i 's/ /\ /g;s/—/―/g;s/•/•/g;s/á/á/g;s/´/´/g;s/à/à/g;s/α/α/g;s/ä/ä/g;s/ç/ç/g;s/©/©/g;s/↓/↓/g;s/°/°/g;s/é/é/g;s/ê/ê/g;s/ë/ë/g;s/è/è/g;s/€/€/g;s/↔//g;s/…/…/g;s/í/í/g;s/ì/ì/g;s/←/←/g;s/“/“/g;s/·/·/g;s/−/−/g;s/–/–/g;s/ó/ó/g;s/ô/ô/g;s/œ/œ/g;s/ò/ò/g;s/õ/õ/g;s/ö/ö/g;s/£/£/g;s/′/′/g;s/″/″/g;s/»/»/g;s/→/→/g;s/”/”/g;s/Σ/Σ/g;s/×/×/g;s/ú/ú/g;s/↑/↑/g;s/ü/ü/g;s/¥/¥/g' {} + followed by reading over every single line of the resulting diff and fixing a whole bunch of false positives. The reason for this change is given in <http://lists.wikimedia.org/pipermail/wikitech-l/2010-April/047617.html>. I cleared it with Tim and Brion on IRC before committing. It might cause a few problems, but I tried to be careful; please report any issues. I skipped all messages files. I plan to make a follow-up commit that alters wfMsgExt() with 'escapenoentities' to sanitize all the entities. That way, the only messages that will be problems will be ones that output raw HTML, and we want to get rid of those anyway. This should get rid of all named entities everywhere except messages. I skipped a few things like   that I noticed in manual inspection, because they weren't well-formed XML anyway. Also, to everyone who uses non-breaking spaces when they could use a normal space, or nothing at all, or CSS padding: I still hate you. Die.
173 lines
4.9 KiB
PHP
173 lines
4.9 KiB
PHP
<?php
|
|
if ( !defined( 'MEDIAWIKI' ) )
|
|
die();
|
|
|
|
class AbuseFilterViewTestBatch extends AbuseFilterView {
|
|
// Hard-coded for now.
|
|
static $mChangeLimit = 100;
|
|
|
|
function show() {
|
|
global $wgOut, $wgUser, $wgRequest;
|
|
|
|
AbuseFilter::disableConditionLimit();
|
|
|
|
if ( !$wgUser->isAllowed( 'abusefilter-modify' ) ) {
|
|
$wgOut->addWikiMsg( 'abusefilter-mustbeeditor' );
|
|
return;
|
|
}
|
|
|
|
$this->loadParameters();
|
|
|
|
$wgOut->setPageTitle( wfMsg( 'abusefilter-test' ) );
|
|
$wgOut->addWikiMsg( 'abusefilter-test-intro', self::$mChangeLimit );
|
|
|
|
$output = '';
|
|
$output .= AbuseFilter::buildEditBox( $this->mFilter, 'wpTestFilter' ) . "\n";
|
|
$output .=
|
|
Xml::inputLabel(
|
|
wfMsg( 'abusefilter-test-load-filter' ),
|
|
'wpInsertFilter',
|
|
'mw-abusefilter-load-filter',
|
|
10,
|
|
''
|
|
) .
|
|
' ' .
|
|
Xml::element(
|
|
'input',
|
|
array(
|
|
'type' => 'button',
|
|
'value' => wfMsg( 'abusefilter-test-load' ),
|
|
'id' => 'mw-abusefilter-load'
|
|
)
|
|
);
|
|
$output = Xml::tags( 'div', array( 'id' => 'mw-abusefilter-test-editor' ), $output );
|
|
|
|
$output .= Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'abusefilter-test-shownegative' ), 'wpShowNegative', 'wpShowNegative', $this->mShowNegative ) );
|
|
|
|
// Selectory stuff
|
|
$selectFields = array();
|
|
$selectFields['abusefilter-test-user'] = Xml::input( 'wpTestUser', 45, $this->mTestUser );
|
|
$selectFields['abusefilter-test-period-start'] =
|
|
Xml::input( 'wpTestPeriodStart', 45, $this->mTestPeriodStart );
|
|
$selectFields['abusefilter-test-period-end'] =
|
|
Xml::input( 'wpTestPeriodEnd', 45, $this->mTestPeriodEnd );
|
|
$selectFields['abusefilter-test-page'] =
|
|
Xml::input( 'wpTestPage', 45, $this->mTestPage );
|
|
|
|
$output .= Xml::buildForm( $selectFields, 'abusefilter-test-submit' );
|
|
|
|
$output .= Xml::hidden( 'title', $this->getTitle( 'test' )->getPrefixedText() );
|
|
$output = Xml::tags( 'form',
|
|
array(
|
|
'action' => $this->getTitle( 'test' )->getLocalURL(),
|
|
'method' => 'POST'
|
|
),
|
|
$output
|
|
);
|
|
|
|
$output = Xml::fieldset( wfMsg( 'abusefilter-test-legend' ), $output );
|
|
|
|
$wgOut->addHTML( $output );
|
|
|
|
if ( $wgRequest->wasPosted() ) {
|
|
$this->doTest();
|
|
}
|
|
}
|
|
|
|
function doTest() {
|
|
// Quick syntax check.
|
|
global $wgUser, $wgOut;
|
|
if ( ( $result = AbuseFilter::checkSyntax( $this->mFilter ) ) !== true ) {
|
|
$wgOut->addWikiMsg( 'abusefilter-test-syntaxerr' );
|
|
return;
|
|
}
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$conds = array( 'rc_user_text' => $this->mTestUser );
|
|
|
|
if ( $this->mTestPeriodStart ) {
|
|
$conds[] = 'rc_timestamp >= ' .
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mTestPeriodStart ) ) );
|
|
}
|
|
if ( $this->mTestPeriodEnd ) {
|
|
$conds[] = 'rc_timestamp <= ' .
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mTestPeriodEnd ) ) );
|
|
}
|
|
if ( $this->mTestPage ) {
|
|
$title = Title::newFromText( $this->mTestPage );
|
|
$conds['rc_namespace'] = $title->getNamespace();
|
|
$conds['rc_title'] = $title->getDBkey();
|
|
}
|
|
|
|
// Get our ChangesList
|
|
$changesList = new AbuseFilterChangesList( $wgUser->getSkin() );
|
|
$output = $changesList->beginRecentChangesList();
|
|
|
|
$res = $dbr->select(
|
|
'recentchanges',
|
|
'*',
|
|
array_filter( $conds ),
|
|
__METHOD__,
|
|
array( 'LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp desc' )
|
|
);
|
|
|
|
$counter = 1;
|
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
if ( !$vars )
|
|
continue;
|
|
|
|
$result = AbuseFilter::checkConditions( $this->mFilter, $vars );
|
|
|
|
if ( $result || $this->mShowNegative ) {
|
|
// Stash result in RC item
|
|
$rc = RecentChange::newFromRow( $row );
|
|
$rc->examineParams['testfilter'] = $this->mFilter;
|
|
$rc->filterResult = $result;
|
|
$rc->counter = $counter++;
|
|
$output .= $changesList->recentChangesLine( $rc, false );
|
|
}
|
|
}
|
|
|
|
$output .= $changesList->endRecentChangesList();
|
|
|
|
$wgOut->addHTML( $output );
|
|
}
|
|
|
|
function loadParameters() {
|
|
global $wgRequest;
|
|
|
|
$this->mFilter = $wgRequest->getText( 'wpTestFilter' );
|
|
$this->mShowNegative = $wgRequest->getBool( 'wpShowNegative' );
|
|
$testUsername = $wgRequest->getText( 'wpTestUser' );
|
|
$this->mTestPeriodEnd = $wgRequest->getText( 'wpTestPeriodEnd' );
|
|
$this->mTestPeriodStart = $wgRequest->getText( 'wpTestPeriodStart' );
|
|
$this->mTestPage = $wgRequest->getText( 'wpTestPage' );
|
|
|
|
if ( !$this->mFilter
|
|
&& count( $this->mParams ) > 1
|
|
&& is_numeric( $this->mParams[1] ) )
|
|
{
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
$this->mFilter = $dbr->selectField( 'abuse_filter',
|
|
'af_pattern',
|
|
array( 'af_id' => $this->mParams[1] ),
|
|
__METHOD__
|
|
);
|
|
}
|
|
|
|
// Normalise username
|
|
$userTitle = Title::newFromText( $testUsername );
|
|
|
|
if ( $userTitle && $userTitle->getNamespace() == NS_USER )
|
|
$this->mTestUser = $userTitle->getText(); // Allow User:Blah syntax.
|
|
elseif ( $userTitle )
|
|
// Not sure of the value of prefixedText over text, but no need to munge unnecessarily.
|
|
$this->mTestUser = $userTitle->getPrefixedText();
|
|
else
|
|
$this->mTestUser = null; // No user specified.
|
|
}
|
|
}
|