2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!defined( 'MEDIAWIKI' ))
|
|
|
|
die();
|
|
|
|
|
|
|
|
class AbuseFilterViewHistory extends AbuseFilterView {
|
|
|
|
|
|
|
|
function __construct( $page, $params ) {
|
|
|
|
parent::__construct( $page, $params );
|
|
|
|
$this->mFilter = $page->mFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show() {
|
|
|
|
global $wgRequest,$wgOut;
|
|
|
|
|
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
$filter = $this->mFilter;
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
if ($filter)
|
|
|
|
$wgOut->setPageTitle( wfMsg( 'abusefilter-history', $filter ) );
|
|
|
|
else
|
2009-01-26 19:23:27 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'abusefilter-filter-log' ) );
|
2009-01-26 18:50:20 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
$links = array();
|
|
|
|
if ($filter)
|
|
|
|
$links['abusefilter-history-backedit'] = $this->getTitle( $filter );
|
|
|
|
$links['abusefilter-history-backlist'] = $this->getTitle();
|
|
|
|
|
|
|
|
foreach( $links as $msg => $title ) {
|
|
|
|
$links[$msg] = $sk->link( $title, wfMsgExt( $msg, 'parseinline' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$backlinks = implode( ' • ', $links );
|
2009-01-23 19:23:19 +00:00
|
|
|
$wgOut->addHTML( Xml::tags( 'p', null, $backlinks ) );
|
|
|
|
|
2009-01-26 18:50:20 +00:00
|
|
|
$user = $wgRequest->getText( 'user' );
|
|
|
|
if ($user) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->setSubtitle(
|
|
|
|
wfMsg(
|
|
|
|
'abusefilter-history-foruser',
|
|
|
|
$sk->userLink( 1 /* We don't really need to get a user ID */, $user )
|
|
|
|
)
|
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add filtering of changes et al.
|
|
|
|
$fields['abusefilter-history-select-user'] = wfInput( 'user', 45, $user );
|
|
|
|
|
|
|
|
$filterForm = Xml::buildForm( $fields, 'abusefilter-history-select-submit' );
|
|
|
|
$filterForm .= "\n" . Xml::hidden( 'title', $this->getTitle( "history/$filter" ) );
|
2009-02-07 09:34:11 +00:00
|
|
|
$filterForm = Xml::tags( 'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( "history/$filter" )->getLocalURL(),
|
|
|
|
'method' => 'get' ),
|
|
|
|
$filterForm
|
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
$filterForm = Xml::fieldset( wfMsg( 'abusefilter-history-select-legend' ), $filterForm );
|
|
|
|
$wgOut->addHTML( $filterForm );
|
|
|
|
|
|
|
|
$pager = new AbuseFilterHistoryPager( $filter, $this, $user );
|
2009-01-23 19:23:19 +00:00
|
|
|
$table = $pager->getBody();
|
|
|
|
|
|
|
|
$wgOut->addHTML( $pager->getNavigationBar() . $table . $pager->getNavigationBar() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AbuseFilterHistoryPager extends TablePager {
|
|
|
|
|
2009-01-26 18:50:20 +00:00
|
|
|
function __construct( $filter, $page, $user ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$this->mFilter = $filter;
|
|
|
|
$this->mPage = $page;
|
2009-01-26 18:50:20 +00:00
|
|
|
$this->mUser = $user;
|
2009-01-23 19:23:19 +00:00
|
|
|
$this->mDefaultDirection = true;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFieldNames() {
|
|
|
|
static $headers = null;
|
|
|
|
|
|
|
|
if (!empty($headers)) {
|
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$headers = array(
|
|
|
|
'afh_timestamp' => 'abusefilter-history-timestamp',
|
|
|
|
'afh_user_text' => 'abusefilter-history-user',
|
|
|
|
'afh_public_comments' => 'abusefilter-history-public',
|
|
|
|
'afh_flags' => 'abusefilter-history-flags',
|
|
|
|
'afh_pattern' => 'abusefilter-history-filter',
|
|
|
|
'afh_comments' => 'abusefilter-history-comments',
|
|
|
|
'afh_actions' => 'abusefilter-history-actions' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-26 18:50:20 +00:00
|
|
|
if (!$this->mFilter) {
|
|
|
|
// awful hack
|
|
|
|
$headers = array( 'afh_filter' => 'abusefilter-history-filterid' ) + $headers;
|
2009-02-04 19:56:21 +00:00
|
|
|
unset( $headers['afh_comments'] );
|
2009-01-26 18:50:20 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$headers = array_map( 'wfMsg', $headers );
|
|
|
|
|
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatValue( $name, $value ) {
|
|
|
|
global $wgOut,$wgLang;
|
|
|
|
|
|
|
|
static $sk=null;
|
|
|
|
|
|
|
|
if (empty($sk)) {
|
|
|
|
global $wgUser;
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = $this->mCurrentRow;
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = '';
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
switch($name) {
|
|
|
|
case 'afh_timestamp':
|
2009-02-07 09:34:11 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'AbuseFilter',
|
|
|
|
'history/'.$row->afh_filter.'/item/'.$row->afh_id );
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = $sk->link( $title, $wgLang->timeanddate( $row->afh_timestamp ) );
|
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_user_text':
|
2009-02-07 09:34:11 +00:00
|
|
|
$formatted =
|
|
|
|
$sk->userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
|
|
|
|
$sk->userToolLinks( $row->afh_user, $row->afh_user_text );
|
2009-01-26 22:31:02 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_public_comments':
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = $wgOut->parse( $value );
|
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_flags':
|
|
|
|
$flags = array_filter( explode( ',', $value ) );
|
|
|
|
$flags_display = array();
|
|
|
|
foreach( $flags as $flag ) {
|
|
|
|
$flags_display[] = wfMsg( "abusefilter-history-$flag" );
|
|
|
|
}
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = implode( ', ', $flags_display );
|
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_pattern':
|
2009-02-13 19:13:48 +00:00
|
|
|
$formatted = htmlspecialchars( $wgLang->truncate( $value, 200 ) );
|
2009-01-26 22:31:02 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_comments':
|
2009-02-13 19:13:48 +00:00
|
|
|
$formatted = htmlspecialchars( $wgLang->truncate( $value, 200 ) );
|
2009-01-26 22:31:02 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_actions':
|
|
|
|
$actions = unserialize( $value );
|
|
|
|
|
|
|
|
$display_actions = '';
|
|
|
|
|
|
|
|
foreach( $actions as $action => $parameters ) {
|
2009-02-07 09:34:11 +00:00
|
|
|
$display_actions .= Xml::tags(
|
|
|
|
'li', null,
|
|
|
|
wfMsgExt(
|
|
|
|
'abusefilter-history-action',
|
|
|
|
array( 'parseinline' ),
|
|
|
|
array(
|
|
|
|
AbuseFilter::getActionDisplay($action),
|
|
|
|
implode('; ', $parameters)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
$display_actions = Xml::tags( 'ul', null, $display_actions );
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = $display_actions;
|
|
|
|
break;
|
2009-01-26 18:50:20 +00:00
|
|
|
case 'afh_filter':
|
2009-01-26 22:31:02 +00:00
|
|
|
$title = $this->mPage->getTitle( strval($value) );
|
|
|
|
$formatted = $sk->link( $title, $value );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$formatted = "Unable to format $name";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$mappings = array_flip(AbuseFilter::$history_mappings) +
|
|
|
|
array( 'afh_actions' => 'actions' );
|
2009-01-26 22:31:02 +00:00
|
|
|
$changed = explode( ',', $row->afh_changed_fields );
|
|
|
|
|
|
|
|
$fieldChanged = false;
|
|
|
|
if ($name == 'afh_flags') {
|
2009-02-07 09:34:11 +00:00
|
|
|
// This is a bit freaky, but it works.
|
|
|
|
// Basically, returns true if any of those filters are in the $changed array.
|
|
|
|
$filters = array( 'af_enabled', 'af_hidden', 'af_deleted' );
|
|
|
|
if ( count( array_diff( $filters, $changed ) ) < 3 ) {
|
2009-01-26 22:31:02 +00:00
|
|
|
$fieldChanged = true;
|
|
|
|
}
|
|
|
|
} elseif ( in_array( $mappings[$name], $changed ) ) {
|
|
|
|
$fieldChanged = true;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
if ($fieldChanged) {
|
|
|
|
$formatted = Xml::tags( 'div',
|
|
|
|
array( 'class' => 'mw-abusefilter-history-changed' ),
|
|
|
|
$formatted );
|
|
|
|
}
|
2009-01-26 22:31:02 +00:00
|
|
|
|
|
|
|
return $formatted;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getQueryInfo() {
|
2009-01-26 18:50:20 +00:00
|
|
|
$info = array(
|
2009-01-23 19:23:19 +00:00
|
|
|
'tables' => 'abuse_filter_history',
|
2009-02-07 09:34:11 +00:00
|
|
|
'fields' => array(
|
|
|
|
'afh_filter',
|
|
|
|
'afh_timestamp',
|
|
|
|
'afh_user_text',
|
|
|
|
'afh_public_comments',
|
|
|
|
'afh_flags',
|
|
|
|
'afh_comments',
|
|
|
|
'afh_actions',
|
|
|
|
'afh_id',
|
|
|
|
'afh_user',
|
|
|
|
'afh_changed_fields' ),
|
|
|
|
'conds' => array(),
|
2009-01-23 19:23:19 +00:00
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
global $wgRequest;
|
|
|
|
if ($this->mUser) {
|
|
|
|
$info['conds']['afh_user_text'] = $this->mUser;
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
if ( $this->mFilter ) {
|
|
|
|
$info['fields'][] = 'afh_pattern';
|
|
|
|
$info['conds']['afh_filter'] = $this->mFilter;
|
|
|
|
}
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
return $info;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIndexField() {
|
|
|
|
return 'afh_timestamp';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDefaultSort() {
|
|
|
|
return 'afh_timestamp';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isFieldSortable($name) {
|
|
|
|
$sortable_fields = array( 'afh_timestamp', 'afh_user_text' );
|
|
|
|
return in_array( $name, $sortable_fields );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title used for self-links. Override this if you want to be able to
|
|
|
|
* use a title other than $wgTitle
|
|
|
|
*/
|
|
|
|
function getTitle() {
|
|
|
|
return $this->mPage->getTitle( "history/".$this->mFilter );
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|