Index: trunk/extensions/Loops/Loops.php |
— | — | @@ -161,24 +161,24 @@ |
162 | 162 | // no loops to perform |
163 | 163 | return ''; |
164 | 164 | } |
165 | | - |
166 | | - global $wgExtVariables; |
167 | | - |
| 165 | + |
168 | 166 | $output = ''; |
169 | 167 | $endVal = $startVal + $loops; |
| 168 | + $i = $startVal; |
170 | 169 | |
171 | | - while( $startVal !== $endVal ) { |
| 170 | + while( $i !== $endVal ) { |
172 | 171 | // limit check: |
173 | 172 | if( ! self::incrCounter( $parser ) ) { |
174 | 173 | return self::msgLoopsLimit( $output ); |
175 | 174 | } |
176 | 175 | |
177 | | - $wgExtVariables->vardefine( $parser, $varName, (string)$startVal ); |
| 176 | + // set current position as variable: |
| 177 | + self::setVariable( $parser, $varName, (string)$i ); |
178 | 178 | |
179 | 179 | $output .= trim( $frame->expand( $rawCode ) ); |
180 | 180 | |
181 | 181 | // in-/decrease loop count (count can be negative): |
182 | | - ( $startVal < $endVal ) ? $startVal++ : $startVal--; |
| 182 | + ( $i < $endVal ) ? $i++ : $i--; |
183 | 183 | } |
184 | 184 | return $output; |
185 | 185 | } |
— | — | @@ -245,8 +245,7 @@ |
246 | 246 | // unexpanded code: |
247 | 247 | $rawCode = array_shift( $funcArgs ); |
248 | 248 | $rawCode = $rawCode !== null ? $rawCode : ''; |
249 | | - |
250 | | - global $wgExtVariables; |
| 249 | + |
251 | 250 | $output = ''; |
252 | 251 | |
253 | 252 | // if prefix contains numbers only or isn't set, get all arguments, otherwise just non-numeric |
— | — | @@ -259,15 +258,11 @@ |
260 | 259 | continue; |
261 | 260 | } |
262 | 261 | if ( $keyVar !== $valVar ) { |
263 | | - // variable with the argument name as value |
264 | | - $wgExtVariables->vardefine( |
265 | | - $parser, |
266 | | - $keyVar, |
267 | | - trim( substr( $argName, strlen( $prefix ) ) ) |
268 | | - ); |
| 262 | + // variable with the argument name without prefix as value: |
| 263 | + self::setVariable( $parser, $keyVar, substr( $argName, strlen( $prefix ) ) ); |
269 | 264 | } |
270 | | - // variable with the arguments value |
271 | | - $wgExtVariables->vardefine( $parser, $valVar, trim( $argVal ) ); |
| 265 | + // variable with the arguments value: |
| 266 | + self::setVariable( $parser, $valVar, $argVal ); |
272 | 267 | |
273 | 268 | // expand current run: |
274 | 269 | $output .= trim( $frame->expand( $rawCode ) ); |
— | — | @@ -276,7 +271,34 @@ |
277 | 272 | return $output; |
278 | 273 | } |
279 | 274 | |
| 275 | + /** |
| 276 | + * Connects to 'Variables' extension and sets a variable. Handles different versions of |
| 277 | + * 'Variables' extension since there have changed some things along the way. |
| 278 | + * |
| 279 | + * @param Parser $parser |
| 280 | + * @param string $varName |
| 281 | + * @param string $varValue |
| 282 | + */ |
| 283 | + private static function setVariable( Parser &$parser, $varName, $varValue ) { |
| 284 | + global $wgExtVariables; |
| 285 | + |
| 286 | + static $newVersion = null; |
| 287 | + if( $newVersion === null ) { |
| 288 | + // find out whether local wiki is using variables extension 2.0 or higher |
| 289 | + $newVersion = ( defined( 'ExtVariables::VERSION' ) && version_compare( ExtVariables::VERSION, '1.9999', '>' ) ); |
| 290 | + } |
| 291 | + |
| 292 | + if( $newVersion ) { |
| 293 | + // clean way since Variables 2.0: |
| 294 | + ExtVariables::get( $parser )->setVarValue( $varName, $varValue ); |
| 295 | + } |
| 296 | + else { |
| 297 | + // make sure to trim values and convert them to string since old versions of Variables extension won't do this. |
| 298 | + $wgExtVariables->vardefine( $parser, trim( $varName ), trim( $varValue ) ); |
| 299 | + } |
| 300 | + } |
280 | 301 | |
| 302 | + |
281 | 303 | ############### |
282 | 304 | # Loops Count # |
283 | 305 | ############### |
Index: trunk/extensions/Loops/RELEASE-NOTES |
— | — | @@ -4,13 +4,12 @@ |
5 | 5 | * (trunk) -- Version 0.4 alpha by Daniel Werner |
6 | 6 | - The loops count now counts per parser instance. Before there were several hacks to reset the |
7 | 7 | counter, for example including an special page in wikitext. This has been solved now. |
| 8 | + - Compatbility to Variables Version 2.0. |
8 | 9 | - Language file clean-up. |
9 | 10 | - Internal structure changed, ExtLoops now works as a static class. |
10 | 11 | - '#fornumargs' parameter 1 can be empty to make it more consistent with other Loop parser |
11 | 12 | functions. E.g. '{{#fornumargs: | keyVarName | valVarName | code }}' istead of |
12 | 13 | '{{#fornumargs: keyVarName | valVarName | code }}' (which still works as well). |
13 | | - @ToDo: Open points for final 0.4 release: |
14 | | - - Compatbility to Variables Version 2.0. |
15 | 14 | |
16 | 15 | * November 15, 2011 -- Version 0.3.2 by Daniel Werner |
17 | 16 | - Bug solved where '#loop' didn't create variables with name or starting index '0'. |