MediaWiki REL1_39
PPTemplateFrame_Hash.php
Go to the documentation of this file.
1<?php
26// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
28
32 public $namedArgs;
34 public $parent;
39
47 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
48 $namedArgs = [], $title = false
49 ) {
50 parent::__construct( $preprocessor );
52 '@phan-var PPFrame_Hash $parent';
53
54 $this->parent = $parent;
55 $this->numberedArgs = $numberedArgs;
56 $this->namedArgs = $namedArgs;
57 $this->title = $title;
58 $pdbk = $title ? $title->getPrefixedDBkey() : false;
59 $this->titleCache = $parent->titleCache;
60 $this->titleCache[] = $pdbk;
61 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
62 if ( $pdbk !== false ) {
63 $this->loopCheckHash[$pdbk] = true;
64 }
65 $this->depth = $parent->depth + 1;
66 $this->numberedExpansionCache = $this->namedExpansionCache = [];
67 }
68
69 public function __toString() {
70 $s = 'tplframe{';
71 $first = true;
72 $args = $this->numberedArgs + $this->namedArgs;
73 foreach ( $args as $name => $value ) {
74 if ( $first ) {
75 $first = false;
76 } else {
77 $s .= ', ';
78 }
79 $s .= "\"$name\":\"" .
80 str_replace( '"', '\\"', $value->__toString() ) . '"';
81 }
82 $s .= '}';
83 return $s;
84 }
85
93 public function cachedExpand( $key, $root, $flags = 0 ) {
94 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
95 return $this->parent->childExpansionCache[$key];
96 }
97 $retval = $this->expand( $root, $flags );
98 if ( !$this->isVolatile() ) {
99 $this->parent->childExpansionCache[$key] = $retval;
100 }
101 return $retval;
102 }
103
109 public function isEmpty() {
110 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
111 }
112
116 public function getArguments() {
117 $arguments = [];
118 foreach ( array_merge(
119 array_keys( $this->numberedArgs ),
120 array_keys( $this->namedArgs ) ) as $key ) {
121 $arguments[$key] = $this->getArgument( $key );
122 }
123 return $arguments;
124 }
125
129 public function getNumberedArguments() {
130 $arguments = [];
131 foreach ( array_keys( $this->numberedArgs ) as $key ) {
132 $arguments[$key] = $this->getArgument( $key );
133 }
134 return $arguments;
135 }
136
140 public function getNamedArguments() {
141 $arguments = [];
142 foreach ( array_keys( $this->namedArgs ) as $key ) {
143 $arguments[$key] = $this->getArgument( $key );
144 }
145 return $arguments;
146 }
147
152 public function getNumberedArgument( $index ) {
153 if ( !isset( $this->numberedArgs[$index] ) ) {
154 return false;
155 }
156 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
157 # No trimming for unnamed arguments
158 $this->numberedExpansionCache[$index] = $this->parent->expand(
159 $this->numberedArgs[$index],
161 );
162 }
163 return $this->numberedExpansionCache[$index];
164 }
165
170 public function getNamedArgument( $name ) {
171 if ( !isset( $this->namedArgs[$name] ) ) {
172 return false;
173 }
174 if ( !isset( $this->namedExpansionCache[$name] ) ) {
175 # Trim named arguments post-expand, for backwards compatibility
176 $this->namedExpansionCache[$name] = trim(
177 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
178 }
179 return $this->namedExpansionCache[$name];
180 }
181
186 public function getArgument( $name ) {
187 $text = $this->getNumberedArgument( $name );
188 if ( $text === false ) {
189 $text = $this->getNamedArgument( $name );
190 }
191 return $text;
192 }
193
199 public function isTemplate() {
200 return true;
201 }
202
203 public function setVolatile( $flag = true ) {
204 parent::setVolatile( $flag );
205 $this->parent->setVolatile( $flag );
206 }
207
208 public function setTTL( $ttl ) {
209 parent::setTTL( $ttl );
210 $this->parent->setTTL( $ttl );
211 }
212}
An expansion frame, used as a context to expand the result of preprocessToObj()
expand( $root, $flags=0)
Preprocessor $preprocessor
isVolatile()
Get the volatile flag.
Expansion frame with template arguments.
cachedExpand( $key, $root, $flags=0)
isEmpty()
Returns true if there are no arguments in this frame.
isTemplate()
Return true if the frame is a template frame.
setVolatile( $flag=true)
Set the volatile flag.
__construct( $preprocessor, $parent=false, $numberedArgs=[], $namedArgs=[], $title=false)
getPrefixedDBkey()
Get the prefixed database key form.
Definition Title.php:1878
const STRIP_COMMENTS
Definition PPFrame.php:31
if( $line===false) $args
Definition mcc.php:124
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s