MediaWiki REL1_34
PPTemplateFrame_Hash.php
Go to the documentation of this file.
1<?php
26// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
28
31
39 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
40 $namedArgs = [], $title = false
41 ) {
42 parent::__construct( $preprocessor );
44 '@phan-var PPFrame_Hash $parent';
45
46 $this->parent = $parent;
47 $this->numberedArgs = $numberedArgs;
48 $this->namedArgs = $namedArgs;
49 $this->title = $title;
50 $pdbk = $title ? $title->getPrefixedDBkey() : false;
51 $this->titleCache = $parent->titleCache;
52 $this->titleCache[] = $pdbk;
53 $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
54 if ( $pdbk !== false ) {
55 $this->loopCheckHash[$pdbk] = true;
56 }
57 $this->depth = $parent->depth + 1;
58 $this->numberedExpansionCache = $this->namedExpansionCache = [];
59 }
60
61 public function __toString() {
62 $s = 'tplframe{';
63 $first = true;
64 $args = $this->numberedArgs + $this->namedArgs;
65 foreach ( $args as $name => $value ) {
66 if ( $first ) {
67 $first = false;
68 } else {
69 $s .= ', ';
70 }
71 $s .= "\"$name\":\"" .
72 str_replace( '"', '\\"', $value->__toString() ) . '"';
73 }
74 $s .= '}';
75 return $s;
76 }
77
85 public function cachedExpand( $key, $root, $flags = 0 ) {
86 if ( isset( $this->parent->childExpansionCache[$key] ) ) {
87 return $this->parent->childExpansionCache[$key];
88 }
89 $retval = $this->expand( $root, $flags );
90 if ( !$this->isVolatile() ) {
91 $this->parent->childExpansionCache[$key] = $retval;
92 }
93 return $retval;
94 }
95
101 public function isEmpty() {
102 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
103 }
104
108 public function getArguments() {
109 $arguments = [];
110 foreach ( array_merge(
111 array_keys( $this->numberedArgs ),
112 array_keys( $this->namedArgs ) ) as $key ) {
113 $arguments[$key] = $this->getArgument( $key );
114 }
115 return $arguments;
116 }
117
121 public function getNumberedArguments() {
122 $arguments = [];
123 foreach ( array_keys( $this->numberedArgs ) as $key ) {
124 $arguments[$key] = $this->getArgument( $key );
125 }
126 return $arguments;
127 }
128
132 public function getNamedArguments() {
133 $arguments = [];
134 foreach ( array_keys( $this->namedArgs ) as $key ) {
135 $arguments[$key] = $this->getArgument( $key );
136 }
137 return $arguments;
138 }
139
144 public function getNumberedArgument( $index ) {
145 if ( !isset( $this->numberedArgs[$index] ) ) {
146 return false;
147 }
148 if ( !isset( $this->numberedExpansionCache[$index] ) ) {
149 # No trimming for unnamed arguments
150 $this->numberedExpansionCache[$index] = $this->parent->expand(
151 $this->numberedArgs[$index],
153 );
154 }
155 return $this->numberedExpansionCache[$index];
156 }
157
162 public function getNamedArgument( $name ) {
163 if ( !isset( $this->namedArgs[$name] ) ) {
164 return false;
165 }
166 if ( !isset( $this->namedExpansionCache[$name] ) ) {
167 # Trim named arguments post-expand, for backwards compatibility
168 $this->namedExpansionCache[$name] = trim(
169 $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
170 }
171 return $this->namedExpansionCache[$name];
172 }
173
178 public function getArgument( $name ) {
179 $text = $this->getNumberedArgument( $name );
180 if ( $text === false ) {
181 $text = $this->getNamedArgument( $name );
182 }
183 return $text;
184 }
185
191 public function isTemplate() {
192 return true;
193 }
194
195 public function setVolatile( $flag = true ) {
196 parent::setVolatile( $flag );
197 $this->parent->setVolatile( $flag );
198 }
199
200 public function setTTL( $ttl ) {
201 parent::setTTL( $ttl );
202 $this->parent->setTTL( $ttl );
203 }
204}
if( $line===false) $args
Definition cdb.php:64
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:1806
const STRIP_COMMENTS
Definition PPFrame.php:31