When users edit in VisualEditor, it can make the fields of a template "cramp up" and make the code basically unreadable in source editor, which many other editors (including myself) use due to how it allows them to gain a closer control of the text. (The VisualEditor does not allow for a lot of more complex formatting, and frankly is just annoying.) As well, the program AutoWikiBrowser (AWB) itself, which runs my bot, edits pages in source formatting. So, it's essential to keep the source format of the pages clean.
After some reading, I finally figured out how to use AWB to clean up pages with messy templates so that it can be actually edited in source editor! The one downside is that you have to make a rule for each field of the template. But once you make them once (and remember to save), you can edit any page (in AWB) and it will clear it up for you.
Instructions[]
You need to use advanced rules/advanced settings for this. I recommend making one base rule, then adding the rules for each field as subrules (named as the title of each field). That way, you can disable the base rule without having to disable a bunch of others, in case bot decides to act up on other pages.
For each subrule, the IF criteria should be:
- Contains
.\|(fieldname)\s
Where fieldname
is the name of the field. You MUST keep the parentheses. Don't delete the parentheses! Just replace the text fieldname
. For example, if the field shows up as |caption =
, then you would write
.\|(caption)\s
Then, make sure that the checkbox Regular Expression is checked.
For the FIND criteria, it should be:
|fieldname
- Replace with:
|fieldname
You are basically just replacing that fieldname which is on a single line, to the same fieldname but on another line. Therefore separating it from the text that would go before it.
Make sure regular expression is not checked for the FIND tab.
One final thing is to change the type to "Inside templates {{...}}" (at the top, beneath the name).
Now, you need a version of this for every field of the template. You can copy and paste rules by using ctrl-C and ctrl-V and it will just paste it right below it in the list. Then just change your field names and you are set.
Explanation[]
So, this took me an embarrassingly long time to figure out and I feel bad explaining something that is probably obvious to someone who knows regex, but I am doing it anyways in case someone who is reading this wants to try something themselves.
What this does is: It searches for any field that has text (that is not a new line) before the |
(vertical bar) that separates fields of a template. However, it doesn't look at bars in images or links and etc. Though if you name your template fields things like "thumb" or "300", then you might have to narrow your criteria a bit and add in the enter signs. (I'm just lazy)
Regex is just sort of confusing in general, but I used Wikipedia's article on regular expression for AWB for most of it. Here is each part:
Part of regex | Definition | Why it's there |
---|---|---|
.
|
Any character except newline | It detects if there is a character that is not a newline behind the next part of what we're looking for. |
\| | Escape character \ and vertical bar | | To look for a vertical bar. (Vertical means something else in regex, so you have to tell it that you're not looking for that.) |
(fieldname)
|
Capture group (captures anything between the parentheses) | To look for the exact text that is between the parentheses. You can't just use the escape character, because the escape character isn't an escape character before letters, it has actual meaning then (I don't know why it's like that either). |
\s
|
White space character | To look for a space. (If your templates are scrunched up with the equals sign beside the text, you might have a bad time, and you should replace this with something else.) |
If a string of text meets ALL those requirements, then AWB will go to the find and replace. And, it doesn't find and replace what the regex is referring to - it finds what is in the FIND criteria box. That's why making the type of rule "within templates" is important, because then if a page has multiple of the same template on one page, it won't apply the criteria to things outside of the template (I think).
If you have any more good AWB or regex tricks that might be useful, please leave them in the comments too! Thanks!