See edit at the bottom.
Feature summary (what you would like to be able to do and where):
See https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#Stripping_whitespace.
I want to be able to have whitespace characters at the beginning/end of a parameter and have a parameter that consists of nothing but whitespace.
Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
There are many, I ran into this before, but today my problem is this: I need to conditionally substitute some newlines. More specifically: I am working on a reply-link/DiscussionTools like script that can add a section. If the page already exists, it has to insert two newlines followed by the section. If the page doesn't exist yet, it should just post the section.
Here are various methods to solve my problem, none of which are ideal:
- Litter the place with <nowiki /> tags as instructed by mediawikiwiki. I hate litter and it doesn't work because because <nowiki />==Section title== doesn't work.
- Check if the page exists before posting. Increases the risk of failure, reduces responsiveness, complicates my code. I just need some newlines.
- Don't use the appendtext parameter from https://en.wikipedia.org/w/api.php?action=help&modules=edit, instead obtain page text (if any) and replace the full page text. See the previous method.
- Fuck it and insert the newlines regardless. Not so pretty if the page didn't exist yet.
- Use section=new. GREAT IDEA.
Too bad it trashes my edit summary.I have no idea what happened but it actually works fine. I figured forcing the default "→Title: new section" summary was a feature, but it isn't forced after all. I'll be using section:new then.
Benefits (why should this be implemented?):
Will cut my Tylenol budget in half.
Edit: okay, my problem today is solved. I already had a function to obtain the wikitext and it was even executed when adding a new section, but the response was discarded. Now I look at the response to determine if the page already exists and add the newlines if it does. That being said: mediawikiwiki describing foo{{#if:||<nowiki /> bar <nowiki />}}foo as a solution is really ugly and makes little sense since it's a workaround. It would be nice if we had {{SPACE}}, {{NEWLINE}} and {{TAB}} so one could use foo{{#if:||{{SPACE}}bar{{SPACE}}}}foo instead, including the ability to successfully subst those so for example a substed template could allow one to insert {{subst:NEWLINE}}{{subst:NEWLINE}}==Message for user=={{subst:NEWLINE}}Hello ~~~~ or '''Keep'''{{subst:SPACE}}.