MediaWiki REL1_40
PPDStackElement_Hash.php
Go to the documentation of this file.
1<?php
28// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
33 public $open;
34
38 public $close;
39
44 public $savedPrefix = '';
45
49 public $startPos;
50
54 public $count;
55
59 public $parts;
60
65 public $lineStart;
66
68 public $partClass = PPDPart_Hash::class;
69
70 public function __construct( $data = [] ) {
71 $class = $this->partClass;
72 $this->parts = [ new $class ];
73
74 foreach ( $data as $name => $value ) {
75 $this->$name = $value;
76 }
77 }
78
79 public function &getAccum() {
80 return $this->parts[count( $this->parts ) - 1]->out;
81 }
82
83 public function addPart( $s = '' ) {
84 $class = $this->partClass;
85 $this->parts[] = new $class( $s );
86 }
87
91 public function getCurrentPart() {
92 return $this->parts[count( $this->parts ) - 1];
93 }
94
98 public function getFlags() {
99 $partCount = count( $this->parts );
100 $findPipe = $this->open != "\n" && $this->open != '[';
101 return [
102 'findPipe' => $findPipe,
103 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
104 'inHeading' => $this->open == "\n",
105 ];
106 }
107
114 public function breakSyntax( $openingCount = false ) {
115 if ( $this->open == "\n" ) {
116 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
117 } else {
118 if ( $openingCount === false ) {
119 $openingCount = $this->count;
120 }
121 $s = substr( $this->open, 0, -1 );
122 $s .= str_repeat(
123 substr( $this->open, -1 ),
124 $openingCount - strlen( $s )
125 );
126 $accum = [ $this->savedPrefix . $s ];
127 $lastIndex = 0;
128 $first = true;
129 foreach ( $this->parts as $part ) {
130 if ( $first ) {
131 $first = false;
132 } elseif ( is_string( $accum[$lastIndex] ) ) {
133 $accum[$lastIndex] .= '|';
134 } else {
135 $accum[++$lastIndex] = '|';
136 }
137
138 foreach ( $part->out as $node ) {
139 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
140 $accum[$lastIndex] .= $node;
141 } else {
142 $accum[++$lastIndex] = $node;
143 }
144 }
145 }
146 }
147 return $accum;
148 }
149}
string $savedPrefix
Saved prefix that may affect later processing, e.g.
int $startPos
Start offset of this element in the source wikitext.
int $count
Number of opening characters found (number of "=" for heading)
bool $lineStart
True if the open char appeared at the start of the input line.
PPDPart_Hash[] $parts
Array of PPDPart objects describing pipe-separated parts.
breakSyntax( $openingCount=false)
Get the accumulator that would result if the close is not found.
string $close
Matching closing character.
string $open
Opening character (\n for heading)