User blog:Catinthedark/Infobox level: killing the massive switches

So you know those massive switches in Template:Infobox level? Well they were hate at first sight for me, so I wrote some replacement code that uses string matching instead. For each of current, previous, and next level links, there are now about three ifs and three calls to string match, instead of a 600+ line switch statement.

I did this in a test template called Template:CatinthedarkTest, which is "plugged in" at User:Catinthedark/Sandbox. It covers the same cases as the switch, and then some. I tested the general cases covered by the switch: N/A, Dreamworld level, Dreamworld Mobile level, Reality level.

I also made a small change WRT previous functionality, whereby "N/A" was made into a link: N/A, which redirects to level 1. I took the link out for this case.

If the changes are approved, I will need for an admin to briefly remove the protection on Template:Infobox level as I do not have accessss...... Alternatively, if an admin wants to port the code, they will need to be very careful and re-replace with  inside the ifeq statements that replace the ifs. (My template uses this additional parameter for testing.) There are also other changes in the file: only the three switch statements should be brought over.

The code should be much more efficient this way, however, any maintenance on that section will require a bit more thought. All you wikicoders out there... what do you think?

Thanks, Catinthedark (talk)