MediaWiki REL1_40
WordAccumulator.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Diff;
27
36 public $insClass = ' class="diffchange diffchange-inline"';
38 public $delClass = ' class="diffchange diffchange-inline"';
39
41 private $lines = [];
43 private $line = '';
45 private $group = '';
47 private $tag = '';
48
52 private function flushGroup( $new_tag ) {
53 if ( $this->group !== '' ) {
54 $encGroup = htmlspecialchars( $this->group, ENT_NOQUOTES );
55 if ( $this->tag == 'ins' ) {
56 $this->line .= "<ins{$this->insClass}>$encGroup</ins>";
57 } elseif ( $this->tag == 'del' ) {
58 $this->line .= "<del{$this->delClass}>$encGroup</del>";
59 } else {
60 $this->line .= $encGroup;
61 }
62 }
63 $this->group = '';
64 $this->tag = $new_tag;
65 }
66
70 private function flushLine( $new_tag ) {
71 $this->flushGroup( $new_tag );
72 if ( $this->line != '' ) {
73 array_push( $this->lines, $this->line );
74 } else {
75 # make empty lines visible by inserting an NBSP
76 array_push( $this->lines, "\u{00A0}" );
77 }
78 $this->line = '';
79 }
80
85 public function addWords( $words, $tag = '' ) {
86 if ( $tag != $this->tag ) {
87 $this->flushGroup( $tag );
88 }
89
90 foreach ( $words as $word ) {
91 // new-line should only come as first char of word.
92 if ( $word == '' ) {
93 continue;
94 }
95 if ( $word[0] == "\n" ) {
96 $this->flushLine( $tag );
97 $word = substr( $word, 1 );
98 }
99 // FIXME: Don't use assert()
100 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
101 assert( !strstr( $word, "\n" ) );
102 $this->group .= $word;
103 }
104 }
105
109 public function getLines() {
110 $this->flushLine( '~done' );
111
112 return $this->lines;
113 }
114}
Stores, escapes and formats the results of word-level diff.
if(!file_exists( $CREDITS)) $lines