MediaWiki master
ArrayDiffFormatter.php
Go to the documentation of this file.
1<?php
28
35
42 public function format( $diff ) {
43 $oldline = 1;
44 $newline = 1;
45 $retval = [];
46 foreach ( $diff->getEdits() as $edit ) {
47 switch ( $edit->getType() ) {
48 case 'add':
49 foreach ( $edit->getClosing() as $line ) {
50 $retval[] = [
51 'action' => 'add',
52 'new' => $line,
53 'newline' => $newline++
54 ];
55 }
56 break;
57 case 'delete':
58 foreach ( $edit->getOrig() as $line ) {
59 $retval[] = [
60 'action' => 'delete',
61 'old' => $line,
62 'oldline' => $oldline++,
63 ];
64 }
65 break;
66 case 'change':
67 foreach ( $edit->getOrig() as $key => $line ) {
68 $retval[] = [
69 'action' => 'change',
70 'old' => $line,
71 'new' => $edit->getClosing( $key ),
72 'oldline' => $oldline++,
73 'newline' => $newline++,
74 ];
75 }
76 break;
77 case 'copy':
78 $oldline += $edit->norig();
79 $newline += $edit->norig();
80 }
81 }
82
83 return $retval;
84 }
85
86}
87
89class_alias( ArrayDiffFormatter::class, 'ArrayDiffFormatter' );
A pseudo-formatter that just passes along the Diff::$edits array.
Base class for diff formatters.