3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 namespace MediaWiki\Parser
;
27 * @property PPDPart_Hash[] $parts
28 * @property int $startPos
30 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
31 class PPDStackElement_Hash
{
33 * @var string Opening character (\n for heading)
38 * @var string Matching closing character
43 * @var string Saved prefix that may affect later processing,
44 * e.g. to differentiate `-{{{{` and `{{{{` after later seeing `}}}`.
46 public $savedPrefix = '';
49 * @var int Start offset of this element in the source wikitext
54 * @var int Number of opening characters found (number of "=" for heading)
59 * @var PPDPart_Hash[] Array of PPDPart objects describing pipe-separated parts.
64 * @var bool True if the open char appeared at the start of the input line.
65 * Not set for headings.
70 public $partClass = PPDPart_Hash
::class;
72 public function __construct( $data = [] ) {
73 $class = $this->partClass
;
74 $this->parts
= [ new $class ];
76 foreach ( $data as $name => $value ) {
77 $this->$name = $value;
81 public function &getAccum() {
82 return $this->parts
[count( $this->parts
) - 1]->out
;
85 public function addPart( $s = '' ) {
86 $class = $this->partClass
;
87 $this->parts
[] = new $class( $s );
91 * @return PPDPart_Hash
93 public function getCurrentPart() {
94 return $this->parts
[count( $this->parts
) - 1];
100 public function getFlags() {
101 $partCount = count( $this->parts
);
102 $findPipe = $this->open
!= "\n" && $this->open
!= '[';
104 'findPipe' => $findPipe,
105 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts
[$partCount - 1]->eqpos
),
106 'inHeading' => $this->open
== "\n",
111 * Get the accumulator that would result if the close is not found.
113 * @param int|false $openingCount
116 public function breakSyntax( $openingCount = false ) {
117 if ( $this->open
== "\n" ) {
118 $accum = array_merge( [ $this->savedPrefix
], $this->parts
[0]->out
);
120 if ( $openingCount === false ) {
121 $openingCount = $this->count
;
123 $s = substr( $this->open
, 0, -1 );
125 substr( $this->open
, -1 ),
126 $openingCount - strlen( $s )
128 $accum = [ $this->savedPrefix
. $s ];
131 foreach ( $this->parts
as $part ) {
134 } elseif ( is_string( $accum[$lastIndex] ) ) {
135 $accum[$lastIndex] .= '|';
137 $accum[++
$lastIndex] = '|';
140 foreach ( $part->out
as $node ) {
141 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
142 $accum[$lastIndex] .= $node;
144 $accum[++
$lastIndex] = $node;
153 /** @deprecated class alias since 1.43 */
154 class_alias( PPDStackElement_Hash
::class, 'PPDStackElement_Hash' );