| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Parser; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PPDStackElement_Hash { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public $open; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public $close; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public $savedPrefix = ''; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public $startPos; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public $count; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public $parts; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public $lineStart; |
| 68 |
|
| 69 |
|
| 70 |
public $partClass = PPDPart_Hash::class; |
| 71 |
|
| 72 |
public function __construct( $data = [] ) { |
| 73 |
$class = $this->partClass; |
| 74 |
$this->parts = [ new $class ]; |
| 75 |
|
| 76 |
foreach ( $data as $name => $value ) { |
| 77 |
$this->$name = $value; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public function &getAccum() { |
| 82 |
return $this->parts[count( $this->parts ) - 1]->out; |
| 83 |
} |
| 84 |
|
| 85 |
public function addPart( $s = '' ) { |
| 86 |
$class = $this->partClass; |
| 87 |
$this->parts[] = new $class( $s ); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public function getCurrentPart() { |
| 94 |
return $this->parts[count( $this->parts ) - 1]; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public function getFlags() { |
| 101 |
$partCount = count( $this->parts ); |
| 102 |
$findPipe = $this->open != "\n" && $this->open != '['; |
| 103 |
return [ |
| 104 |
'findPipe' => $findPipe, |
| 105 |
'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ), |
| 106 |
'inHeading' => $this->open == "\n", |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public function breakSyntax( $openingCount = false ) { |
| 117 |
if ( $this->open == "\n" ) { |
| 118 |
$accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out ); |
| 119 |
} else { |
| 120 |
if ( $openingCount === false ) { |
| 121 |
$openingCount = $this->count; |
| 122 |
} |
| 123 |
$s = substr( $this->open, 0, -1 ); |
| 124 |
$s .= str_repeat( |
| 125 |
substr( $this->open, -1 ), |
| 126 |
$openingCount - strlen( $s ) |
| 127 |
); |
| 128 |
$accum = [ $this->savedPrefix . $s ]; |
| 129 |
$lastIndex = 0; |
| 130 |
$first = true; |
| 131 |
foreach ( $this->parts as $part ) { |
| 132 |
if ( $first ) { |
| 133 |
$first = false; |
| 134 |
} elseif ( is_string( $accum[$lastIndex] ) ) { |
| 135 |
$accum[$lastIndex] .= '|'; |
| 136 |
} else { |
| 137 |
$accum[++$lastIndex] = '|'; |
| 138 |
} |
| 139 |
|
| 140 |
foreach ( $part->out as $node ) { |
| 141 |
if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) { |
| 142 |
$accum[$lastIndex] .= $node; |
| 143 |
} else { |
| 144 |
$accum[++$lastIndex] = $node; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
return $accum; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
class_alias( PPDStackElement_Hash::class, 'PPDStackElement_Hash' ); |