mediawiki-extensions-AbuseF.../special/SpecialAbuseLog.php

549 lines
13 KiB
PHP
Raw Normal View History

2008-06-27 06:18:51 +00:00
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
2008-06-27 06:18:51 +00:00
die();
}
2008-06-27 06:18:51 +00:00
class SpecialAbuseLog extends SpecialPage {
/**
* @var User
*/
protected $mSearchUser;
/**
* @var Title
*/
protected $mSearchTitle;
protected $mSearchFilter;
public function __construct() {
2008-06-27 06:18:51 +00:00
parent::__construct( 'AbuseLog', 'abusefilter-log' );
}
public function execute( $parameter ) {
global $wgUser, $wgOut, $wgRequest;
AbuseFilter::addNavigationLinks( $wgOut, $wgUser->getSkin(), 'log' );
2008-06-27 06:18:51 +00:00
$this->setHeaders();
2009-02-27 09:12:25 +00:00
$this->outputHeader( 'abusefilter-log-summary' );
2008-06-27 06:18:51 +00:00
$this->loadParameters();
$wgOut->setPageTitle( wfMsg( 'abusefilter-log' ) );
$wgOut->setRobotPolicy( "noindex,nofollow" );
2008-06-27 06:18:51 +00:00
$wgOut->setArticleRelated( false );
$wgOut->enableClientCache( false );
$wgOut->addModuleStyles( 'ext.abuseFilter' );
2008-06-27 06:18:51 +00:00
// Are we allowed?
$errors = $this->getTitle()->getUserPermissionsErrors(
'abusefilter-log', $wgUser, true, array( 'ns-specialprotected' ) );
if ( count( $errors ) ) {
2008-06-27 06:18:51 +00:00
// Go away.
$wgOut->showPermissionsErrorPage( $errors, 'abusefilter-log' );
return;
}
$detailsid = $wgRequest->getIntOrNull( 'details' );
$hideid = $wgRequest->getIntOrNull( 'hide' );
if ( $parameter ) {
$detailsid = $parameter;
}
2009-05-22 06:42:10 +00:00
if ( $detailsid ) {
$this->showDetails( $detailsid );
} elseif ( $hideid ) {
$this->showHideForm( $hideid );
} else {
// Show the search form.
$this->searchForm();
// Show the log itself.
$this->showList();
}
2008-06-27 06:18:51 +00:00
}
2008-06-27 06:18:51 +00:00
function loadParameters() {
global $wgRequest;
2008-06-27 06:18:51 +00:00
$this->mSearchUser = $wgRequest->getText( 'wpSearchUser' );
$t = Title::newFromText( trim( $this->mSearchUser ) );
2009-05-22 06:42:10 +00:00
if ( $t ) {
$this->mSearchUser = $t->getText(); // Username normalisation
2009-05-22 06:42:10 +00:00
} else {
$this->mSearchUser = null;
}
2008-06-27 06:18:51 +00:00
$this->mSearchTitle = $wgRequest->getText( 'wpSearchTitle' );
$this->mSearchFilter = null;
if ( self::canSeeDetails() ) {
2008-06-27 06:18:51 +00:00
$this->mSearchFilter = $wgRequest->getIntOrNull( 'wpSearchFilter' );
2009-05-22 06:42:10 +00:00
}
2008-06-27 06:18:51 +00:00
}
2008-06-27 06:18:51 +00:00
function searchForm() {
2010-07-24 21:12:27 +00:00
global $wgOut;
2008-06-27 06:18:51 +00:00
$output = Xml::element( 'legend', null, wfMsg( 'abusefilter-log-search' ) );
$fields = array();
2008-06-27 06:18:51 +00:00
// Search conditions
$fields['abusefilter-log-search-user'] =
Xml::input( 'wpSearchUser', 45, $this->mSearchUser );
if ( self::canSeeDetails() ) {
$fields['abusefilter-log-search-filter'] =
Xml::input( 'wpSearchFilter', 45, $this->mSearchFilter );
}
$fields['abusefilter-log-search-title'] =
Xml::input( 'wpSearchTitle', 45, $this->mSearchTitle );
$form = Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
2008-06-27 06:18:51 +00:00
$form .= Xml::buildForm( $fields, 'abusefilter-log-search-submit' );
$output .= Xml::tags( 'form',
array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL() ),
$form );
2008-06-27 06:18:51 +00:00
$output = Xml::tags( 'fieldset', null, $output );
2008-11-06 22:20:29 +00:00
$wgOut->addHTML( $output );
2008-06-27 06:18:51 +00:00
}
function showHideForm( $id ) {
global $wgOut, $wgUser;
if ( !$wgUser->isAllowed( 'abusefilter-hide-log' ) ) {
$wgOut->addWikiMsg( 'abusefilter-log-hide-forbidden' );
return;
}
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
array( 'abuse_filter_log', 'abuse_filter' ),
'*',
array( 'afl_id' => $id ),
__METHOD__,
array(),
array( 'abuse_filter' => array( 'LEFT JOIN', 'af_id=afl_filter' ) )
);
if ( !$row ) {
return;
}
$formInfo = array(
'logid' => array(
'type' => 'info',
'default' => $id,
'label-message' => 'abusefilter-log-hide-id',
),
'reason' => array(
'type' => 'text',
'label-message' => 'abusefilter-log-hide-reason',
),
'hidden' => array(
'type' => 'toggle',
'default' => $row->afl_deleted,
'label-message' => 'abusefilter-log-hide-hidden',
),
);
$form = new HTMLForm( $formInfo );
$form->setTitle( $this->getTitle() );
2010-08-29 11:32:49 +00:00
$form->setWrapperLegend( wfMsgExt( 'abusefilter-log-hide-legend', 'parsemag' ) );
$form->addHiddenField( 'hide', $id );
$form->setSubmitCallback( array( $this, 'saveHideForm' ) );
$form->show();
}
function saveHideForm( $fields ) {
global $wgRequest, $wgOut;
$logid = $wgRequest->getVal( 'hide' );
$dbw = wfGetDB( DB_MASTER );
$dbw->update(
'abuse_filter_log',
array( 'afl_deleted' => $fields['hidden'] ),
array( 'afl_id' => $logid ),
__METHOD__
);
$logPage = new LogPage( 'suppress' );
$action = $fields['hidden'] ? 'hide-afl' : 'unhide-afl';
$logPage->addEntry( $action, $this->getTitle( $logid ), $fields['reason'] );
$wgOut->redirect( SpecialPage::getTitleFor( 'AbuseLog' )->getFullURL() );
return true;
}
2008-06-27 06:18:51 +00:00
function showList() {
global $wgOut;
2008-06-27 06:18:51 +00:00
// Generate conditions list.
$conds = array();
if ( $this->mSearchUser ) {
$user = User::newFromName( $this->mSearchUser );
if ( !$user ) {
$conds[] = 'afl_ip=afl_user_text';
$conds['afl_user'] = 0;
$conds['afl_user_text'] = $this->mSearchUser;
} else {
$conds['afl_user'] = $user->getId();
$conds['afl_user_text'] = $user->getName();
}
2009-05-22 06:42:10 +00:00
}
if ( $this->mSearchFilter ) {
2008-06-27 06:18:51 +00:00
$conds['afl_filter'] = $this->mSearchFilter;
2009-05-22 06:42:10 +00:00
}
2008-06-27 06:18:51 +00:00
$searchTitle = Title::newFromText( $this->mSearchTitle );
2009-05-22 06:42:10 +00:00
if ( $this->mSearchTitle && $searchTitle ) {
2008-06-27 06:18:51 +00:00
$conds['afl_namespace'] = $searchTitle->getNamespace();
2009-05-24 08:33:57 +00:00
$conds['afl_title'] = $searchTitle->getDBkey();
2008-06-27 06:18:51 +00:00
}
2008-06-27 06:18:51 +00:00
$pager = new AbuseLogPager( $this, $conds );
$pager->doQuery();
$result = $pager->getResult();
if( $result && $result->numRows() !== 0 ) {
$wgOut->addHTML( $pager->getNavigationBar() .
Xml::tags( 'ul', null, $pager->getBody() ) .
$pager->getNavigationBar() );
} else {
$wgOut->addWikiMsg( 'abusefilter-log-noresults' );
}
2008-06-27 06:18:51 +00:00
}
2008-06-27 06:18:51 +00:00
function showDetails( $id ) {
if ( !self::canSeeDetails() ) {
2008-06-27 06:18:51 +00:00
return;
}
2008-06-27 06:18:51 +00:00
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
array( 'abuse_filter_log', 'abuse_filter' ),
'*',
array( 'afl_id' => $id ),
__METHOD__,
array(),
array( 'abuse_filter' => array( 'LEFT JOIN', 'af_id=afl_filter' ) )
);
2009-05-22 06:42:10 +00:00
if ( !$row ) {
2008-06-27 06:18:51 +00:00
return;
2009-05-22 06:42:10 +00:00
}
if ( $row->afl_deleted && !self::canSeeHidden() ) {
global $wgOut;
$wgOut->addWikiMsg( 'abusefilter-log-details-hidden' );
return;
}
2008-06-27 06:18:51 +00:00
$output = '';
2008-06-27 06:18:51 +00:00
$output .= Xml::element( 'legend', null, wfMsg( 'abusefilter-log-details-legend', $id ) );
$output .= Xml::tags( 'p', null, $this->formatRow( $row, false ) );
// Load data
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
// Diff, if available
if ( $vars->getVar( 'action' )->toString() == 'edit' ) {
$old_wikitext = $vars->getVar( 'old_wikitext' )->toString();
$new_wikitext = $vars->getVar( 'new_wikitext' )->toString();
$diffEngine = new DifferenceEngine;
$diffEngine->showDiffStyle();
$formattedDiff = $diffEngine->generateDiffBody( $old_wikitext, $new_wikitext );
static $colDescriptions = "<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />";
$formattedDiff =
"<table class='diff'>$colDescriptions<tbody>$formattedDiff</tbody></table>";
$output .=
Xml::tags(
'h3',
null,
wfMsgExt( 'abusefilter-log-details-diff', 'parseinline' )
);
$output .= $formattedDiff;
}
$output .= Xml::element( 'h3', null, wfMsg( 'abusefilter-log-details-vars' ) );
// Build a table.
$output .= AbuseFilter::buildVarDumpTable( $vars );
if ( self::canSeePrivate() ) {
2008-06-27 08:11:09 +00:00
// Private stuff, like IPs.
$header =
Xml::element( 'th', null, wfMsg( 'abusefilter-log-details-var' ) ) .
Xml::element( 'th', null, wfMsg( 'abusefilter-log-details-val' ) );
2008-06-27 08:11:09 +00:00
$output .= Xml::element( 'h3', null, wfMsg( 'abusefilter-log-details-private' ) );
$output .=
Xml::openElement( 'table',
array(
'class' => 'wikitable mw-abuselog-private',
'style' => 'width: 80%;'
)
) .
Xml::openElement( 'tbody' );
2008-06-27 08:11:09 +00:00
$output .= $header;
2008-06-27 08:11:09 +00:00
// IP address
$output .=
Xml::tags( 'tr', null,
Xml::element( 'td',
array( 'style' => 'width: 30%;' ),
wfMsg( 'abusefilter-log-details-ip' )
) .
Xml::element( 'td', null, $row->afl_ip )
);
2008-06-27 08:11:09 +00:00
$output .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
}
2008-06-27 06:18:51 +00:00
$output = Xml::tags( 'fieldset', null, $output );
2008-06-27 06:18:51 +00:00
global $wgOut;
$wgOut->addHTML( $output );
}
/**
* @return bool
*/
static function canSeeDetails() {
2008-06-27 06:18:51 +00:00
global $wgUser;
return $wgUser->isAllowed( 'abusefilter-log-detail' );
2008-06-27 06:18:51 +00:00
}
/**
* @return bool
*/
static function canSeePrivate() {
global $wgUser;
return $wgUser->isAllowed( 'abusefilter-private' );
}
/**
* @return bool
*/
static function canSeeHidden() {
2008-06-27 08:11:09 +00:00
global $wgUser;
return $wgUser->isAllowed( 'abusefilter-hidden-log' );
2008-06-27 08:11:09 +00:00
}
function formatRow( $row, $li = true ) {
global $wgLang, $wgUser;
# One-time setup
static $sk = null;
$actionLinks = array();
2009-05-22 06:42:10 +00:00
if ( is_null( $sk ) ) {
2008-06-27 06:18:51 +00:00
$sk = $wgUser->getSkin();
}
2008-06-27 06:18:51 +00:00
$title = Title::makeTitle( $row->afl_namespace, $row->afl_title );
2009-05-22 06:42:10 +00:00
if ( !$row->afl_wiki ) {
$pageLink = $sk->link( $title );
} else {
$pageLink = WikiMap::makeForeignLink( $row->afl_wiki, $row->afl_title );
}
2009-05-22 06:42:10 +00:00
if ( !$row->afl_wiki ) {
// Local user
$user = $sk->userLink( $row->afl_user, $row->afl_user_text ) .
$sk->userToolLinks( $row->afl_user, $row->afl_user_text );
} else {
$user = WikiMap::foreignUserLink( $row->afl_wiki, $row->afl_user_text );
$user .= ' (' . WikiMap::getWikiName( $row->afl_wiki ) . ')';
}
$timestamp = $wgLang->timeanddate( $row->afl_timestamp, true );
2008-06-27 06:18:51 +00:00
$actions_taken = $row->afl_actions;
2009-05-22 06:42:10 +00:00
if ( !strlen( trim( $actions_taken ) ) ) {
2008-06-27 06:18:51 +00:00
$actions_taken = wfMsg( 'abusefilter-log-noactions' );
} else {
2009-05-22 06:42:10 +00:00
$actions = explode( ',', $actions_taken );
$displayActions = array();
foreach ( $actions as $action ) {
$displayActions[] = AbuseFilter::getActionDisplay( $action );
}
2010-03-13 17:23:08 +00:00
$actions_taken = $wgLang->commaList( $displayActions );
2008-06-27 06:18:51 +00:00
}
$globalIndex = AbuseFilter::decodeGlobalName( $row->afl_filter );
global $wgOut;
2009-05-22 06:42:10 +00:00
if ( $globalIndex ) {
// Pull global filter description
$parsed_comments =
$wgOut->parseInline( AbuseFilter::getGlobalFilterDescription( $globalIndex ) );
} else {
$parsed_comments = $wgOut->parseInline( $row->af_public_comments );
}
if ( self::canSeeDetails() ) {
$examineTitle = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/log/' . $row->afl_id );
$detailsLink = $sk->makeKnownLinkObj(
$this->getTitle($row->afl_id),
wfMsg( 'abusefilter-log-detailslink' )
);
$examineLink = $sk->link(
$examineTitle,
wfMsgExt( 'abusefilter-changeslist-examine', 'parseinline' ),
array()
);
$actionLinks[] = $detailsLink;
$actionLinks[] = $examineLink;
if ( $wgUser->isAllowed( 'abusefilter-hide-log' ) ) {
$hideLink = $sk->link(
$this->getTitle(),
wfMsg( 'abusefilter-log-hidelink' ),
array(),
array( 'hide' => $row->afl_id )
);
$actionLinks[] = $hideLink;
}
2009-05-22 06:42:10 +00:00
if ( $globalIndex ) {
global $wgAbuseFilterCentralDB;
$globalURL =
WikiMap::getForeignURL( $wgAbuseFilterCentralDB,
'Special:AbuseFilter/' . $globalIndex );
$linkText = wfMessage( 'abusefilter-log-detailedentry-global' )->numParams( $globalIndex )->escaped();
$filterLink = $sk->makeExternalLink( $globalURL, $linkText );
} else {
$title = SpecialPage::getTitleFor( 'AbuseFilter', $row->afl_filter );
$linkText = wfMessage( 'abusefilter-log-detailedentry-local' )->numParams( $row->afl_filter )->escaped();
$filterLink = $sk->link( $title, $linkText );
}
$description = wfMsgExt( 'abusefilter-log-detailedentry-meta',
array( 'parseinline', 'replaceafter' ),
array(
$timestamp,
$user,
$filterLink,
$row->afl_action,
$pageLink,
$actions_taken,
$parsed_comments,
$wgLang->pipeList( $actionLinks ),
)
);
2008-06-27 06:18:51 +00:00
} else {
$description = wfMsgExt(
'abusefilter-log-entry',
array( 'parseinline', 'replaceafter' ),
array(
$timestamp,
$user,
$row->afl_action,
$sk->link( $title ),
$actions_taken,
$parsed_comments
)
);
2008-06-27 06:18:51 +00:00
}
if ( $row->afl_deleted ) {
$description .= ' '.
wfMsgExt( 'abusefilter-log-hidden', 'parseinline' );
}
return $li ? Xml::tags( 'li', null, $description ) : $description;
2008-06-27 06:18:51 +00:00
}
/**
* @param $db DatabaseBase
* @return string
*/
public static function getNotDeletedCond( $db ) {
$deletedZeroCond = $db->makeList(
array( 'afl_deleted' => 0 ), LIST_AND );
$deletedNullCond = $db->makeList(
array( 'afl_deleted' => null ), LIST_AND );
$notDeletedCond = $db->makeList(
array( $deletedZeroCond, $deletedNullCond ), LIST_OR );
return $notDeletedCond;
}
2008-06-27 06:18:51 +00:00
}
class AbuseLogPager extends ReverseChronologicalPager {
/**
* @var HtmlForm
*/
public $mForm;
/**
* @var array
*/
public $mConds;
2008-06-27 06:18:51 +00:00
function __construct( $form, $conds = array(), $details = false ) {
$this->mForm = $form;
$this->mConds = $conds;
parent::__construct();
}
function formatRow( $row ) {
return $this->mForm->formatRow( $row );
}
function getQueryInfo() {
$conds = $this->mConds;
$info = array(
'tables' => array( 'abuse_filter_log', 'abuse_filter' ),
2008-06-27 06:18:51 +00:00
'fields' => '*',
'conds' => $conds,
'join_conds' =>
array( 'abuse_filter' =>
array(
'LEFT JOIN',
'af_id=afl_filter',
),
),
2008-06-27 06:18:51 +00:00
);
if ( !$this->mForm->canSeeHidden() ) {
$db = $this->mDb;
$info['conds'][] = SpecialAbuseLog::getNotDeletedCond($db);
}
return $info;
2008-06-27 06:18:51 +00:00
}
function getIndexField() {
return 'afl_timestamp';
}
}