MediaWiki master
PPTemplateFrame_Hash.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
11
16// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
18
22 public $namedArgs;
24 public $parent;
29
37 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
38 $namedArgs = [], $title = false
39 ) {
40 parent::__construct( $preprocessor );
42 '@phan-var PPFrame_Hash $parent';
43
44 $this->parent = $parent;
45 $this->numberedArgs = $numberedArgs;
46 $this->namedArgs = $namedArgs;
47 $this->title = $title;
48 $pdbk = $title ? $title->getPrefixedDBkey() : false;
49 $this->titleCache = $parent->titleCache;
50 $this->titleCache[] = $pdbk;
51 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
52 if ( $pdbk !== false ) {
53 $this->loopCheckHash[$pdbk] = true;
54 }
55 $this->depth = $parent->depth + 1;
56 $this->numberedExpansionCache = $this->namedExpansionCache = [];
57 }
58
59 public function __toString() {
60 $s = 'tplframe{';
61 $first = true;
62 $args = $this->numberedArgs + $this->namedArgs;
63 foreach ( $args as $name => $value ) {
64 if ( $first ) {
65 $first = false;
66 } else {
67 $s .= ', ';
68 }
69 $s .= "\"$name\":\"" .
70 str_replace( '"', '\\"', $value->__toString() ) . '"';
71 }
72 $s .= '}';
73 return $s;
74 }
75
82 public function cachedExpand( $key, $root, $flags = 0 ) {
83 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
84 return $this->parent->childExpansionCache[$key];
85 }
86 $retval = $this->expand( $root, $flags );
87 if ( !$this->isVolatile() ) {
88 $this->parent->childExpansionCache[$key] = $retval;
89 }
90 return $retval;
91 }
92
98 public function isEmpty() {
99 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
100 }
101
105 public function getArguments() {
106 $arguments = [];
107 foreach ( array_merge(
108 array_keys( $this->numberedArgs ),
109 array_keys( $this->namedArgs ) ) as $key ) {
110 $arguments[$key] = $this->getArgument( $key );
111 }
112 return $arguments;
113 }
114
118 public function getNumberedArguments() {
119 $arguments = [];
120 foreach ( $this->numberedArgs as $key => $_ ) {
121 $arguments[$key] = $this->getArgument( $key );
122 }
123 return $arguments;
124 }
125
129 public function getNamedArguments() {
130 $arguments = [];
131 foreach ( $this->namedArgs as $key => $_ ) {
132 $arguments[$key] = $this->getArgument( $key );
133 }
134 return $arguments;
135 }
136
141 public function getNumberedArgument( $index ) {
142 if ( !isset( $this->numberedArgs[$index] ) ) {
143 return false;
144 }
145 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
146 # No trimming for unnamed arguments
147 $this->numberedExpansionCache[$index] = $this->parent->expand(
148 $this->numberedArgs[$index],
150 );
151 }
152 return $this->numberedExpansionCache[$index];
153 }
154
159 public function getNamedArgument( $name ) {
160 if ( !isset( $this->namedArgs[$name] ) ) {
161 return false;
162 }
163 if ( !isset( $this->namedExpansionCache[$name] ) ) {
164 # Trim named arguments post-expand, for backwards compatibility
165 $this->namedExpansionCache[$name] = trim(
166 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
167 }
168 return $this->namedExpansionCache[$name];
169 }
170
175 public function getArgument( $name ) {
176 $text = $this->getNumberedArgument( $name );
177 if ( $text === false ) {
178 $text = $this->getNamedArgument( $name );
179 }
180 return $text;
181 }
182
188 public function isTemplate() {
189 return true;
190 }
191
193 public function setVolatile( $flag = true ) {
194 parent::setVolatile( $flag );
195 $this->parent->setVolatile( $flag );
196 }
197
199 public function setTTL( $ttl ) {
200 wfDeprecated( __METHOD__, '1.46' );
201 parent::setTTL( $ttl );
202 $this->parent->setTTL( $ttl );
203 }
204}
205
207class_alias( PPTemplateFrame_Hash::class, 'PPTemplateFrame_Hash' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
An expansion frame, used as a context to expand the result of preprocessToObj()
isVolatile()
Get the volatile flag.
Expansion frame with template arguments.
isTemplate()
Return true if the frame is a template frame.
isEmpty()
Returns true if there are no arguments in this frame.
__construct( $preprocessor, $parent=false, $numberedArgs=[], $namedArgs=[], $title=false)
setVolatile( $flag=true)
Set the volatile flag.
setTTL( $ttl)
since 1.44, use ParserOutput::updateCacheExpiry()
Represents a title within MediaWiki.
Definition Title.php:69
getPrefixedDBkey()
Get the prefixed database key form.
Definition Title.php:1845