2009-03-12 05:04:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewDiff extends AbuseFilterView {
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var array|null The old version of the filter
|
|
|
|
*/
|
2013-10-15 12:35:03 +00:00
|
|
|
public $mOldVersion = null;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var array|null The new version of the filter
|
|
|
|
*/
|
2013-10-15 12:35:03 +00:00
|
|
|
public $mNewVersion = null;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var int|null The history ID of the next version, if any
|
|
|
|
*/
|
2013-10-15 12:35:03 +00:00
|
|
|
public $mNextHistoryId = null;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var int|null The ID of the filter
|
|
|
|
*/
|
2013-10-15 12:35:03 +00:00
|
|
|
public $mFilter = null;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public function show() {
|
2009-03-12 05:04:39 +00:00
|
|
|
$show = $this->loadData();
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2018-04-24 09:35:07 +00:00
|
|
|
$out->enableOOUI();
|
2018-05-01 12:55:35 +00:00
|
|
|
$out->addModuleStyles( [ 'oojs-ui.styles.icons-movement' ] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$links = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mFilter ) {
|
2018-04-24 09:35:07 +00:00
|
|
|
$links['abusefilter-history-backedit'] =
|
|
|
|
$this->getTitle( $this->mFilter )->getFullURL();
|
|
|
|
$links['abusefilter-diff-backhistory'] =
|
|
|
|
$this->getTitle( 'history/' . $this->mFilter )->getFullURL();
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 09:35:07 +00:00
|
|
|
foreach ( $links as $msg => $href ) {
|
|
|
|
$links[$msg] =
|
|
|
|
new OOUI\ButtonWidget( [
|
|
|
|
'label' => $this->msg( $msg )->text(),
|
|
|
|
'href' => $href
|
|
|
|
] );
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-24 09:35:07 +00:00
|
|
|
$backlinks =
|
|
|
|
new OOUI\HorizontalLayout( [
|
|
|
|
'items' => $links
|
|
|
|
] );
|
|
|
|
$out->addHTML( $backlinks );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $show ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $this->formatDiff() );
|
2012-12-30 03:59:33 +00:00
|
|
|
// Next and previous change links
|
2018-05-01 12:55:35 +00:00
|
|
|
$buttons = [];
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( AbuseFilter::getFirstFilterChange( $this->mFilter ) !=
|
|
|
|
$this->mOldVersion['meta']['history_id']
|
|
|
|
) {
|
2012-12-30 03:59:33 +00:00
|
|
|
// Create a "previous change" link if this isn't the first change of the given filter
|
2018-05-01 12:55:35 +00:00
|
|
|
$href = $this->getTitle(
|
|
|
|
'history/' . $this->mFilter . '/diff/prev/' . $this->mOldVersion['meta']['history_id']
|
|
|
|
)->getFullURL();
|
|
|
|
$buttons[] = new OOUI\ButtonWidget( [
|
|
|
|
'label' => $this->msg( 'abusefilter-diff-prev' )->text(),
|
|
|
|
'href' => $href,
|
|
|
|
'icon' => 'previous'
|
|
|
|
] );
|
2012-12-30 03:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !is_null( $this->mNextHistoryId ) ) {
|
|
|
|
// Create a "next change" link if this isn't the last change of the given filter
|
2018-05-01 12:55:35 +00:00
|
|
|
$href = $this->getTitle(
|
|
|
|
'history/' . $this->mFilter . '/diff/prev/' . $this->mNextHistoryId
|
|
|
|
)->getFullURL();
|
|
|
|
$buttons[] = new OOUI\ButtonWidget( [
|
|
|
|
'label' => $this->msg( 'abusefilter-diff-next' )->text(),
|
|
|
|
'href' => $href,
|
|
|
|
'icon' => 'next'
|
|
|
|
] );
|
2012-12-30 03:59:33 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 12:55:35 +00:00
|
|
|
if ( count( $buttons ) > 0 ) {
|
|
|
|
$buttons = new OOUI\HorizontalLayout( [
|
|
|
|
'items' => $buttons,
|
|
|
|
'classes' => [ 'mw-abusefilter-history-buttons' ]
|
|
|
|
] );
|
|
|
|
$out->addHTML( $buttons );
|
2012-12-30 03:59:33 +00:00
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function loadData() {
|
2009-03-12 05:04:39 +00:00
|
|
|
$oldSpec = $this->mParams[3];
|
|
|
|
$newSpec = $this->mParams[4];
|
|
|
|
$this->mFilter = $this->mParams[1];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-03-28 19:59:53 +00:00
|
|
|
if ( !is_numeric( $this->mFilter ) ) {
|
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-26 16:13:55 +00:00
|
|
|
if ( AbuseFilter::filterHidden( $this->mFilter )
|
2019-08-27 10:08:17 +00:00
|
|
|
&& !AbuseFilter::canViewPrivate( $this->getUser() )
|
2016-04-26 16:13:55 +00:00
|
|
|
) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-history-error-hidden' );
|
2011-07-14 04:57:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$this->mOldVersion = $this->loadSpec( $oldSpec, $newSpec );
|
|
|
|
$this->mNewVersion = $this->loadSpec( $newSpec, $oldSpec );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( is_null( $this->mOldVersion ) || is_null( $this->mNewVersion ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' );
|
2009-03-12 05:04:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
$this->mNextHistoryId = $this->getNextHistoryId(
|
2016-12-02 18:22:48 +00:00
|
|
|
$this->mNewVersion['meta']['history_id']
|
2015-09-28 18:03:35 +00:00
|
|
|
);
|
2012-12-30 03:59:33 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-12-30 03:59:33 +00:00
|
|
|
/**
|
|
|
|
* Get the history ID of the next change
|
|
|
|
*
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param int $historyId History id to find next change of
|
|
|
|
* @return int|null Id of the next change or null if there isn't one
|
2012-12-30 03:59:33 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function getNextHistoryId( $historyId ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2012-12-30 03:59:33 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_history',
|
|
|
|
'afh_id',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2012-12-30 03:59:33 +00:00
|
|
|
'afh_filter' => $this->mFilter,
|
|
|
|
'afh_id > ' . $dbr->addQuotes( $historyId ),
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2012-12-30 03:59:33 +00:00
|
|
|
__METHOD__,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'ORDER BY' => 'afh_timestamp ASC' ]
|
2012-12-30 03:59:33 +00:00
|
|
|
);
|
|
|
|
if ( $row ) {
|
|
|
|
return $row->afh_id;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param string $spec
|
|
|
|
* @param string $otherSpec
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function loadSpec( $spec, $otherSpec ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
static $dependentSpecs = [ 'prev', 'next' ];
|
|
|
|
static $cache = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-01-06 20:17:41 +00:00
|
|
|
if ( isset( $cache[$spec] ) ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
return $cache[$spec];
|
2016-01-06 20:17:41 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2018-08-31 14:19:44 +00:00
|
|
|
// All but afh_filter, afh_deleted and afh_changed_fields
|
|
|
|
$selectFields = [
|
|
|
|
'afh_id',
|
|
|
|
'afh_user',
|
|
|
|
'afh_user_text',
|
|
|
|
'afh_timestamp',
|
|
|
|
'afh_pattern',
|
|
|
|
'afh_comments',
|
|
|
|
'afh_flags',
|
|
|
|
'afh_public_comments',
|
|
|
|
'afh_actions',
|
|
|
|
'afh_group',
|
|
|
|
];
|
2013-10-15 12:28:39 +00:00
|
|
|
$row = null;
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( is_numeric( $spec ) ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
2018-08-31 14:19:44 +00:00
|
|
|
$selectFields,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afh_id' => $spec, 'afh_filter' => $this->mFilter ],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2018-08-26 08:34:42 +00:00
|
|
|
} elseif ( $spec === 'cur' ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
2018-08-31 14:19:44 +00:00
|
|
|
$selectFields,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afh_filter' => $this->mFilter ],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'ORDER BY' => 'afh_timestamp desc' ]
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2018-08-26 08:34:42 +00:00
|
|
|
} elseif ( ( $spec === 'prev' || $spec === 'next' ) &&
|
|
|
|
!in_array( $otherSpec, $dependentSpecs )
|
|
|
|
) {
|
2009-03-12 05:04:39 +00:00
|
|
|
// cached
|
|
|
|
$other = $this->loadSpec( $otherSpec, $spec );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2018-11-19 14:50:36 +00:00
|
|
|
$comparison = $spec === 'prev' ? '<' : '>';
|
|
|
|
$order = $spec === 'prev' ? 'DESC' : 'ASC';
|
2009-03-12 05:04:39 +00:00
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
2018-08-31 14:19:44 +00:00
|
|
|
$selectFields,
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'afh_filter' => $this->mFilter,
|
2018-11-19 14:50:36 +00:00
|
|
|
"afh_id $comparison" . $dbr->addQuotes( $other['meta']['history_id'] ),
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__,
|
2018-11-19 14:50:36 +00:00
|
|
|
[ 'ORDER BY' => "afh_timestamp $order" ]
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( $other && !$row ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
$t = $this->getTitle(
|
2009-10-07 13:57:06 +00:00
|
|
|
'history/' . $this->mFilter . '/item/' . $other['meta']['history_id'] );
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->getOutput()->redirect( $t->getFullURL() );
|
2012-03-11 20:51:54 +00:00
|
|
|
return null;
|
2009-03-22 23:27:27 +00:00
|
|
|
}
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !$row ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
return null;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$data = $this->loadFromHistoryRow( $row );
|
|
|
|
$cache[$spec] = $data;
|
|
|
|
return $data;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param stdClass $row
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function loadFromHistoryRow( $row ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'meta' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
'history_id' => $row->afh_id,
|
|
|
|
'modified_by' => $row->afh_user,
|
2013-06-26 22:58:36 +00:00
|
|
|
'modified_by_text' => $row->afh_user_text,
|
2009-10-07 13:57:06 +00:00
|
|
|
'modified' => $row->afh_timestamp,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'info' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
'description' => $row->afh_public_comments,
|
|
|
|
'flags' => $row->afh_flags,
|
|
|
|
'notes' => $row->afh_comments,
|
2012-05-06 06:44:45 +00:00
|
|
|
'group' => $row->afh_group,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2009-10-07 13:57:06 +00:00
|
|
|
'pattern' => $row->afh_pattern,
|
|
|
|
'actions' => unserialize( $row->afh_actions ),
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param string $timestamp
|
|
|
|
* @param int $history_id
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function formatVersionLink( $timestamp, $history_id ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$filter = $this->mFilter;
|
2011-11-22 16:08:18 +00:00
|
|
|
$text = $this->getLanguage()->timeanddate( $timestamp, true );
|
2009-03-12 05:04:39 +00:00
|
|
|
$title = $this->getTitle( "history/$filter/item/$history_id" );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-12-04 15:13:16 +00:00
|
|
|
$link = $this->linkRenderer->makeLink( $title, $text );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
return $link;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function formatDiff() {
|
2009-03-12 05:04:39 +00:00
|
|
|
$oldVersion = $this->mOldVersion;
|
|
|
|
$newVersion = $this->mNewVersion;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
// headings
|
|
|
|
$oldLink = $this->formatVersionLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
$oldVersion['meta']['modified'],
|
|
|
|
$oldVersion['meta']['history_id']
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
$newLink = $this->formatVersionLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
$newVersion['meta']['modified'],
|
|
|
|
$newVersion['meta']['history_id']
|
|
|
|
);
|
|
|
|
|
2011-07-14 04:57:29 +00:00
|
|
|
$oldUserLink = Linker::userLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
$oldVersion['meta']['modified_by'],
|
|
|
|
$oldVersion['meta']['modified_by_text']
|
|
|
|
);
|
2011-07-14 04:57:29 +00:00
|
|
|
$newUserLink = Linker::userLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
$newVersion['meta']['modified_by'],
|
|
|
|
$newVersion['meta']['modified_by_text']
|
|
|
|
);
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$headings = '';
|
|
|
|
$headings .= Xml::tags( 'th', null,
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-diff-item' )->parse() );
|
2009-03-12 05:04:39 +00:00
|
|
|
$headings .= Xml::tags( 'th', null,
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-diff-version' )
|
2012-10-24 12:59:00 +00:00
|
|
|
->rawParams( $oldLink, $oldUserLink )
|
|
|
|
->params( $newVersion['meta']['modified_by_text'] )
|
|
|
|
->parse()
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
$headings .= Xml::tags( 'th', null,
|
2012-10-24 12:59:00 +00:00
|
|
|
$this->msg( 'abusefilter-diff-version' )
|
|
|
|
->rawParams( $newLink, $newUserLink )
|
|
|
|
->params( $newVersion['meta']['modified_by_text'] )
|
2011-10-02 07:06:38 +00:00
|
|
|
->parse()
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$headings = Xml::tags( 'tr', null, $headings );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
$body = '';
|
2009-03-12 05:04:39 +00:00
|
|
|
// Basic info
|
2018-05-01 19:05:01 +00:00
|
|
|
$infoHeader = $this->getHeaderRow( 'abusefilter-diff-info' );
|
2009-03-12 05:04:39 +00:00
|
|
|
$info = '';
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-description',
|
|
|
|
$oldVersion['info']['description'],
|
2013-06-10 19:49:30 +00:00
|
|
|
$newVersion['info']['description']
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2013-06-10 19:49:30 +00:00
|
|
|
if (
|
2018-03-10 21:47:33 +00:00
|
|
|
count( $this->getConfig()->get( 'AbuseFilterValidGroups' ) ) > 1 ||
|
2018-08-26 08:34:42 +00:00
|
|
|
$oldVersion['info']['group'] !== $newVersion['info']['group']
|
2012-05-06 06:44:45 +00:00
|
|
|
) {
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2012-05-06 06:44:45 +00:00
|
|
|
'abusefilter-edit-group',
|
2013-06-10 19:49:30 +00:00
|
|
|
AbuseFilter::nameGroup( $oldVersion['info']['group'] ),
|
|
|
|
AbuseFilter::nameGroup( $newVersion['info']['group'] )
|
2012-05-06 06:44:45 +00:00
|
|
|
);
|
|
|
|
}
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-flags',
|
2018-10-14 09:39:36 +00:00
|
|
|
AbuseFilter::formatFlags( $oldVersion['info']['flags'], $this->getLanguage() ),
|
|
|
|
AbuseFilter::formatFlags( $newVersion['info']['flags'], $this->getLanguage() )
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-notes',
|
|
|
|
$oldVersion['info']['notes'],
|
|
|
|
$newVersion['info']['notes']
|
|
|
|
);
|
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $info !== '' ) {
|
|
|
|
$body .= $infoHeader . $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
$patternHeader = $this->getHeaderRow( 'abusefilter-diff-pattern' );
|
|
|
|
$pattern = '';
|
|
|
|
$pattern .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-rules',
|
|
|
|
$oldVersion['pattern'],
|
2018-04-29 17:52:45 +00:00
|
|
|
$newVersion['pattern']
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $pattern !== '' ) {
|
|
|
|
$body .= $patternHeader . $pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
$actionsHeader = $this->getHeaderRow( 'abusefilter-edit-consequences' );
|
|
|
|
$actions = '';
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$oldActions = $this->stringifyActions( $oldVersion['actions'] );
|
|
|
|
$newActions = $this->stringifyActions( $newVersion['actions'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
$actions .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-consequences',
|
|
|
|
$oldActions,
|
|
|
|
$newActions
|
|
|
|
);
|
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $actions !== '' ) {
|
|
|
|
$body .= $actionsHeader . $actions;
|
|
|
|
}
|
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
$html = "<table class='wikitable'>
|
|
|
|
<thead>$headings</thead>
|
2018-05-01 19:05:01 +00:00
|
|
|
<tbody>$body</tbody>
|
2013-06-10 19:49:30 +00:00
|
|
|
</table>";
|
2009-03-12 05:04:39 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$html = Xml::tags( 'h2', null, $this->msg( 'abusefilter-diff-title' )->parse() ) . $html;
|
2009-03-12 05:04:39 +00:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param array $actions
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function stringifyActions( $actions ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$lines = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
ksort( $actions );
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action => $parameters ) {
|
2018-10-14 09:39:36 +00:00
|
|
|
$lines[] = AbuseFilter::formatAction( $action, $parameters, $this->getLanguage() );
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !count( $lines ) ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$lines[] = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
return $lines;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param string $msg
|
|
|
|
* @return string
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function getHeaderRow( $msg ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$html = $this->msg( $msg )->parse();
|
2017-06-15 14:23:16 +00:00
|
|
|
$html = Xml::tags( 'th', [ 'colspan' => 3 ], $html );
|
|
|
|
$html = Xml::tags( 'tr', [ 'class' => 'mw-abusefilter-diff-header' ], $html );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param string $msg
|
|
|
|
* @param array|string $old
|
|
|
|
* @param array|string $new
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function getDiffRow( $msg, $old, $new ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !is_array( $old ) ) {
|
2011-12-10 08:40:11 +00:00
|
|
|
$old = explode( "\n", preg_replace( "/\\\r\\\n?/", "\n", $old ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( !is_array( $new ) ) {
|
2011-12-10 08:40:11 +00:00
|
|
|
$new = explode( "\n", preg_replace( "/\\\r\\\n?/", "\n", $new ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $old === $new ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2013-06-10 19:53:33 +00:00
|
|
|
$diffEngine = new DifferenceEngine( $this->getContext() );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
$diffEngine->showDiffStyle();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$diff = new Diff( $old, $new );
|
2013-06-10 19:49:30 +00:00
|
|
|
$formatter = new TableDiffFormatterFullContext();
|
|
|
|
$formattedDiff = $diffEngine->addHeader( $formatter->format( $diff ), '', '' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
return Xml::tags( 'tr', null,
|
|
|
|
Xml::tags( 'th', null, $this->msg( $msg )->parse() ) .
|
2017-06-15 14:23:16 +00:00
|
|
|
Xml::tags( 'td', [ 'colspan' => 2 ], $formattedDiff )
|
2013-06-10 19:49:30 +00:00
|
|
|
) . "\n";
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
}
|