Matmarex has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67868
Change subject: AbuseFilterViewDiff: Make diffs use standard styling (and more)
......................................................................
AbuseFilterViewDiff: Make diffs use standard styling (and more)
They still used old 1.18-style diffs, with styles copied from core.
Also:
* Remove the distinction between "simple" and "multiline" diff chunk,
enabling consistent styling
* Always show word-level diff, even in previously "simple" chunks
* Ensure the full context is always shown. This was clearly intended
(showing straight side-by-side comparison if there were no changes
and in "simple" chunks, diff otherwise; showing chunks with no
changes), but the default context is only 2 lines.
* Remove the distinction between 'wikitext' and 'text' diffs (all are
treated like 'text' was); it's impossible to show parsed code with
word-level diff, and it was only enabled for "simple" chunks, all of
which are intended to be one-line strings and are shown unparsed
elsewhere (e.g. filter description on the list on Special:AbuseFilter)
Bug: 36478
Change-Id: Ie24ad5ac5a9a2bc9b8f0fc0c4a03d5dfe7a6a83f
---
M Views/AbuseFilterViewDiff.php
M modules/ext.abuseFilter.css
2 files changed, 60 insertions(+), 103 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter
refs/changes/68/67868/1
diff --git a/Views/AbuseFilterViewDiff.php b/Views/AbuseFilterViewDiff.php
index af530d0..7028a9d 100644
--- a/Views/AbuseFilterViewDiff.php
+++ b/Views/AbuseFilterViewDiff.php
@@ -1,5 +1,40 @@
<?php
+/**
+ * Like TableDiffFormatter, but will always render the full context
+ * (even for empty diffs).
+ *
+ * @private
+ */
+class TableDiffFormatterFullContext extends TableDiffFormatter {
+ /**
+ * Format a diff.
+ *
+ * @param $diff Diff A Diff object.
+ * @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;
+ }
+}
+
class AbuseFilterViewDiff extends AbuseFilterView {
var $mOldVersion = null;
var $mNewVersion = null;
@@ -261,30 +296,29 @@
// Basic info
$info = '';
$info .= $this->getHeaderRow( 'abusefilter-diff-info' );
- $info .= $this->getSimpleRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-description',
$oldVersion['info']['description'],
- $newVersion['info']['description'],
- 'wikitext'
+ $newVersion['info']['description']
);
global $wgAbuseFilterValidGroups;
- if (
+ if (
count($wgAbuseFilterValidGroups) > 1 ||
$oldVersion['info']['group'] !=
$newVersion['info']['group']
) {
- $info .= $this->getSimpleRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-group',
-
AbuseFilter::nameGroup($oldVersion['info']['group']),
-
AbuseFilter::nameGroup($newVersion['info']['group'])
+ AbuseFilter::nameGroup(
$oldVersion['info']['group'] ),
+ AbuseFilter::nameGroup(
$newVersion['info']['group'] )
);
}
- $info .= $this->getSimpleRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-flags',
AbuseFilter::formatFlags( $oldVersion['info']['flags']
),
AbuseFilter::formatFlags( $newVersion['info']['flags'] )
);
- $info .= $this->getMultiLineRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-notes',
$oldVersion['info']['notes'],
$newVersion['info']['notes']
@@ -292,7 +326,7 @@
// Pattern
$info .= $this->getHeaderRow( 'abusefilter-diff-pattern' );
- $info .= $this->getMultiLineRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-rules',
$oldVersion['pattern'],
$newVersion['pattern'],
@@ -304,16 +338,16 @@
$newActions = $this->stringifyActions( $newVersion['actions'] );
$info .= $this->getHeaderRow( 'abusefilter-edit-consequences' );
- $info .= $this->getMultiLineRow(
+ $info .= $this->getDiffRow(
'abusefilter-edit-consequences',
$oldActions,
$newActions
);
- $html = "<table class='mw-abusefilter-diff'>
- <thead>$headings</thead>
- <tbody>$info</tbody>
-</table>";
+ $html = "<table class='wikitable'>
+ <thead>$headings</thead>
+ <tbody>$info</tbody>
+ </table>";
$html = Xml::tags( 'h2', null, $this->msg(
'abusefilter-diff-title' )->parse() ) . $html;
@@ -355,43 +389,9 @@
* @param $msg
* @param $old
* @param $new
- * @param string $format
* @return string
*/
- function getSimpleRow( $msg, $old, $new, $format = 'wikitext' ) {
- $row = '';
-
- $row .= Xml::tags( 'th', null, $this->msg( $msg )->parse() );
-
- $oldClass = $newClass = 'mw-abusefilter-diff-context';
- if ( trim( $old ) != trim( $new ) ) {
- $oldClass = 'mw-abusefilter-diff-removed';
- $newClass = 'mw-abusefilter-diff-added';
- }
-
- if ( $format == 'wikitext' ) {
- $old = $this->getOutput()->parseInline( $old );
- $new = $this->getOutput()->parseInline( $new );
- }
-
- if ( $format == 'text' ) {
- $old = nl2br( htmlspecialchars( $old ) );
- $new = nl2br( htmlspecialchars( $new ) );
- }
-
- $row .= Xml::tags( 'td', array( 'class' => $oldClass ), $old );
- $row .= Xml::tags( 'td', array( 'class' => $newClass ), $new );
-
- return Xml::tags( 'tr', null, $row ) . "\n";
- }
-
- /**
- * @param $msg
- * @param $old
- * @param $new
- * @return string
- */
- function getMultiLineRow( $msg, $old, $new ) {
+ function getDiffRow( $msg, $old, $new ) {
if ( !is_array( $old ) ) {
$old = explode( "\n", preg_replace( "/\\\r\\\n?/",
"\n", $old ) );
}
@@ -399,20 +399,19 @@
$new = explode( "\n", preg_replace( "/\\\r\\\n?/",
"\n", $new ) );
}
- if ( $old == $new ) {
- $old = implode( "\n", $old );
- $new = implode( "\n", $new );
- return $this->getSimpleRow( $msg, $old, $new, 'text' );
- }
+ $diffEngine = new DifferenceEngine;
+
+ $diffEngine->showDiffStyle();
+
+ // We can't use $diffEngine->generateDiffBody since it doesn't
allow custom formatters
+ $diff = new Diff( $old, $new );
+ $formatter = new TableDiffFormatterFullContext();
+ $formattedDiff = $formatter->format( $diff );
+
+ $formattedDiff = $diffEngine->addHeader( $formattedDiff, '', ''
);
$row = '';
$row .= Xml::tags( 'th', null, $this->msg( $msg )->parse() );
-
- $diff = new Diff( $old, $new );
- $formatter = new TableDiffFormatter();
- $formattedDiff = $formatter->format( $diff );
- $formattedDiff =
- "<table
class='mw-abusefilter-diff-multiline'><tbody>$formattedDiff</tbody></table>";
$row .= Xml::tags( 'td', array( 'colspan' => 2 ),
$formattedDiff );
return Xml::tags( 'tr', null, $row ) . "\n";
diff --git a/modules/ext.abuseFilter.css b/modules/ext.abuseFilter.css
index 11f0181..c1d3b2a 100644
--- a/modules/ext.abuseFilter.css
+++ b/modules/ext.abuseFilter.css
@@ -73,48 +73,6 @@
background-position: left center;
}
-table.mw-abusefilter-diff {
- width: 80%;
- border-collapse: collapse;
-}
-
-table.mw-abusefilter-diff td,
-table.mw-abusefilter-diff th {
- border: 1px solid #888888;
-}
-
-.mw-abusefilter-diff-added,
-.mw-abusefilter-diff-multiline .diff-addedline {
- background: #cfc;
-}
-
-.mw-abusefilter-diff-removed,
-.mw-abusefilter-diff-multiline .diff-deletedline {
- background: #ffa;
-}
-
-.mw-abusefilter-diff-context,
-.mw-abusefilter-diff-multiline .diff-context {
- background: #eee;
-}
-
-.mw-abusefilter-diff-multiline {
- width: 100%;
-}
-
-.mw-abusefilter-diff-multiline td {
- border: none !important;
-}
-
-.mw-abusefilter-diff-multiline .diff-marker {
- font-size: 0.8em;
-}
-
-.mw-abusefilter-diff-multiline td.diff-addedline,
-.mw-abusefilter-diff-multiline td.diff-deletedline {
- width: 50%;
-}
-
/* Name is in site content language */
/* @noflip */
.sitedir-ltr .TablePager_col_af_public_comments {
--
To view, visit https://gerrit.wikimedia.org/r/67868
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie24ad5ac5a9a2bc9b8f0fc0c4a03d5dfe7a6a83f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Matmarex <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits