2009-03-12 05:04:39 +00:00
|
|
|
<?php
|
2020-09-18 14:49:13 +00:00
|
|
|
|
2020-11-29 10:53:29 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\View;
|
|
|
|
|
|
|
|
use DifferenceEngine;
|
2022-04-30 19:09:15 +00:00
|
|
|
use Html;
|
2020-10-02 15:08:48 +00:00
|
|
|
use IContextSource;
|
2020-11-29 10:53:29 +00:00
|
|
|
use Linker;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2021-01-07 23:42:58 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Filter\ClosestFilterVersionNotFoundException;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Filter\FilterNotFoundException;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Filter\FilterVersionNotFoundException;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Filter\HistoryFilter;
|
2021-01-04 13:46:34 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterLookup;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
|
2021-01-03 11:12:16 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\TableDiffFormatterFullContext;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2020-11-29 10:53:29 +00:00
|
|
|
use OOUI;
|
2021-10-01 06:49:49 +00:00
|
|
|
use TextContent;
|
2023-06-29 01:56:13 +00:00
|
|
|
use Wikimedia\Diff\Diff;
|
2020-11-29 10:53:29 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
class AbuseFilterViewDiff extends AbuseFilterView {
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
2021-01-07 23:42:58 +00:00
|
|
|
* @var HistoryFilter|null The old version of the filter
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
2021-01-07 23:42:58 +00:00
|
|
|
public $oldVersion;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
2021-01-07 23:42:58 +00:00
|
|
|
* @var HistoryFilter|null The new version of the filter
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
2021-01-07 23:42:58 +00:00
|
|
|
public $newVersion;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var int|null The history ID of the next version, if any
|
|
|
|
*/
|
2021-01-07 23:42:58 +00:00
|
|
|
public $nextHistoryId;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var int|null The ID of the filter
|
|
|
|
*/
|
2020-10-03 17:13:32 +00:00
|
|
|
private $filter;
|
2020-10-02 15:08:48 +00:00
|
|
|
/**
|
|
|
|
* @var SpecsFormatter
|
|
|
|
*/
|
|
|
|
private $specsFormatter;
|
2021-01-04 13:46:34 +00:00
|
|
|
/**
|
|
|
|
* @var FilterLookup
|
|
|
|
*/
|
|
|
|
private $filterLookup;
|
2020-10-02 15:08:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
|
|
|
* @param SpecsFormatter $specsFormatter
|
2021-01-04 13:46:34 +00:00
|
|
|
* @param FilterLookup $filterLookup
|
2020-10-02 15:08:48 +00:00
|
|
|
* @param IContextSource $context
|
|
|
|
* @param LinkRenderer $linkRenderer
|
|
|
|
* @param string $basePageName
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
|
|
|
SpecsFormatter $specsFormatter,
|
2021-01-04 13:46:34 +00:00
|
|
|
FilterLookup $filterLookup,
|
2020-10-02 15:08:48 +00:00
|
|
|
IContextSource $context,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
string $basePageName,
|
|
|
|
array $params
|
|
|
|
) {
|
|
|
|
parent::__construct( $afPermManager, $context, $linkRenderer, $basePageName, $params );
|
|
|
|
$this->specsFormatter = $specsFormatter;
|
|
|
|
$this->specsFormatter->setMessageLocalizer( $this->getContext() );
|
2021-01-04 13:46:34 +00:00
|
|
|
$this->filterLookup = $filterLookup;
|
2020-10-02 15:08:48 +00:00
|
|
|
}
|
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 = [];
|
2020-10-03 17:13:32 +00:00
|
|
|
if ( $this->filter ) {
|
2021-01-07 23:42:58 +00:00
|
|
|
$links['abusefilter-history-backedit'] = $this->getTitle( $this->filter )->getFullURL();
|
|
|
|
$links['abusefilter-diff-backhistory'] = $this->getTitle( "history/$this->filter" )->getFullURL();
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 09:35:07 +00:00
|
|
|
foreach ( $links as $msg => $href ) {
|
2021-01-07 23:42:58 +00:00
|
|
|
$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
|
|
|
|
2022-01-18 22:52:04 +00:00
|
|
|
$backlinks = new OOUI\HorizontalLayout( [ 'items' => array_values( $links ) ] );
|
2018-04-24 09:35:07 +00:00
|
|
|
$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 = [];
|
2021-01-07 23:42:58 +00:00
|
|
|
$oldHistoryID = $this->oldVersion->getHistoryID();
|
|
|
|
if ( $this->filterLookup->getFirstFilterVersionID( $this->filter ) !== $oldHistoryID ) {
|
2012-12-30 03:59:33 +00:00
|
|
|
// Create a "previous change" link if this isn't the first change of the given filter
|
2021-01-07 23:42:58 +00:00
|
|
|
$href = $this->getTitle( "history/$this->filter/diff/prev/$oldHistoryID" )->getFullURL();
|
2018-05-01 12:55:35 +00:00
|
|
|
$buttons[] = new OOUI\ButtonWidget( [
|
|
|
|
'label' => $this->msg( 'abusefilter-diff-prev' )->text(),
|
|
|
|
'href' => $href,
|
|
|
|
'icon' => 'previous'
|
|
|
|
] );
|
2012-12-30 03:59:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
if ( $this->nextHistoryId !== null ) {
|
2012-12-30 03:59:33 +00:00
|
|
|
// Create a "next change" link if this isn't the last change of the given filter
|
2021-01-07 23:42:58 +00:00
|
|
|
$href = $this->getTitle( "history/$this->filter/diff/prev/$this->nextHistoryId" )->getFullURL();
|
2018-05-01 12:55:35 +00:00
|
|
|
$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];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-20 10:18:46 +00:00
|
|
|
if ( !is_numeric( $this->mParams[1] ) ) {
|
2019-03-28 19:59:53 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' );
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->filter = (int)$this->mParams[1];
|
2019-03-28 19:59:53 +00:00
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$this->oldVersion = $this->loadSpec( $oldSpec, $newSpec );
|
|
|
|
$this->newVersion = $this->loadSpec( $newSpec, $oldSpec );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
if ( $this->oldVersion === null || $this->newVersion === null ) {
|
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
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
if ( !$this->afPermManager->canViewPrivateFilters( $this->getAuthority() ) &&
|
2021-01-07 23:42:58 +00:00
|
|
|
( $this->oldVersion->isHidden() || $this->newVersion->isHidden() )
|
2019-01-18 12:05:43 +00:00
|
|
|
) {
|
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-history-error-hidden' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-20 16:24:44 +00:00
|
|
|
try {
|
|
|
|
$this->nextHistoryId = $this->filterLookup->getClosestVersion(
|
|
|
|
$this->newVersion->getHistoryID(),
|
|
|
|
$this->filter,
|
|
|
|
FilterLookup::DIR_NEXT
|
|
|
|
)->getHistoryID();
|
|
|
|
} catch ( ClosestFilterVersionNotFoundException $_ ) {
|
|
|
|
$this->nextHistoryId = null;
|
|
|
|
}
|
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
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param string $spec
|
|
|
|
* @param string $otherSpec
|
2021-01-07 23:42:58 +00:00
|
|
|
* @return HistoryFilter|null
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function loadSpec( $spec, $otherSpec ): ?HistoryFilter {
|
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
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$filterObj = null;
|
|
|
|
if ( ( $spec === 'prev' || $spec === 'next' ) && !in_array( $otherSpec, $dependentSpecs ) ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$other = $this->loadSpec( $otherSpec, $spec );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2021-01-04 13:16:05 +00:00
|
|
|
if ( !$other ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$dir = $spec === 'prev' ? FilterLookup::DIR_PREV : FilterLookup::DIR_NEXT;
|
|
|
|
try {
|
|
|
|
$filterObj = $this->filterLookup->getClosestVersion( $other->getHistoryID(), $this->filter, $dir );
|
|
|
|
} catch ( ClosestFilterVersionNotFoundException $_ ) {
|
|
|
|
$t = $this->getTitle( "history/$this->filter/item/" . $other->getHistoryID() );
|
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
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
if ( $filterObj === null ) {
|
|
|
|
try {
|
|
|
|
if ( is_numeric( $spec ) ) {
|
|
|
|
$filterObj = $this->filterLookup->getFilterVersion( (int)$spec );
|
|
|
|
} elseif ( $spec === 'cur' ) {
|
|
|
|
$filterObj = $this->filterLookup->getLastHistoryVersion( $this->filter );
|
|
|
|
}
|
|
|
|
} catch ( FilterNotFoundException | FilterVersionNotFoundException $_ ) {
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$cache[$spec] = $filterObj;
|
|
|
|
return $cache[$spec];
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2022-04-30 19:09:15 +00:00
|
|
|
* @param HistoryFilter $filterVersion
|
|
|
|
* @return string raw html for the <th> element
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2022-04-30 19:09:15 +00:00
|
|
|
private function getVersionHeading( HistoryFilter $filterVersion ) {
|
|
|
|
$text = $this->getLanguage()->userTimeAndDate(
|
|
|
|
$filterVersion->getTimestamp(),
|
|
|
|
$this->getUser()
|
|
|
|
);
|
|
|
|
$history_id = $filterVersion->getHistoryID();
|
2021-01-07 23:42:58 +00:00
|
|
|
$title = $this->getTitle( "history/$this->filter/item/$history_id" );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2022-04-30 19:09:15 +00:00
|
|
|
$versionLink = $this->linkRenderer->makeLink( $title, $text );
|
|
|
|
$userLink = Linker::userLink(
|
|
|
|
$filterVersion->getUserID(),
|
|
|
|
$filterVersion->getUserName()
|
|
|
|
);
|
|
|
|
return Html::rawElement(
|
|
|
|
'th',
|
|
|
|
[],
|
|
|
|
$this->msg( 'abusefilter-diff-version' )
|
|
|
|
->rawParams( $versionLink, $userLink )
|
|
|
|
->params( $filterVersion->getUserName() )
|
|
|
|
->parse()
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
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() {
|
2021-01-07 23:42:58 +00:00
|
|
|
$oldVersion = $this->oldVersion;
|
|
|
|
$newVersion = $this->newVersion;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
// headings
|
2022-04-30 19:09:15 +00:00
|
|
|
$headings = Html::rawElement(
|
|
|
|
'th',
|
|
|
|
[],
|
|
|
|
$this->msg( 'abusefilter-diff-item' )->parse()
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2022-04-30 19:09:15 +00:00
|
|
|
$headings .= $this->getVersionHeading( $oldVersion );
|
|
|
|
$headings .= $this->getVersionHeading( $newVersion );
|
|
|
|
$headings = Html::rawElement( 'tr', [], $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
|
2021-01-07 23:42:58 +00:00
|
|
|
$info = $this->getDiffRow( 'abusefilter-edit-description', $oldVersion->getName(), $newVersion->getName() );
|
|
|
|
$info .= $this->getDiffRow(
|
|
|
|
'abusefilter-edit-group',
|
|
|
|
$this->specsFormatter->nameGroup( $oldVersion->getGroup() ),
|
|
|
|
$this->specsFormatter->nameGroup( $newVersion->getGroup() )
|
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-flags',
|
2021-01-07 23:42:58 +00:00
|
|
|
$this->specsFormatter->formatFilterFlags( $oldVersion, $this->getLanguage() ),
|
|
|
|
$this->specsFormatter->formatFilterFlags( $newVersion, $this->getLanguage() )
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$info .= $this->getDiffRow( 'abusefilter-edit-notes', $oldVersion->getComments(), $newVersion->getComments() );
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $info !== '' ) {
|
2020-12-03 08:52:39 +00:00
|
|
|
$body .= $this->getHeaderRow( 'abusefilter-diff-info' ) . $info;
|
2018-05-01 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 23:42:58 +00:00
|
|
|
$pattern = $this->getDiffRow( 'abusefilter-edit-rules', $oldVersion->getRules(), $newVersion->getRules() );
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $pattern !== '' ) {
|
2020-12-03 08:52:39 +00:00
|
|
|
$body .= $this->getHeaderRow( 'abusefilter-diff-pattern' ) . $pattern;
|
2018-05-01 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 08:52:39 +00:00
|
|
|
$actions = $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-consequences',
|
2021-01-07 23:42:58 +00:00
|
|
|
$this->stringifyActions( $oldVersion->getActions() ) ?: [ '' ],
|
|
|
|
$this->stringifyActions( $newVersion->getActions() ) ?: [ '' ]
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2018-05-01 19:05:01 +00:00
|
|
|
if ( $actions !== '' ) {
|
2020-12-03 08:52:39 +00:00
|
|
|
$body .= $this->getHeaderRow( 'abusefilter-edit-consequences' ) . $actions;
|
2018-05-01 19:05:01 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 19:09:15 +00:00
|
|
|
$tableHead = Html::rawElement( 'thead', [], $headings );
|
|
|
|
$tableBody = Html::rawElement( 'tbody', [], $body );
|
|
|
|
$table = Html::rawElement(
|
|
|
|
'table',
|
|
|
|
[ 'class' => 'wikitable' ],
|
|
|
|
$tableHead . $tableBody
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
|
2023-06-12 15:08:25 +00:00
|
|
|
return Html::rawElement( 'h2', [], $this->msg( 'abusefilter-diff-title' )->parse() ) .
|
|
|
|
$table;
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2020-12-03 08:49:56 +00:00
|
|
|
* @param string[][] $actions
|
|
|
|
* @return string[]
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
private function stringifyActions( array $actions ): array {
|
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 );
|
2022-04-30 19:09:15 +00:00
|
|
|
$language = $this->getLanguage();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action => $parameters ) {
|
2022-04-30 19:09:15 +00:00
|
|
|
$lines[] = $this->specsFormatter->formatAction( $action, $parameters, $language );
|
2009-03-12 05:04:39 +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
|
|
|
/**
|
2022-04-30 19:09:15 +00:00
|
|
|
* @param string $key
|
2017-08-04 23:14:10 +00:00
|
|
|
* @return string
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2022-04-30 19:09:15 +00:00
|
|
|
public function getHeaderRow( $key ) {
|
|
|
|
$msg = $this->msg( $key )->parse();
|
|
|
|
return Html::rawElement(
|
|
|
|
'tr',
|
|
|
|
[ 'class' => 'mw-abusefilter-diff-header' ],
|
|
|
|
Html::rawElement( 'th', [ 'colspan' => 3 ], $msg )
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2022-04-30 19:09:15 +00:00
|
|
|
* @param string $key
|
2017-08-04 23:14:10 +00:00
|
|
|
* @param array|string $old
|
|
|
|
* @param array|string $new
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2022-04-30 19:09:15 +00:00
|
|
|
public function getDiffRow( $key, $old, $new ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !is_array( $old ) ) {
|
2021-10-01 06:49:49 +00:00
|
|
|
$old = explode( "\n", TextContent::normalizeLineEndings( $old ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( !is_array( $new ) ) {
|
2021-10-01 06:49:49 +00:00
|
|
|
$new = explode( "\n", TextContent::normalizeLineEndings( $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
|
|
|
|
2022-04-30 19:09:15 +00:00
|
|
|
$heading = Html::rawElement( 'th', [], $this->msg( $key )->parse() );
|
|
|
|
$bodyCell = Html::rawElement( 'td', [ 'colspan' => 2 ], $formattedDiff );
|
|
|
|
return Html::rawElement(
|
|
|
|
'tr',
|
|
|
|
[],
|
|
|
|
$heading . $bodyCell
|
2013-06-10 19:49:30 +00:00
|
|
|
) . "\n";
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
}
|