MediaWiki 1.40.4
PPTemplateFrame_Hash.php
Go to the documentation of this file.
1<?php
23
28// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
30
34 public $namedArgs;
36 public $parent;
41
49 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
50 $namedArgs = [], $title = false
51 ) {
52 parent::__construct( $preprocessor );
54 '@phan-var PPFrame_Hash $parent';
55
56 $this->parent = $parent;
57 $this->numberedArgs = $numberedArgs;
58 $this->namedArgs = $namedArgs;
59 $this->title = $title;
60 $pdbk = $title ? $title->getPrefixedDBkey() : false;
61 $this->titleCache = $parent->titleCache;
62 $this->titleCache[] = $pdbk;
63 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
64 if ( $pdbk !== false ) {
65 $this->loopCheckHash[$pdbk] = true;
66 }
67 $this->depth = $parent->depth + 1;
68 $this->numberedExpansionCache = $this->namedExpansionCache = [];
69 }
70
71 public function __toString() {
72 $s = 'tplframe{';
73 $first = true;
74 $args = $this->numberedArgs + $this->namedArgs;
75 foreach ( $args as $name => $value ) {
76 if ( $first ) {
77 $first = false;
78 } else {
79 $s .= ', ';
80 }
81 $s .= "\"$name\":\"" .
82 str_replace( '"', '\\"', $value->__toString() ) . '"';
83 }
84 $s .= '}';
85 return $s;
86 }
87
95 public function cachedExpand( $key, $root, $flags = 0 ) {
96 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
97 return $this->parent->childExpansionCache[$key];
98 }
99 $retval = $this->expand( $root, $flags );
100 if ( !$this->isVolatile() ) {
101 $this->parent->childExpansionCache[$key] = $retval;
102 }
103 return $retval;
104 }
105
111 public function isEmpty() {
112 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
113 }
114
118 public function getArguments() {
119 $arguments = [];
120 foreach ( array_merge(
121 array_keys( $this->numberedArgs ),
122 array_keys( $this->namedArgs ) ) as $key ) {
123 $arguments[$key] = $this->getArgument( $key );
124 }
125 return $arguments;
126 }
127
131 public function getNumberedArguments() {
132 $arguments = [];
133 foreach ( array_keys( $this->numberedArgs ) as $key ) {
134 $arguments[$key] = $this->getArgument( $key );
135 }
136 return $arguments;
137 }
138
142 public function getNamedArguments() {
143 $arguments = [];
144 foreach ( array_keys( $this->namedArgs ) as $key ) {
145 $arguments[$key] = $this->getArgument( $key );
146 }
147 return $arguments;
148 }
149
154 public function getNumberedArgument( $index ) {
155 if ( !isset( $this->numberedArgs[$index] ) ) {
156 return false;
157 }
158 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
159 # No trimming for unnamed arguments
160 $this->numberedExpansionCache[$index] = $this->parent->expand(
161 $this->numberedArgs[$index],
163 );
164 }
165 return $this->numberedExpansionCache[$index];
166 }
167
172 public function getNamedArgument( $name ) {
173 if ( !isset( $this->namedArgs[$name] ) ) {
174 return false;
175 }
176 if ( !isset( $this->namedExpansionCache[$name] ) ) {
177 # Trim named arguments post-expand, for backwards compatibility
178 $this->namedExpansionCache[$name] = trim(
179 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
180 }
181 return $this->namedExpansionCache[$name];
182 }
183
188 public function getArgument( $name ) {
189 $text = $this->getNumberedArgument( $name );
190 if ( $text === false ) {
191 $text = $this->getNamedArgument( $name );
192 }
193 return $text;
194 }
195
201 public function isTemplate() {
202 return true;
203 }
204
205 public function setVolatile( $flag = true ) {
206 parent::setVolatile( $flag );
207 $this->parent->setVolatile( $flag );
208 }
209
210 public function setTTL( $ttl ) {
211 parent::setTTL( $ttl );
212 $this->parent->setTTL( $ttl );
213 }
214}
Represents a title within MediaWiki.
Definition Title.php:82
getPrefixedDBkey()
Get the prefixed database key form.
Definition Title.php:1911
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)
const STRIP_COMMENTS
Definition PPFrame.php:33