mediawiki-extensions-AbuseF.../Views/AbuseFilterViewExamine.php

278 lines
7.3 KiB
PHP
Raw Normal View History

<?php
class AbuseFilterViewExamine extends AbuseFilterView {
public static $examineType = null;
public static $examineId = null;
public $mCounter, $mSearchUser, $mSearchPeriodStart, $mSearchPeriodEnd,
$mTestFilter;
function show() {
$out = $this->getOutput();
$out->setPageTitle( $this->msg( 'abusefilter-examine' ) );
$out->addWikiMsg( 'abusefilter-examine-intro' );
$this->loadParameters();
// Check if we've got a subpage
if ( count( $this->mParams ) > 1 && is_numeric( $this->mParams[1] ) ) {
$this->showExaminerForRC( $this->mParams[1] );
} elseif ( count( $this->mParams ) > 2
&& $this->mParams[1] == 'log'
&& is_numeric( $this->mParams[2] ) )
{
$this->showExaminerForLogEntry( $this->mParams[2] );
} else {
$this->showSearch();
}
}
function showSearch() {
// Add selector
$selector = '';
$selectFields = array(); # Same fields as in Test
2009-03-21 18:47:26 +00:00
$selectFields['abusefilter-test-user'] = Xml::input( 'wpSearchUser', 45, $this->mSearchUser );
$selectFields['abusefilter-test-period-start'] =
2009-03-21 18:47:26 +00:00
Xml::input( 'wpSearchPeriodStart', 45, $this->mSearchPeriodStart );
$selectFields['abusefilter-test-period-end'] =
2009-03-21 18:47:26 +00:00
Xml::input( 'wpSearchPeriodEnd', 45, $this->mSearchPeriodEnd );
$selector .= Xml::buildForm( $selectFields, 'abusefilter-examine-submit' );
$selector .= Html::hidden( 'submit', 1 );
$selector .= Html::hidden( 'title', $this->getTitle( 'examine' )->getPrefixedText() );
$selector = Xml::tags( 'form',
array(
'action' => $this->getTitle( 'examine' )->getLocalURL(),
'method' => 'get'
),
$selector
);
$selector = Xml::fieldset(
$this->msg( 'abusefilter-examine-legend' )->text(),
$selector
);
$this->getOutput()->addHTML( $selector );
if ( $this->mSubmit ) {
$this->showResults();
}
}
function showResults() {
$changesList = new AbuseFilterChangesList( $this->getSkin() );
$output = $changesList->beginRecentChangesList();
2009-03-12 11:38:21 +00:00
$this->mCounter = 1;
2009-03-12 11:38:21 +00:00
$pager = new AbuseFilterExaminePager( $this, $changesList );
$output .= $pager->getNavigationBar() .
$pager->getBody() .
$pager->getNavigationBar();
$output .= $changesList->endRecentChangesList();
$this->getOutput()->addHTML( $output );
}
function showExaminerForRC( $rcid ) {
// Get data
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
if ( !$row ) {
$this->getOutput()->addWikiMsg( 'abusefilter-examine-notfound' );
return;
}
self::$examineType = 'rc';
self::$examineId = $rcid;
$vars = AbuseFilter::getVarsFromRCRow( $row );
$this->showExaminer( $vars );
}
function showExaminerForLogEntry( $logid ) {
// Get data
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'abuse_filter_log', '*', array( 'afl_id' => $logid ), __METHOD__ );
if ( !$row ) {
$this->getOutput()->addWikiMsg( 'abusefilter-examine-notfound' );
return;
}
self::$examineType = 'log';
self::$examineId = $logid;
if ( !SpecialAbuseLog::canSeeDetails( $row->afl_filter ) ) {
$this->getOutput()->addWikiMsg( 'abusefilter-log-cannot-see-details' );
return;
}
if ( $row->afl_deleted && !SpecialAbuseLog::canSeeHidden() ) {
$this->getOutput()->addWikiMsg( 'abusefilter-log-details-hidden' );
return;
}
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
$this->showExaminer( $vars );
}
function showExaminer( $vars ) {
$output = $this->getOutput();
if ( !$vars ) {
$output->addWikiMsg( 'abusefilter-examine-incompatible' );
return;
}
if ( $vars instanceof AbuseFilterVariableHolder ) {
$vars = $vars->exportAllVars();
}
2011-11-22 16:08:18 +00:00
$html = '';
$output->addModules( 'ext.abuseFilter.examine' );
// Add test bit
if ( $this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
$tester = Xml::tags( 'h2', null, $this->msg( 'abusefilter-examine-test' )->parse() );
$tester .= AbuseFilter::buildEditBox( $this->mTestFilter, 'wpTestFilter', false );
$tester .=
"\n" .
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',
array(
'type' => 'button',
'value' => $this->msg( 'abusefilter-test-load' )->text(),
'id' => 'mw-abusefilter-load'
)
);
2011-11-22 16:08:18 +00:00
$html .= Xml::tags( 'div', array( 'id' => 'mw-abusefilter-examine-editor' ), $tester );
$html .= Xml::tags( 'p',
null,
Xml::element( 'input',
array(
'type' => 'button',
'value' => $this->msg( 'abusefilter-examine-test-button' )->text(),
'id' => 'mw-abusefilter-examine-test'
)
) .
Xml::element( 'div',
array(
'id' => 'mw-abusefilter-syntaxresult',
'style' => 'display: none;'
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;'
)
);
}
// Variable dump
$html .= Xml::tags(
'h2',
null,
$this->msg( 'abusefilter-examine-vars', 'parseinline' )->parse()
);
2011-11-22 16:08:18 +00:00
$html .= AbuseFilter::buildVarDumpTable( $vars );
2011-11-22 16:08:18 +00:00
$output->addHTML( $html );
}
function loadParameters() {
$request = $this->getRequest();
$searchUsername = $request->getText( 'wpSearchUser' );
$this->mSearchPeriodStart = $request->getText( 'wpSearchPeriodStart' );
$this->mSearchPeriodEnd = $request->getText( 'wpSearchPeriodEnd' );
$this->mSubmit = $request->getCheck( 'submit' );
$this->mTestFilter = $request->getText( 'testfilter' );
// Normalise username
$userTitle = Title::newFromText( $searchUsername );
if ( $userTitle && $userTitle->getNamespace() == NS_USER ) {
$this->mSearchUser = $userTitle->getText(); // Allow User:Blah syntax.
} elseif ( $userTitle ) {
// Not sure of the value of prefixedText over text, but no need to munge unnecessarily.
$this->mSearchUser = $userTitle->getPrefixedText();
} else {
$this->mSearchUser = '';
}
}
}
2009-03-12 11:38:21 +00:00
class AbuseFilterExaminePager extends ReverseChronologicalPager {
/**
* @param AbuseFilterViewExamine $page
* @param AbuseFilterChangesList $changesList
*/
2009-03-12 11:38:21 +00:00
function __construct( $page, $changesList ) {
parent::__construct();
$this->mChangesList = $changesList;
$this->mPage = $page;
}
2009-03-12 11:38:21 +00:00
function getQueryInfo() {
$dbr = wfGetDB( DB_SLAVE );
$conds = array(
'rc_user_text' => $this->mPage->mSearchUser,
'rc_type != ' . RC_EXTERNAL
);
$startTS = strtotime( $this->mPage->mSearchPeriodStart );
if ( $startTS ) {
2009-03-12 11:38:21 +00:00
$conds[] = 'rc_timestamp>=' . $dbr->addQuotes( $dbr->timestamp( $startTS ) );
}
$endTS = strtotime( $this->mPage->mSearchPeriodEnd );
if ( $endTS ) {
2009-03-12 11:38:21 +00:00
$conds[] = 'rc_timestamp<=' . $dbr->addQuotes( $dbr->timestamp( $endTS ) );
}
2009-03-12 11:38:21 +00:00
// If one of these is true, we're abusefilter compatible.
$compatConds = array(
'rc_this_oldid != 0',
'rc_log_action' => array( 'move', 'create' ),
2009-03-12 11:38:21 +00:00
);
2009-03-12 11:38:21 +00:00
$conds[] = $dbr->makeList( $compatConds, LIST_OR );
2009-03-12 11:38:21 +00:00
$info = array(
'tables' => 'recentchanges',
'fields' => '*',
'conds' => array_filter( $conds ),
2009-03-12 11:38:21 +00:00
'options' => array( 'ORDER BY' => 'rc_timestamp DESC' ),
);
2009-03-12 11:38:21 +00:00
return $info;
}
2009-03-12 11:38:21 +00:00
function formatRow( $row ) {
# Incompatible stuff.
2009-03-12 11:38:21 +00:00
$rc = RecentChange::newFromRow( $row );
$rc->counter = $this->mPage->mCounter++;
return $this->mChangesList->recentChangesLine( $rc, false );
}
2009-03-12 11:38:21 +00:00
function getIndexField() {
return 'rc_id';
}
2009-03-12 11:38:21 +00:00
function getTitle() {
return $this->mPage->getTitle( 'examine' );
}
function getEmptyBody() {
return $this->msg( 'abusefilter-examine-noresults' )->parseAsBlock();
}
}