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
23 * Expansion frame with template arguments
24 * @deprecated since 1.34, use PPTemplateFrame_Hash
27 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
28 class PPTemplateFrame_DOM
extends PPFrame_DOM
{
30 public $numberedArgs, $namedArgs;
36 public $numberedExpansionCache, $namedExpansionCache;
39 * @param Preprocessor $preprocessor
40 * @param bool|PPFrame_DOM $parent
41 * @param array $numberedArgs
42 * @param array $namedArgs
43 * @param bool|Title $title
45 public function __construct( $preprocessor, $parent = false, $numberedArgs = [],
46 $namedArgs = [], $title = false
48 parent
::__construct( $preprocessor );
50 $this->parent
= $parent;
51 $this->numberedArgs
= $numberedArgs;
52 $this->namedArgs
= $namedArgs;
53 $this->title
= $title;
54 $pdbk = $title ?
$title->getPrefixedDBkey() : false;
55 $this->titleCache
= $parent->titleCache
;
56 $this->titleCache
[] = $pdbk;
57 $this->loopCheckHash
= /*clone*/ $parent->loopCheckHash
;
58 if ( $pdbk !== false ) {
59 $this->loopCheckHash
[$pdbk] = true;
61 $this->depth
= $parent->depth +
1;
62 $this->numberedExpansionCache
= $this->namedExpansionCache
= [];
65 public function __toString() {
68 $args = $this->numberedArgs +
$this->namedArgs
;
69 foreach ( $args as $name => $value ) {
75 $s .= "\"$name\":\"" .
76 str_replace( '"', '\\"', $value->ownerDocument
->saveXML( $value ) ) . '"';
84 * @param string|int $key
85 * @param string|PPNode_DOM|DOMDocument $root
89 public function cachedExpand( $key, $root, $flags = 0 ) {
90 if ( isset( $this->parent
->childExpansionCache
[$key] ) ) {
91 return $this->parent
->childExpansionCache
[$key];
93 $retval = $this->expand( $root, $flags );
94 if ( !$this->isVolatile() ) {
95 $this->parent
->childExpansionCache
[$key] = $retval;
101 * Returns true if there are no arguments in this frame
105 public function isEmpty() {
106 return !count( $this->numberedArgs
) && !count( $this->namedArgs
);
109 public function getArguments() {
111 foreach ( array_merge(
112 array_keys( $this->numberedArgs
),
113 array_keys( $this->namedArgs
) ) as $key ) {
114 $arguments[$key] = $this->getArgument( $key );
119 public function getNumberedArguments() {
121 foreach ( array_keys( $this->numberedArgs
) as $key ) {
122 $arguments[$key] = $this->getArgument( $key );
127 public function getNamedArguments() {
129 foreach ( array_keys( $this->namedArgs
) as $key ) {
130 $arguments[$key] = $this->getArgument( $key );
137 * @return string|bool
139 public function getNumberedArgument( $index ) {
140 if ( !isset( $this->numberedArgs
[$index] ) ) {
143 if ( !isset( $this->numberedExpansionCache
[$index] ) ) {
144 # No trimming for unnamed arguments
145 $this->numberedExpansionCache
[$index] = $this->parent
->expand(
146 $this->numberedArgs
[$index],
147 PPFrame
::STRIP_COMMENTS
150 return $this->numberedExpansionCache
[$index];
154 * @param string $name
155 * @return string|bool
157 public function getNamedArgument( $name ) {
158 if ( !isset( $this->namedArgs
[$name] ) ) {
161 if ( !isset( $this->namedExpansionCache
[$name] ) ) {
162 # Trim named arguments post-expand, for backwards compatibility
163 $this->namedExpansionCache
[$name] = trim(
164 $this->parent
->expand( $this->namedArgs
[$name], PPFrame
::STRIP_COMMENTS
) );
166 return $this->namedExpansionCache
[$name];
170 * @param int|string $name
171 * @return string|bool
173 public function getArgument( $name ) {
174 $text = $this->getNumberedArgument( $name );
175 if ( $text === false ) {
176 $text = $this->getNamedArgument( $name );
182 * Return true if the frame is a template frame
186 public function isTemplate() {
190 public function setVolatile( $flag = true ) {
191 parent
::setVolatile( $flag );
192 $this->parent
->setVolatile( $flag );
195 public function setTTL( $ttl ) {
196 parent
::setTTL( $ttl );
197 $this->parent
->setTTL( $ttl );