2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
die();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
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 ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->setPageTitle( wfMsg( 'abusefilter-history', $filter ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->setPageTitle( wfMsg( '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
|
2011-11-16 05:34:24 +00:00
|
|
|
$sk = $this->getSkin();
|
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 ) {
|
2009-01-26 18:50:20 +00:00
|
|
|
$links[$msg] = $sk->link( $title, wfMsgExt( $msg, 'parseinline' ) );
|
|
|
|
}
|
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
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getRequest()->getText( 'user' );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $user ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->setSubtitle(
|
2009-10-07 13:57:06 +00:00
|
|
|
wfMsg(
|
|
|
|
'abusefilter-history-foruser',
|
2009-03-17 13:18:33 +00:00
|
|
|
$sk->userLink( 1 /* We don't really need to get a user ID */, $user ),
|
|
|
|
$user // For GENDER
|
2010-02-13 14:10:36 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add filtering of changes et al.
|
2009-07-17 14:03:11 +00:00
|
|
|
$fields['abusefilter-history-select-user'] = Xml::input( 'user', 45, $user );
|
2009-01-26 18:50:20 +00:00
|
|
|
|
|
|
|
$filterForm = Xml::buildForm( $fields, 'abusefilter-history-select-submit' );
|
2010-10-29 15:14:44 +00:00
|
|
|
$filterForm .= "\n" . Html::hidden( 'title', $this->getTitle( "history/$filter" ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
$filterForm = Xml::tags( 'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( "history/$filter" )->getLocalURL(),
|
|
|
|
'method' => 'get'
|
|
|
|
),
|
|
|
|
$filterForm
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-26 18:50:20 +00:00
|
|
|
$filterForm = Xml::fieldset( wfMsg( 'abusefilter-history-select-legend' ), $filterForm );
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $filterForm );
|
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
|
|
|
|
* @param $page Article
|
|
|
|
* @param $user User
|
|
|
|
*/
|
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',
|
2009-10-07 13:57:06 +00:00
|
|
|
'afh_id' => 'abusefilter-history-diff'
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$headers = array_map( 'wfMsg', $headers );
|
|
|
|
|
|
|
|
return $headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatValue( $name, $value ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$sk = $this->getSkin();
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$row = $this->mCurrentRow;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
switch( $name ) {
|
2011-10-17 07:56:05 +00:00
|
|
|
case 'afh_filter':
|
2011-11-16 05:34:24 +00:00
|
|
|
$formatted = $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 );
|
2011-11-16 05:34:24 +00:00
|
|
|
$formatted = $sk->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 =
|
|
|
|
$sk->userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
|
2009-02-07 09:34:11 +00:00
|
|
|
$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':
|
2011-11-16 05:34:24 +00:00
|
|
|
$formatted = $this->getOutput()->parse( $value );
|
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-01-26 18:50:20 +00:00
|
|
|
case 'afh_filter':
|
2009-10-07 13:57:06 +00:00
|
|
|
$title = $this->mPage->getTitle( strval( $value ) );
|
2009-01-26 22:31:02 +00:00
|
|
|
$formatted = $sk->link( $title, $value );
|
|
|
|
break;
|
2009-03-12 05:04:39 +00:00
|
|
|
case 'afh_id':
|
2010-02-13 14:10:36 +00:00
|
|
|
$title = $this->mPage->getTitle(
|
2009-10-07 13:57:06 +00:00
|
|
|
'history/' . $row->afh_filter . "/diff/prev/$value" );
|
2009-03-12 05:04:39 +00:00
|
|
|
$formatted = $sk->link( $title, wfMsgExt( 'abusefilter-history-diff', 'parseinline' ) );
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title used for self-links. Override this if you want to be able to
|
|
|
|
* use a title other than $wgTitle
|
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
|
|
|
}
|