2009-03-12 05:04:39 +00:00
|
|
|
<?php
|
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
/**
|
|
|
|
* Like TableDiffFormatter, but will always render the full context
|
|
|
|
* (even for empty diffs).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
class TableDiffFormatterFullContext extends TableDiffFormatter {
|
|
|
|
/**
|
|
|
|
* Format a diff.
|
|
|
|
*
|
|
|
|
* @param Diff $diff
|
|
|
|
* @return string The formatted output.
|
|
|
|
*/
|
|
|
|
function format( $diff ) {
|
|
|
|
$xlen = $ylen = 0;
|
|
|
|
|
|
|
|
// Calculate the length of the left and the right side
|
|
|
|
foreach ( $diff->edits as $edit ) {
|
|
|
|
if ( $edit->orig ) {
|
|
|
|
$xlen += count( $edit->orig );
|
|
|
|
}
|
|
|
|
if ( $edit->closing ) {
|
|
|
|
$ylen += count( $edit->closing );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just render the diff with no preprocessing
|
|
|
|
$this->_start_diff();
|
|
|
|
$this->_block( 1, $xlen, 1, $ylen, $diff->edits );
|
|
|
|
$end = $this->_end_diff();
|
|
|
|
|
|
|
|
return $end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
class AbuseFilterViewDiff extends AbuseFilterView {
|
|
|
|
var $mOldVersion = null;
|
|
|
|
var $mNewVersion = null;
|
2012-12-30 03:59:33 +00:00
|
|
|
var $mNextHistoryId = null;
|
2009-03-12 05:04:39 +00:00
|
|
|
var $mFilter = null;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
function show() {
|
2009-03-12 05:04:39 +00:00
|
|
|
$show = $this->loadData();
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$links = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mFilter ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$links['abusefilter-history-backedit'] = $this->getTitle( $this->mFilter );
|
2009-10-07 13:57:06 +00:00
|
|
|
$links['abusefilter-diff-backhistory'] = $this->getTitle( 'history/' . $this->mFilter );
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $links as $msg => $title ) {
|
2012-12-30 03:59:33 +00:00
|
|
|
$links[$msg] = Linker::link( $title, $this->msg( $msg )->escaped() );
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +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-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
|
|
|
|
$links = array();
|
|
|
|
if ( AbuseFilter::getFirstFilterChange( $this->mFilter ) != $this->mOldVersion['meta']['history_id'] ) {
|
|
|
|
// Create a "previous change" link if this isn't the first change of the given filter
|
|
|
|
$links[] = Linker::link(
|
|
|
|
$this->getTitle(
|
|
|
|
'history/' . $this->mFilter . '/diff/prev/' . $this->mOldVersion['meta']['history_id']
|
|
|
|
),
|
|
|
|
$this->getLanguage()->getArrow( 'backwards' ) . ' ' . $this->msg( 'abusefilter-diff-prev' )->escaped()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !is_null( $this->mNextHistoryId ) ) {
|
|
|
|
// Create a "next change" link if this isn't the last change of the given filter
|
|
|
|
$links[] = Linker::link(
|
|
|
|
$this->getTitle(
|
|
|
|
'history/' . $this->mFilter . '/diff/prev/' . $this->mNextHistoryId
|
|
|
|
),
|
|
|
|
$this->msg( 'abusefilter-diff-next' )->escaped() . ' ' . $this->getLanguage()->getArrow( 'forwards' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( count( $links ) > 0 ) {
|
|
|
|
$backlinks = $this->getLanguage()->pipeList( $links );
|
|
|
|
$out->addHTML( Xml::tags( 'p', null, $backlinks ) );
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
function loadData() {
|
|
|
|
$oldSpec = $this->mParams[3];
|
|
|
|
$newSpec = $this->mParams[4];
|
|
|
|
$this->mFilter = $this->mParams[1];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-07-14 04:57:29 +00:00
|
|
|
if ( AbuseFilter::filterHidden( $this->mFilter ) &&
|
2012-06-07 15:54:14 +00:00
|
|
|
!$this->getUser()->isAllowed( 'abusefilter-modify' ) &&
|
|
|
|
!$this->getUser()->isAllowed( 'abusefilter-view-private' ) ) {
|
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
|
|
|
|
2012-12-30 03:59:33 +00:00
|
|
|
$this->mNextHistoryId = $this->getNextHistoryId( $this->mNewVersion['meta']['history_id'] , 'next' );
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param $historyId Integer: History id to find next change of
|
|
|
|
* @return Integer|Null: Id of the next change or null if there isn't one
|
|
|
|
*/
|
|
|
|
function getNextHistoryId( $historyId ) {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_history',
|
|
|
|
'afh_id',
|
|
|
|
array(
|
|
|
|
'afh_filter' => $this->mFilter,
|
|
|
|
'afh_id > ' . $dbr->addQuotes( $historyId ),
|
|
|
|
),
|
|
|
|
__METHOD__,
|
|
|
|
array( 'ORDER BY' => 'afh_timestamp ASC' )
|
|
|
|
);
|
|
|
|
if ( $row ) {
|
|
|
|
return $row->afh_id;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
function loadSpec( $spec, $otherSpec ) {
|
|
|
|
static $dependentSpecs = array( 'prev', 'next' );
|
|
|
|
static $cache = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
if ( isset( $cache[$spec] ) )
|
|
|
|
return $cache[$spec];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
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',
|
|
|
|
'*',
|
|
|
|
array( 'afh_id' => $spec, 'afh_filter' => $this->mFilter ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
} elseif ( $spec == 'cur' ) {
|
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
|
|
|
'*',
|
|
|
|
array( 'afh_filter' => $this->mFilter ),
|
|
|
|
__METHOD__,
|
|
|
|
array( 'ORDER BY' => 'afh_timestamp desc' )
|
|
|
|
);
|
|
|
|
} elseif ( $spec == 'prev' && !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
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
|
|
|
'*',
|
|
|
|
array(
|
|
|
|
'afh_filter' => $this->mFilter,
|
|
|
|
'afh_id<' . $dbr->addQuotes( $other['meta']['history_id'] ),
|
|
|
|
),
|
|
|
|
__METHOD__,
|
|
|
|
array( 'ORDER BY' => 'afh_timestamp desc' )
|
|
|
|
);
|
|
|
|
if ( $other && !$row ) {
|
2009-03-22 23:27:27 +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-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
} elseif ( $spec == 'next' && !in_array( $otherSpec, $dependentSpecs ) ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
// cached
|
|
|
|
$other = $this->loadSpec( $otherSpec, $spec );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$row = $dbr->selectRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abuse_filter_history',
|
|
|
|
'*',
|
|
|
|
array(
|
|
|
|
'afh_filter' => $this->mFilter,
|
|
|
|
'afh_id>' . $dbr->addQuotes( $other['meta']['history_id'] ),
|
|
|
|
),
|
|
|
|
__METHOD__,
|
2012-12-30 03:59:33 +00:00
|
|
|
array( 'ORDER BY' => 'afh_timestamp ASC' )
|
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
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
function loadFromHistoryRow( $row ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
return array(
|
|
|
|
'meta' => array(
|
|
|
|
'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,
|
|
|
|
),
|
|
|
|
'info' => array(
|
|
|
|
'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,
|
2009-10-07 13:57:06 +00:00
|
|
|
),
|
|
|
|
'pattern' => $row->afh_pattern,
|
|
|
|
'actions' => unserialize( $row->afh_actions ),
|
|
|
|
);
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
|
|
|
* @param $timestamp
|
|
|
|
* @param $history_id
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-03-12 05:04:39 +00:00
|
|
|
function formatVersionLink( $timestamp, $history_id ) {
|
|
|
|
$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
|
|
|
|
2011-07-14 04:57:29 +00:00
|
|
|
$link = Linker::link( $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
|
|
|
|
*/
|
2009-03-12 05:04:39 +00:00
|
|
|
function formatDiff() {
|
|
|
|
$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
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
// Basic info
|
|
|
|
$info = '';
|
|
|
|
$info .= $this->getHeaderRow( 'abusefilter-diff-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
|
|
|
);
|
2012-05-06 06:44:45 +00:00
|
|
|
global $wgAbuseFilterValidGroups;
|
2013-06-10 19:49:30 +00:00
|
|
|
if (
|
2012-05-06 06:44:45 +00:00
|
|
|
count($wgAbuseFilterValidGroups) > 1 ||
|
|
|
|
$oldVersion['info']['group'] != $newVersion['info']['group']
|
|
|
|
) {
|
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',
|
|
|
|
AbuseFilter::formatFlags( $oldVersion['info']['flags'] ),
|
|
|
|
AbuseFilter::formatFlags( $newVersion['info']['flags'] )
|
|
|
|
);
|
|
|
|
|
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']
|
|
|
|
);
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
// Pattern
|
|
|
|
$info .= $this->getHeaderRow( 'abusefilter-diff-pattern' );
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-rules',
|
|
|
|
$oldVersion['pattern'],
|
|
|
|
$newVersion['pattern'],
|
|
|
|
'text'
|
|
|
|
);
|
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
// Actions
|
|
|
|
$oldActions = $this->stringifyActions( $oldVersion['actions'] );
|
|
|
|
$newActions = $this->stringifyActions( $newVersion['actions'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 05:04:39 +00:00
|
|
|
$info .= $this->getHeaderRow( 'abusefilter-edit-consequences' );
|
2013-06-10 19:49:30 +00:00
|
|
|
$info .= $this->getDiffRow(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-consequences',
|
|
|
|
$oldActions,
|
|
|
|
$newActions
|
|
|
|
);
|
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
$html = "<table class='wikitable'>
|
|
|
|
<thead>$headings</thead>
|
|
|
|
<tbody>$info</tbody>
|
|
|
|
</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
|
|
|
/**
|
|
|
|
* @param $actions
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-03-12 05:04:39 +00:00
|
|
|
function stringifyActions( $actions ) {
|
|
|
|
$lines = array();
|
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 ) {
|
2009-03-12 05:04:39 +00:00
|
|
|
$lines[] = AbuseFilter::formatAction( $action, $parameters );
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
* @param $msg
|
|
|
|
* @return String
|
|
|
|
*/
|
2009-03-12 05:04:39 +00:00
|
|
|
function getHeaderRow( $msg ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$html = $this->msg( $msg )->parse();
|
2009-03-12 05:04:39 +00:00
|
|
|
$html = Xml::tags( 'th', array( 'colspan' => 3 ), $html );
|
|
|
|
$html = Xml::tags( 'tr', array( '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
|
|
|
/**
|
|
|
|
* @param $msg
|
|
|
|
* @param $old
|
|
|
|
* @param $new
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-06-10 19:49:30 +00:00
|
|
|
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
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
$diffEngine = new DifferenceEngine;
|
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
|
|
|
|
2013-06-10 19:49:30 +00:00
|
|
|
// We can't use $diffEngine->generateDiffBody since it doesn't allow custom formatters
|
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() ) .
|
|
|
|
Xml::tags( 'td', array( 'colspan' => 2 ), $formattedDiff )
|
|
|
|
) . "\n";
|
2009-03-12 05:04:39 +00:00
|
|
|
}
|
|
|
|
}
|