Extension talk:LoopFunctions

can you please provide a foreach function that will take a text, separator, param pattern, output separator, replacement and, will split the text with the first separator, iterate over the resulting array, replacing the param in pattern (so if an item is foo1_bar, and the param pattern is foo$n$_bar, then $n$ is 1), creating another array that is then joined with the output separator?

LoopFunctions + VariablesExtension
So I'm trying to combine these two extensions with frustrating results. If I have the following:

*

I get these results:


 * 0
 * 1
 * 1
 * 1
 * 1
 * 1
 * 1
 * 1

It looks like the #vardefine and #var functions inside the loop are getting resolved before the loop even starts. For the life of me, I can't figure out if it's a problem with the LoopFunctions, the VariablesExtension, or both. &mdash;Sledged 22:37, 19 January 2007 (UTC)


 * I tried to help you out...I guess you can't nest for loops.

{{#for:7 | {{#expr:+1}} {{#for:1 | {{#vardefine:odd|{{#expr:+1}} }} }}


 * Mcpaige 04:47, 28 February 2007 (UTC)


 * Fortunately, I've found a solution. —Sledged (talk) 04:14, 25 September 2007 (UTC)

LoopFunctions + Template
This might not be the best way to do this, but here goes.

On page Table I put  , the template TheInfoList looks like this   . There are a bunch of templates named TheInfo1, TheInfo2, TheInfo3, TheInfo... which actually in turn look like this   and of course TheInfo handles all the html and formating and stuff. The loop does not handle templates, what I get on page Table is
 * Template:TheInfo1
 * Template:TheInfo2
 * Template:TheInfo3
 * Template:TheInfo4

with links, the templates are not being included. Any ideas ? Mcpaige 04:26, 28 February 2007 (UTC)


 * This is along the lines of the mentioned limitation. I expanded that section.--Patrick 12:09, 28 February 2007 (UTC)

Hooks (aka "Custom HTML Tags")
They don't seem to work inside a looping function.

I have Extension:Colorize installed and when I do this:

NS:Somepage

Template:foo

I get this: 1 2

As you can see, the "rep$n$" ouside of the "colorize" hook gets replaces as expected, but not the one inside.

Edit: It doesn't matter if I "include" Extension:Colorize before or after Extension:LoopFunctions in LocalSettings.php

Egingell 03:42, 27 April 2007 (UTC)

Version Special Page disappears
Im using Mediawiki 1.10, and as long as the LoopFunctions extension is installed, my Version-Page is just empty. Any idea? --Die Backe, 91.3.112.102 12:38, 29 May 2007 (UTC)
 * This is caused by the special u with double dot character in the author's name. Edit LoopFunctions.php and change this character in the version array construct to a simple 'u'.  Sorry author. 60.240.113.86 14:23, 1 July 2007 (UTC)

Notice: Undefined variable
Any idea why I'm getting this notice? Notice: Undefined variable: return in /foo/wiki/extensions/LoopFunctions/LoopFunctions.php on line 67 --D0li0 01:27, 12 October 2007 (UTC)
 * 1) How do you disable the Notice messages?
 * 2) How do you define a "local" variable such as the $return variable in question?


 * Someone needs to add the following line to the public function foreachHook in the LoopFunctions.php to prevent the error above due to the uninitialized variable $return. This is not unlike the function above foreachHook, but needs to be done again as the variable is not a global.

$return = '';
 * And out of curiosity, it is wise to use a variable named return? Why not output, myfooness or something that is not a reserved word? --D0li0 21:45, 12 October 2007 (UTC)


 * Weird. My wiki had been working fine, and then without changes or reboot, I got this problem in conjunction with the AWC Forum extension.  Changing LoopFunctions.php as above fixed the problem. 60.240.122.215 23:28, 10 July 2008 (UTC)

Pass index value as parameter to template
Trying to create something like:

...but it doesn't work. Suspect the pipe character '|', which is used to provide the parameter to the template, is confusing the for loop and it's trying to use 'param=$n$' as a replacement parameter.

Is this understaning correct, and if so, can anybody recommend an alternative to achieve the above? Cocjh1 12:49, 21 November 2007 (UTC)


 * It's the way MediaWiki (or rather when) parses templates, variables, and parser functions. The parameter are parsed before they're passed to the underlying parser function.  So you example is the same as:




 * with the exception that after the template is expanded, any instance of '$n$' in the resulting text is replaced by number of that iteration.


 * Just what, exactly, are you expecting? And what you instead getting?  —Sledged (talk) 20:59, 21 November 2007 (UTC)


 * Thanks for the response Sledged, but sorry, it's my bad. The loop works just fine and it's my testing that was at fault.  Have switched over to use the Extension:Control Structure Functions now though, so may just stick with them.


 * Thanks anyway Cocjh1 13:01, 22 November 2007 (UTC)


 * You're welcome. Glad you found a solution.  Excellent extension choice.  —Sledged (talk) 22:04, 26 November 2007 (UTC)

Is it MW 1.12 friendly?
I was very happy with this extension, until I upgraded MW to 1.12. It doesn't work anymore. Has anybody experienced any problems at all with upgrades? --Cartoro 10:47, 10 April 2008 (UTC)


 * Yes, I experience problems since my 1.12 upgrade. For the  function, the error messages look like :

Warning: current [function.current]: Passed variable is not an array or object in /path/to/mediawiki/extensions/LoopFunctions/LoopFunctions.php on line 56 Warning: array_key_exists [function.array-key-exists]: The second argument should be either an array or an object in /path/to/mediawiki/extensions/LoopFunctions/LoopFunctions.php on line 61
 * It is due to the type of, which is not an array.
 * --Xiloynaha 11:37, 13 August 2008 (UTC)


 * I just adapted LoopFunctions to MW 1.12, see the extension page. It is not fully tested, but it seems to work… --Xiloynaha 14:47, 13 August 2008 (UTC)

Is it MW 1.13 friendly?
I need this extension under MW 1.13alpha. I get these errors : Warning: current [function.current]: Passed variable is not an array or object in ...../LoopFunctions/LoopFunctions.php on line 59 Warning: array_key_exists [function.array-key-exists]: The second argument should be either an array or an object in ...../LoopFunctions/LoopFunctions.php on line 64 I upgraded MW from 1.10 where everything was working fine. Anyone any ideas ? --217.6.3.114 16:11, 22 July 2008 (UTC)


 * Maybe you should try my patch (version 1.0.4), since I got the same message than you with MW 1.12, maybe that will work for MW 1.13 too. --Xiloynaha 14:47, 13 August 2008 (UTC)
 * I downloaded and installed your patched files, but still get the following notice and no result is returned. Any ideas what's still wrong?

Notice: Undefined variable: return in .../LoopFunctions/LoopFunctions.php on line 96 --217.6.3.114 13:01, 19 August 2008 (UTC)