MediaWiki
REL1_37
WordAccumulator.php
Go to the documentation of this file.
1
<?php
26
namespace
MediaWiki\Diff
;
27
34
class
WordAccumulator
{
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
if
( $this->tag ==
'ins'
) {
55
$this->line .=
"<ins{$this->insClass}>"
. htmlspecialchars( $this->group ) .
'</ins>'
;
56
} elseif ( $this->tag ==
'del'
) {
57
$this->line .=
"<del{$this->delClass}>"
. htmlspecialchars( $this->group ) .
'</del>'
;
58
}
else
{
59
$this->line .= htmlspecialchars( $this->group );
60
}
61
}
62
$this->group =
''
;
63
$this->tag = $new_tag;
64
}
65
69
private
function
flushLine
( $new_tag ) {
70
$this->
flushGroup
( $new_tag );
71
if
( $this->line !=
''
) {
72
array_push( $this->lines, $this->line );
73
}
else
{
74
# make empty lines visible by inserting an NBSP
75
array_push( $this->lines,
"\u{00A0}"
);
76
}
77
$this->line =
''
;
78
}
79
84
public
function
addWords
( $words,
$tag
=
''
) {
85
if
(
$tag
!= $this->tag ) {
86
$this->
flushGroup
(
$tag
);
87
}
88
89
foreach
( $words as $word ) {
90
// new-line should only come as first char of word.
91
if
( $word ==
''
) {
92
continue
;
93
}
94
if
( $word[0] ==
"\n"
) {
95
$this->
flushLine
(
$tag
);
96
$word = substr( $word, 1 );
97
}
98
// FIXME: Don't use assert()
99
// phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
100
assert( !strstr( $word,
"\n"
) );
101
$this->group .= $word;
102
}
103
}
104
108
public
function
getLines
() {
109
$this->
flushLine
(
'~done'
);
110
111
return
$this->lines
;
112
}
113
}
MediaWiki\Diff\WordAccumulator
Stores, escapes and formats the results of word-level diff.
Definition
WordAccumulator.php:34
MediaWiki\Diff\WordAccumulator\$tag
string $tag
Definition
WordAccumulator.php:47
MediaWiki\Diff\WordAccumulator\flushGroup
flushGroup( $new_tag)
Definition
WordAccumulator.php:52
MediaWiki\Diff\WordAccumulator\$delClass
string $delClass
Definition
WordAccumulator.php:38
MediaWiki\Diff\WordAccumulator\flushLine
flushLine( $new_tag)
Definition
WordAccumulator.php:69
MediaWiki\Diff\WordAccumulator\$insClass
string $insClass
Definition
WordAccumulator.php:36
MediaWiki\Diff\WordAccumulator\getLines
getLines()
Definition
WordAccumulator.php:108
MediaWiki\Diff\WordAccumulator\$group
string $group
Definition
WordAccumulator.php:45
MediaWiki\Diff\WordAccumulator\addWords
addWords( $words, $tag='')
Definition
WordAccumulator.php:84
MediaWiki\Diff\WordAccumulator\$lines
array $lines
Definition
WordAccumulator.php:41
MediaWiki\Diff\WordAccumulator\$line
string $line
Definition
WordAccumulator.php:43
MediaWiki\Diff
Definition
ComplexityException.php:22
includes
diff
WordAccumulator.php
Generated on Fri Apr 5 2024 23:40:12 for MediaWiki by
1.9.8