MediaWiki REL1_33
WordAccumulator.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Diff;
27
35 public $insClass = ' class="diffchange diffchange-inline"';
36 public $delClass = ' class="diffchange diffchange-inline"';
37
38 private $lines = [];
39 private $line = '';
40 private $group = '';
41 private $tag = '';
42
46 private function flushGroup( $new_tag ) {
47 if ( $this->group !== '' ) {
48 if ( $this->tag == 'ins' ) {
49 $this->line .= "<ins{$this->insClass}>" . htmlspecialchars( $this->group ) . '</ins>';
50 } elseif ( $this->tag == 'del' ) {
51 $this->line .= "<del{$this->delClass}>" . htmlspecialchars( $this->group ) . '</del>';
52 } else {
53 $this->line .= htmlspecialchars( $this->group );
54 }
55 }
56 $this->group = '';
57 $this->tag = $new_tag;
58 }
59
63 private function flushLine( $new_tag ) {
64 $this->flushGroup( $new_tag );
65 if ( $this->line != '' ) {
66 array_push( $this->lines, $this->line );
67 } else {
68 # make empty lines visible by inserting an NBSP
69 array_push( $this->lines, "\u{00A0}" );
70 }
71 $this->line = '';
72 }
73
78 public function addWords( $words, $tag = '' ) {
79 if ( $tag != $this->tag ) {
80 $this->flushGroup( $tag );
81 }
82
83 foreach ( $words as $word ) {
84 // new-line should only come as first char of word.
85 if ( $word == '' ) {
86 continue;
87 }
88 if ( $word[0] == "\n" ) {
89 $this->flushLine( $tag );
90 $word = substr( $word, 1 );
91 }
92 // FIXME: Don't use assert()
93 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
94 assert( !strstr( $word, "\n" ) );
95 $this->group .= $word;
96 }
97 }
98
102 public function getLines() {
103 $this->flushLine( '~done' );
104
105 return $this->lines;
106 }
107}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
invalid e g too many</span ></p > !end !test with< references/> in group !wikitext Wikipedia rocks< ref > Proceeds of vol XXI</ref > Wikipedia rocks< ref group="note"> Proceeds of vol XXI</ref >< references/>< references group="note"/> ! html< p > Wikipedia rocks< sup id="cite_ref-1" class="reference">< a href="#cite_note-1"> &Wikipedia rocks< sup id="cite_ref-2" class="reference">< a href="#cite_note-2"> &</p >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-1">< span class="mw-cite-backlink">< a href="#cite_ref-1"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-2">< span class="mw-cite-backlink">< a href="#cite_ref-2"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div > !end !test with< references/> in group
Stores, escapes and formats the results of word-level diff.