mediawiki-extensions-AbuseF.../includes/Views/AbuseFilterViewTestBatch.php

188 lines
5.2 KiB
PHP
Raw Normal View History

<?php
class AbuseFilterViewTestBatch extends AbuseFilterView {
// Hard-coded for now.
protected static $mChangeLimit = 100;
public $mShowNegative, $mTestPeriodStart, $mTestPeriodEnd, $mTestPage,
$mTestUser;
function show() {
$out = $this->getOutput();
AbuseFilter::disableConditionLimit();
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
$out->addWikiMsg( 'abusefilter-mustbeeditor' );
return;
}
$this->loadParameters();
$out->setPageTitle( $this->msg( 'abusefilter-test' ) );
$out->addWikiMsg( 'abusefilter-test-intro', self::$mChangeLimit );
$output = '';
$output .= AbuseFilter::buildEditBox( $this->mFilter, 'wpTestFilter' ) . "\n";
$output .=
Xml::inputLabel(
$this->msg( 'abusefilter-test-load-filter' )->text(),
'wpInsertFilter',
'mw-abusefilter-load-filter',
10,
''
) .
Remove most named character references from output 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/&nbsp;/\&#160;/g;s/&mdash;/―/g;s/&bull;/•/g;s/&aacute;/á/g;s/&acute;/´/g;s/&agrave;/à/g;s/&alpha;/α/g;s/&auml;/ä/g;s/&ccedil;/ç/g;s/&copy;/©/g;s/&darr;/↓/g;s/&deg;/°/g;s/&eacute;/é/g;s/&ecirc;/ê/g;s/&euml;/ë/g;s/&egrave;/è/g;s/&euro;/€/g;s/&harr;//g;s/&hellip;/…/g;s/&iacute;/í/g;s/&igrave;/ì/g;s/&larr;/←/g;s/&ldquo;/“/g;s/&middot;/·/g;s/&minus;/−/g;s/&ndash;/–/g;s/&oacute;/ó/g;s/&ocirc;/ô/g;s/&oelig;/œ/g;s/&ograve;/ò/g;s/&otilde;/õ/g;s/&ouml;/ö/g;s/&pound;/£/g;s/&prime;/′/g;s/&Prime;/″/g;s/&raquo;/»/g;s/&rarr;/→/g;s/&rdquo;/”/g;s/&Sigma;/Σ/g;s/&times;/×/g;s/&uacute;/ú/g;s/&uarr;/↑/g;s/&uuml;/ü/g;s/&yen;/¥/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 &nbsp 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.
2010-05-30 17:33:59 +00:00
'&#160;' .
Xml::element(
'input',
[
'type' => 'button',
'value' => $this->msg( 'abusefilter-test-load' )->text(),
'id' => 'mw-abusefilter-load'
]
);
$output = Xml::tags( 'div', [ 'id' => 'mw-abusefilter-test-editor' ], $output );
$output .= Xml::tags( 'p', null, Xml::checkLabel(
$this->msg( 'abusefilter-test-shownegative' )->text(),
'wpShowNegative', 'wpShowNegative', $this->mShowNegative )
);
// Selectory stuff
$selectFields = [];
2009-03-21 18:47:26 +00:00
$selectFields['abusefilter-test-user'] = Xml::input( 'wpTestUser', 45, $this->mTestUser );
$selectFields['abusefilter-test-period-start'] =
2009-03-21 18:47:26 +00:00
Xml::input( 'wpTestPeriodStart', 45, $this->mTestPeriodStart );
$selectFields['abusefilter-test-period-end'] =
2009-03-21 18:47:26 +00:00
Xml::input( 'wpTestPeriodEnd', 45, $this->mTestPeriodEnd );
$selectFields['abusefilter-test-page'] =
Xml::input( 'wpTestPage', 45, $this->mTestPage );
$output .= Xml::buildForm( $selectFields, 'abusefilter-test-submit' );
$output .= Html::hidden( 'title', $this->getTitle( 'test' )->getPrefixedDBkey() );
$output = Xml::tags( 'form',
[
'action' => $this->getTitle( 'test' )->getLocalURL(),
'method' => 'post'
],
$output
);
$output = Xml::fieldset( $this->msg( 'abusefilter-test-legend' )->text(), $output );
$out->addHTML( $output );
if ( $this->getRequest()->wasPosted() ) {
$this->doTest();
}
}
function doTest() {
// Quick syntax check.
$out = $this->getOutput();
2010-11-04 01:29:10 +00:00
$result = AbuseFilter::checkSyntax( $this->mFilter );
if ( $result !== true ) {
$out->addWikiMsg( 'abusefilter-test-syntaxerr' );
return;
}
$dbr = wfGetDB( DB_SLAVE );
$conds = [
'rc_user_text' => $this->mTestUser,
'rc_type != ' . RC_EXTERNAL
];
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 );
if ( $title instanceof Title ) {
$conds['rc_namespace'] = $title->getNamespace();
$conds['rc_title'] = $title->getDBkey();
} else {
$out->addWikiMsg( 'abusefilter-test-badtitle' );
return;
}
}
// Get our ChangesList
$changesList = new AbuseFilterChangesList( $this->getSkin() );
$output = $changesList->beginRecentChangesList();
$res = $dbr->select(
'recentchanges',
'*',
array_filter( $conds ),
__METHOD__,
[ 'LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp desc' ]
);
$counter = 1;
foreach ( $res as $row ) {
$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();
$out->addHTML( $output );
}
function loadParameters() {
$request = $this->getRequest();
$this->mFilter = $request->getText( 'wpTestFilter' );
$this->mShowNegative = $request->getBool( 'wpShowNegative' );
$testUsername = $request->getText( 'wpTestUser' );
$this->mTestPeriodEnd = $request->getText( 'wpTestPeriodEnd' );
$this->mTestPeriodStart = $request->getText( 'wpTestPeriodStart' );
$this->mTestPage = $request->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',
[ '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.
}
}
}