MediaWiki  1.33.0
WordAccumulator.php
Go to the documentation of this file.
1 <?php
26 namespace 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 }
MediaWiki\Diff\WordAccumulator\getLines
getLines()
Definition: WordAccumulator.php:102
MediaWiki\Diff\WordAccumulator\$line
$line
Definition: WordAccumulator.php:39
MediaWiki\Diff
Definition: ComplexityException.php:22
MediaWiki\Diff\WordAccumulator\$tag
$tag
Definition: WordAccumulator.php:41
MediaWiki\Diff\WordAccumulator\$insClass
$insClass
Definition: WordAccumulator.php:35
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Diff\WordAccumulator
Stores, escapes and formats the results of word-level diff.
Definition: WordAccumulator.php:34
MediaWiki\Diff\WordAccumulator\$group
$group
Definition: WordAccumulator.php:40
MediaWiki\Diff\WordAccumulator\$lines
$lines
Definition: WordAccumulator.php:38
MediaWiki\Diff\WordAccumulator\addWords
addWords( $words, $tag='')
Definition: WordAccumulator.php:78
MediaWiki\Diff\WordAccumulator\flushGroup
flushGroup( $new_tag)
Definition: WordAccumulator.php:46
tag
</code > tag
Definition: citeParserTests.txt:225
group
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
Definition: citeParserTests.txt:349
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWiki\Diff\WordAccumulator\flushLine
flushLine( $new_tag)
Definition: WordAccumulator.php:63
MediaWiki\Diff\WordAccumulator\$delClass
$delClass
Definition: WordAccumulator.php:36