Auto-Formatter is a user script that semi-automatically fixes more than 200 common errors in thewiki markup. The script was originally created for the German Wikipedia but can be used in all languages. Please note that the script may make mistakes. Pleasereport errors (you can write English or German).
Seede:User:TMg/autoFormatter for the full documentation (German).
Copy and paste the following line either to your local common.js subpage, e.g.your common.js on the English Wikipedia, or toyour global.js on Meta to activate it on all Wikimedia wikis.
mw.loader.load('//de.wikipedia.org/w/index.php?title=Benutzer:TMg/autoFormatter.js&action=raw&ctype=text/javascript');
Additionally I highly recommendmy cleanDiff script. It makes it a lot easier to review the changes made by the script when pressing the "Show changes" button.
The label andtooltip of the "Auto-Format" button can be localized:
varautoFormatterButtonLabel='Auto-Format';
If you want to use the script on external wikis that don't support linking to Wikimedia wikis with the short syntax[[:en:Wikipedia]] you can disable the feature set:
varautoFormatWikimediaLinks=false;
If you don't want deprecated keywords likeImage: replaced you can turn this feature set off:
varautoFormatLocalisation=false;
Links like[[New York|New York City]] are most probably wrong or at least misleading and therefore replaced with[[New York]] City. You can turn this feature off:
varautoFormatMaskedLinks=false;
In the German Wikipedia year ranges like "2001–02" are expanded to "2001–2002". This feature is disabled in all other languages. Please tell me ifyour local manual of style recommends that too and I should turn it on for your language. If you want you can turn it on for yourself:
varautoFormatShortYearRanges=true;
Example:
varredundantTemplateParameters=['Infobox single|Name','Infobox company|name'];
To disable the feature:
varredundantTemplateParameters=[];
Example:
varautoFormatTemplates=[{name:'Infobox example 1',format:'|_________________ = _\n'},{name:'Infobox example 2',format:'|__________________ = _\n',parameters:{'Old parameter':'New parameter','Deprecated parameter':false}}];
For now, seethe German documentation for the full explanation.
Example:
varautoFormatReplacements=[['Ph.D.','PhD'],[/ +<ref\b/g,'<ref']];
The first rule is a simple "string to string" replacement. It replaces all "Ph.D."abbreviations (including "Ph. D." with spaces andnon-breaking spaces) with "PhD".
The second rule uses aregular expression to remove all spaces in front offootnotes (ref tags).
Seethe German documentation for more examples.
You need to hit the "Auto-Format" button (
) in the toolbar to run the script.
var autoFormatLocalisation = false; is set in your common.js.The following tags are protected from almost all replacements except for a few special character replacements:<code>,<hiero>,<html>,<includeonly>,<math>,<nowiki>,<pre>,<score>,<source>,<syntaxhighlight>,<timeline>.
File names are protected:
[[File:…]]File: prefix).File names are cleaned:
%20 with single spaces.File : Example.jpg.­ and such with­.[A-Z\]ªµºÀ-ÖØ-öø-\u02B8]).‎.prettytable CSS class name towikitable.attribute = "value"."), dashes (e.g.—,–), and daggers (e.g.†). .<source> with<syntaxhighlight>.<strike> with<s>.<nowiki /> tags.<font family="…"> if it contains default fonts only (Arial, Helvetica, Helvetica Neue and sans-serif).<font size="…"> if it's the default font size.<br>,<hr>,<nowiki> and tags withstyle="clear:…;".<font> and<span> with no attributes.<font color="…"> with<span>.<font size="…"> with<small> or<span> if applicable.<span><span>.<br /> including optional attributes.<br /> if there is a break anyway.<small> tags inside and outside of<ref>,<sub>,<sup> and other<small> tags.class="BoxenVerschmelzen" if it contains only one navigation bar.DISPLAYTITLE,File:,thumb and so on.vertical-align:)baseline,middle and so on.right.upright|thumb tothumb|upright if it's not the only change in the line.miniatur tomini if it's not the only change in the line./00 from the end of coordinates.<ref> and<references> tags.<ref /> and<references /> tags.<references> if the closing tag is missing.<references /> tag.<references> block in some specific cases.<ref> tags, but not inside a<references> block.fullurl: links.[[Link|Label]]s to[[Link|Labels]] because it's more readable.[[Link|Links]] to[[Link]]s because it's shorter.[[New York|New York City]] to[[New York]] City (can be disabled by the user).[[2001-01-01]] (ISO format) or[[2001/1/1]].The following rules do not apply to interwiki links.
The following rules do not apply to interwiki links.
<sup>erscripted characters with the Unicode characters ² and ³ (only in the German Wikipedia).Format ISBN numbers, simplify the prefix and add dashes to the proper places depending on the language (currently only English and German books). Does work for both the ISBN magic word and template parameters calledISBN = or similar.
Remove useless "name" or "title" parameters from many often used infoboxes and other templates if the parameter is empty or equal to the article name. See the "cleanRedundantTemplateParameters" sectionin the source for a full list.
This can be used to make infoboxes and all other templates well readable in the source of the articles, remove deprecated parameters and rename parameters. Checkthe German documentation for the required syntax. By default onlythe German Persondata template is processed.
This can be used to apply all kinds of user-defined replacements either by using simple string-to-string replacements or complex regular expressions with optional replacement functions. You can find some examplesabove andin the German documentation.