2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewHistory extends AbuseFilterView {
|
|
|
|
function __construct( $page, $params ) {
|
|
|
|
parent::__construct( $page, $params );
|
|
|
|
$this->mFilter = $page->mFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2009-01-23 19:23:19 +00:00
|
|
|
$filter = $this->mFilter;
|
2009-01-26 18:50:20 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $filter ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-history', $filter ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2012-09-02 11:07:02 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-filter-log' ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
# Check perms
|
2009-03-17 13:18:33 +00:00
|
|
|
if ( $filter &&
|
2011-11-16 05:34:24 +00:00
|
|
|
!$this->getUser()->isAllowed( 'abusefilter-modify' ) &&
|
2009-03-17 13:18:33 +00:00
|
|
|
AbuseFilter::filterHidden( $filter ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-history-error-hidden' );
|
2009-03-17 13:18:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-03-06 10:56:37 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
# Useful links
|
2009-01-26 18:50:20 +00:00
|
|
|
$links = array();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $filter ) {
|
2009-01-26 18:50:20 +00:00
|
|
|
$links['abusefilter-history-backedit'] = $this->getTitle( $filter );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-26 18:50:20 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $links as $msg => $title ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$links[$msg] = Linker::link( $title, $this->msg( $msg )->parse() );
|
2009-01-26 18:50:20 +00:00
|
|
|
}
|
2009-03-06 10:56:37 +00:00
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$backlinks = $this->getLanguage()->pipeList( $links );
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( Xml::tags( 'p', null, $backlinks ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
# For user
|
2013-04-07 23:07:16 +00:00
|
|
|
$user = User::getCanonicalName( $this->getRequest()->getText( 'user' ), 'valid' );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $user ) {
|
2013-04-07 23:07:16 +00:00
|
|
|
$out->addSubtitle(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-history-foruser',
|
2012-09-02 11:07:02 +00:00
|
|
|
Linker::userLink( 1 /* We don't really need to get a user ID */, $user ),
|
2009-03-17 13:18:33 +00:00
|
|
|
$user // For GENDER
|
2013-04-07 23:07:16 +00:00
|
|
|
)->text()
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 08:22:26 +00:00
|
|
|
$formDescriptor = array(
|
|
|
|
'user' => array(
|
|
|
|
'type' => 'user',
|
|
|
|
'name' => 'user',
|
|
|
|
'default' => $user,
|
|
|
|
'size' => '45',
|
|
|
|
'label-message' => 'abusefilter-history-select-user'
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2016-04-14 08:22:26 +00:00
|
|
|
|
|
|
|
$htmlForm = HTMLForm::factory( 'table', $formDescriptor, $this->getContext() );
|
|
|
|
$htmlForm->setSubmitTextMsg( 'abusefilter-history-select-submit' )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-history-select-legend' )
|
|
|
|
->setAction( $this->getTitle( "history/$filter" )->getLocalURL() )
|
|
|
|
->setMethod( 'get' )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
$pager = new AbuseFilterHistoryPager( $filter, $this, $user );
|
2009-01-23 19:23:19 +00:00
|
|
|
$table = $pager->getBody();
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $pager->getNavigationBar() . $table . $pager->getNavigationBar() );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AbuseFilterHistoryPager extends TablePager {
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* @param $filter
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $page ContextSource
|
|
|
|
* @param $user string User name
|
2011-08-24 22:11:52 +00:00
|
|
|
*/
|
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;
|
2011-11-16 05:34:24 +00:00
|
|
|
parent::__construct( $this->mPage->getContext() );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFieldNames() {
|
|
|
|
static $headers = null;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !empty( $headers ) ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$headers = array(
|
2009-10-07 13:57:06 +00:00
|
|
|
'afh_timestamp' => 'abusefilter-history-timestamp',
|
|
|
|
'afh_user_text' => 'abusefilter-history-user',
|
2009-02-07 09:34:11 +00:00
|
|
|
'afh_public_comments' => 'abusefilter-history-public',
|
2009-10-07 13:57:06 +00:00
|
|
|
'afh_flags' => 'abusefilter-history-flags',
|
2009-03-12 05:04:39 +00:00
|
|
|
'afh_actions' => 'abusefilter-history-actions',
|
2012-05-06 06:44:45 +00:00
|
|
|
'afh_id' => 'abusefilter-history-diff',
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$this->mFilter ) {
|
2009-01-26 18:50:20 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-10-09 21:49:56 +00:00
|
|
|
foreach ( $headers as &$msg ) {
|
|
|
|
$msg = $this->msg( $msg )->text();
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatValue( $name, $value ) {
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$row = $this->mCurrentRow;
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $name ) {
|
2011-10-17 07:56:05 +00:00
|
|
|
case 'afh_filter':
|
2014-11-17 17:44:20 +00:00
|
|
|
$formatted = Linker::link(
|
2015-09-28 18:03:35 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseFilter', intval( $row->afh_filter ) ),
|
|
|
|
$lang->formatNum( $row->afh_filter )
|
|
|
|
);
|
2011-10-17 07:56:05 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_timestamp':
|
2010-02-13 14:10:36 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'AbuseFilter',
|
2009-10-07 13:57:06 +00:00
|
|
|
'history/' . $row->afh_filter . '/item/' . $row->afh_id );
|
2012-03-11 20:51:54 +00:00
|
|
|
$formatted = Linker::link( $title, $lang->timeanddate( $row->afh_timestamp, true ) );
|
2009-01-26 22:31:02 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_user_text':
|
2009-10-07 13:57:06 +00:00
|
|
|
$formatted =
|
2013-06-26 22:58:36 +00:00
|
|
|
Linker::userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
|
|
|
|
Linker::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':
|
2013-02-03 15:50:13 +00:00
|
|
|
$formatted = htmlspecialchars( $value, ENT_QUOTES, 'UTF-8', false );
|
2009-01-26 22:31:02 +00:00
|
|
|
break;
|
2009-01-23 19:23:19 +00:00
|
|
|
case 'afh_flags':
|
2009-03-12 05:04:39 +00:00
|
|
|
$formatted = AbuseFilter::formatFlags( $value );
|
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 = '';
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action => $parameters ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$displayAction = AbuseFilter::formatAction( $action, $parameters );
|
2009-03-06 10:56:37 +00:00
|
|
|
$display_actions .= Xml::tags( 'li', null, $displayAction );
|
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-03-12 05:04:39 +00:00
|
|
|
case 'afh_id':
|
2012-12-30 03:59:33 +00:00
|
|
|
$formatted = '';
|
|
|
|
if ( AbuseFilter::getFirstFilterChange( $row->afh_filter ) != $value ) {
|
|
|
|
// Set a link to a diff with the previous version if this isn't the first edit to the filter
|
|
|
|
$title = $this->mPage->getTitle(
|
|
|
|
'history/' . $row->afh_filter . "/diff/prev/$value" );
|
|
|
|
$formatted = Linker::link( $title, $this->msg( 'abusefilter-history-diff' )->parse() );
|
|
|
|
}
|
2009-03-12 05:04:39 +00:00
|
|
|
break;
|
2009-01-26 22:31:02 +00:00
|
|
|
default:
|
|
|
|
$formatted = "Unable to format $name";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$mappings = array_flip( AbuseFilter::$history_mappings ) +
|
2009-03-12 05:04:39 +00:00
|
|
|
array( 'afh_actions' => 'actions', 'afh_id' => 'id' );
|
2009-01-26 22:31:02 +00:00
|
|
|
$changed = explode( ',', $row->afh_changed_fields );
|
|
|
|
|
|
|
|
$fieldChanged = false;
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $name == 'afh_flags' ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
// This is a bit freaky, but it works.
|
2009-02-07 09:34:11 +00:00
|
|
|
// Basically, returns true if any of those filters are in the $changed array.
|
2009-03-30 06:12:12 +00:00
|
|
|
$filters = array( 'af_enabled', 'af_hidden', 'af_deleted', 'af_global' );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( array_diff( $filters, $changed ) ) < count( $filters ) ) {
|
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-10-07 13:57:06 +00:00
|
|
|
if ( $fieldChanged ) {
|
|
|
|
$formatted = Xml::tags( 'div',
|
|
|
|
array( 'class' => 'mw-abusefilter-history-changed' ),
|
|
|
|
$formatted
|
|
|
|
);
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|
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-03-17 13:18:33 +00:00
|
|
|
'tables' => array( 'abuse_filter_history', 'abuse_filter' ),
|
2009-10-07 13:57:06 +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',
|
|
|
|
'afh_pattern',
|
|
|
|
'afh_id',
|
|
|
|
'af_hidden'
|
|
|
|
),
|
2009-02-07 09:34:11 +00:00
|
|
|
'conds' => array(),
|
2009-03-17 13:18:33 +00:00
|
|
|
'join_conds' => array(
|
|
|
|
'abuse_filter' =>
|
|
|
|
array(
|
|
|
|
'LEFT JOIN',
|
|
|
|
'afh_filter=af_id',
|
|
|
|
),
|
|
|
|
),
|
2009-01-23 19:23:19 +00:00
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mUser ) {
|
2009-01-26 18:50:20 +00:00
|
|
|
$info['conds']['afh_user_text'] = $this->mUser;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
if ( $this->mFilter ) {
|
|
|
|
$info['conds']['afh_filter'] = $this->mFilter;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
2009-03-17 13:18:33 +00:00
|
|
|
// Hide data the user can't see.
|
|
|
|
$info['conds']['af_hidden'] = 0;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
function isFieldSortable( $name ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$sortable_fields = array( 'afh_timestamp', 'afh_user_text' );
|
|
|
|
return in_array( $name, $sortable_fields );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-23 04:46:49 +00:00
|
|
|
* Title used for self-links.
|
2011-08-24 22:11:52 +00:00
|
|
|
*
|
|
|
|
* @return Title
|
2009-01-23 19:23:19 +00:00
|
|
|
*/
|
|
|
|
function getTitle() {
|
2009-10-07 13:57:06 +00:00
|
|
|
return $this->mPage->getTitle( 'history/' . $this->mFilter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|