MediaWiki master
ArrayDiffFormatter.php
Go to the documentation of this file.
1<?php
14
21
28 public function format( $diff ) {
29 $oldline = 1;
30 $newline = 1;
31 $retval = [];
32 foreach ( $diff->getEdits() as $edit ) {
33 switch ( $edit->getType() ) {
34 case 'add':
35 foreach ( $edit->getClosing() as $line ) {
36 $retval[] = [
37 'action' => 'add',
38 'new' => $line,
39 'newline' => $newline++
40 ];
41 }
42 break;
43 case 'delete':
44 foreach ( $edit->getOrig() as $line ) {
45 $retval[] = [
46 'action' => 'delete',
47 'old' => $line,
48 'oldline' => $oldline++,
49 ];
50 }
51 break;
52 case 'change':
53 foreach ( $edit->getOrig() as $key => $line ) {
54 $retval[] = [
55 'action' => 'change',
56 'old' => $line,
57 'new' => $edit->getClosing( $key ),
58 'oldline' => $oldline++,
59 'newline' => $newline++,
60 ];
61 }
62 break;
63 case 'copy':
64 $oldline += $edit->norig();
65 $newline += $edit->norig();
66 }
67 }
68
69 return $retval;
70 }
71
72}
73
75class_alias( ArrayDiffFormatter::class, 'ArrayDiffFormatter' );
A pseudo-formatter that just passes along the Diff::$edits array.
Base class for diff formatters.