User blog:Sinthorion/Editable Polls

This is another small wikicode trick, that can be very useful in some situations, but also allows poll result manipulation. It's a trick to make polls editable.

This guide requires you to know how to use and create simple templates.

What are polls?
If you don't know polls at all, here is a short introduction:

Did you ever create an own poll? Yes No I'm not sure

This is a poll. Everyone, including anonymous users, can vote in it. All votes are anonymous. The wikicode for it looks like this: Did you ever create an own poll? Yes No I'm not sure The first line is the question, every other line is a new option. Make sure to use the source edit mode for it to prevent double newlines.

The Limitations
Polls have one small limitation: If you change the content (for example to fix a typo in the question or to add another option), this will be seen as a new poll and all votes will be reset to 0.

The Trick
I found one trick to circumvent this: Usage of templates! If the content of a poll is a template, then the template can be edited and the poll won't be reset.

Now, you usually don't want to create a new template for every poll. So here is another trick: Use transclusion to use the page where the poll is as a template itself! There are two ways to do that:
 * Encapsulate the template part of the page with both  and   tags. This will make sure the page itself does not include the template and the template does not include the rest of the page.
 * Alternatively, encapsulate the template part with the  and all the rest of the page with the   tags. This has exactly the same effect.

Now put all lines inside the poll in the template part and use the template between the poll tags. This is some example code for a page that uses this trick: This page features an editable poll Is this poll editable? Yes No Where "Namespace:NameOfThisPage" has to be replaced by the correct name. Leave the namespace empty (but don't remove the colon) if you are in the article (Main) namespace.

After editing the poll template, you might have to purge the page to see the results.

Going Further
The code shown above means the page can also include only editable poll, because every usage as template will have a different result. The following code will solve this problem too. I won't go into further detail on this one, except for a link to the used #switch parser function.