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)
 * I fixed the Notice by adding a local variable 'return' to the foreach-Function, but still get no result when using the function. Is foreach working for you? --Jailing 09:15, 16 September 2008 (UTC)
 * As said in my talk page, it seems that you have to name the parameters when you call a template with foreach. I'll try to fix that. See the discussion with Jailing for details. --Xiloynaha 07:28, 19 September 2008 (UTC)

Fixed (see my talkpage). Please let me now if you experience any more problem, I'll try to fix when I'll have time for (that's the most difficult !). --Xiloynaha 19:28, 23 October 2008 (UTC)
 * Thanks again for your time Xiloynaha. The extension now works like a charm! One more thing: I had to increase the maximum number of loops to 500 for a rather long dynamic list in our wiki (where the loop function is called several times) to display as wanted. You wouldn't think this might lead to problems, would you? --Jailing 16:29, 17 December 2008 (UTC)
 * 500 is quite high, but I don't think it may cause problems other than the server load. But I am not qualified to guarantee anything ;-)
 * I suppose you modified the $mMaxLoopCount variable in the extension code? Or it is possible to declare it into the LocalSettings.php file? If not, it could be a good feature to add…
 * --Xiloynaha 21:47, 17 December 2008 (UTC)

Does NOT work with MW 1.15
I am running MW 1.15.1. Installing this extension takes down my whole wiki. When I comment out the line in LocalSettings.php that calls this extension, everything works. When I uncomment it, my wiki pages are all blank. --Deutne 11:44, 2 June 2010 (UTC)
 * Hi! I run several MW 1.15.1 with LoopFunctions, and it works fine for me, so I'm not sure I'll be able to help you… What is your configuration? Do you have something in your web server logs? What extra extensions do you have? How do you call LoopFunctions in your LocalSettings.php? --Xiloynaha 12:01, 2 June 2010 (UTC)
 * My configuration: OS Ubuntu 10.04; MediaWiki 1.15.1; PHP 5.3.2-1ubuntu4.1 (apache2handler); MySQL 5.1.41-3ubuntu12. The relevant line in my LocalSettings.php file is: require_once ( "$IP/extensions/LoopFunctions/LoopFunctions.php" ); The problem occurred when my only installed extension was the LoopFunctions. I also tested LoopFunctions after adding Parser Functions (Version 1.1.1), Variables (Version 1.2.2), and ArrayExtension (Version 1.2.2). I continue to get blank pages. I don't have an error message to convey yet, but I can try turning on more error reporting via my php.ini file. --Deutne 22:39, 2 June 2010 (UTC)
 * Here is the error message: "Warning: Parameter 1 to Language::getMagic expected to be a reference, value given in /usr/share/mediawiki/includes/StubObject.php on line 58"--Deutne 22:47, 2 June 2010 (UTC)
 * I think the warning message is unrelated to the LoopFunctions problem:, but until I fixed that problem, I didn't get a useful error message about the problem with LoopFunctions. It seems to me that the problem with LoopFunctions was that LocalSettings.php was looking in the LoopFunctions directory, but the tar file extracted to a LoopFunctions-1.0.5 directory. I changed the name of the directory and am hoping things will work now. --Deutne 09:30, 3 June 2010 (UTC)

Issues with 1.16.1
The basic for loop functionality works, but when it comes to passing template arguments, it doesn't replace it. The examples that demonstrate how to call the foo template does not seem to work. Is this a known issue? Any work-arounds? --XTsukihime 15:54, 1 March 2011 (UTC)
 * Second that. I tried to do something like but it doesn't work. Extensions:Control Structure Functions "redirect" people instead to Extension:Loops, while its still experimental. I'm stuck. Bennylin 09:04, 25 April 2011 (UTC)
 * This is weird because LoopFunctions version 1.0.5 worked for me with MediaWiki 1.16.5. Anyway, Version 1.0.6 works with MW 1.16 and above so you can try it (in the unlikely case you still use it!). --Xiloynaha (talk) 00:07, 6 June 2014 (UTC)

This extension is not working with Mediawiki > 1.17
The procedure $wgMessageCache->addMessages( $value, $key ); is depracted.

See Manual:$wgMessageCache


 * Oops, I had fixed the code back in 2012, but apparently I completely forgot to publish the modification here. I just published the new code (working with MW 1.23 and previous versions as well) in an official Git repo and updated the extension's page. --Xiloynaha (talk) 00:01, 6 June 2014 (UTC)

Broken in 1.30
Last version I used the extension with was 1.26, so sometime between then and now, this extension broke. It now gives a lovely Parser.php error... Strict Standards: Non-static method ExtLoopFunctions::foreachHook should not be called statically in /var/www/html/wiki/includes/parser/Parser.php on line 4805 --140.192.242.150 20:55, 9 April 2018 (UTC)