Page MenuHomePhabricator

Provide a #foreach function
Closed, ResolvedPublic

Description

Author: rene.kijewski

Description:
patch against r43444 (see comment)

Hello,

there where many requests for generic loop functions. I don't think that this genericity is really needful, but a function to split a string by a delimiter and do something for each substring would be.
Consider you want to make a wiki list of "a/b/c/d". Currently it is posible to some degree using #titleparts. And it is done already this way, and by likely bad hacks as well ([[Template:Loop]]). It would be much more easy (and I think it'd go easy on resources, too) if you could iterate the parts like that:

{{#foreach:a/b/c/d|/|n|<nowiki />

  • {{{n}}} }}

where the first parameter is the string to split, the second is the delimiter and the third is the variable to contain the substrings. The last parameter is the action to be done for each substring.

I wrote a little extension to provide just that. Unfortunately, I don't know how to count the ressources used, so someone had to add this.


Version: unspecified
Severity: enhancement

Attached:

Details

Reference
bz16340

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:27 PM
bzimport set Reference to bz16340.
bzimport added a subscriber: Unknown Object (MLST).

herd wrote:

http://www.mediawiki.org/wiki/Extension:ForeachFunction
http://www.mediawiki.org/wiki/Extension:LoopFunctions
http://www.mediawiki.org/wiki/Extension:Loops

There are at least 3 extensions that do this now. These most likely won't be included in the ParserFunctions extension.

If you want one of these enabled on Wikimedia that would be a separate bug.