PreloadRedLinks

PreloadRedLinks adds the preload argument to red links on pages according to rules defined, which can be site-wide or user defined as needed.
== ==
== ==
The script can be used as it is when used site-wide, but it does also support these customizable variables that can be added before the import on Common.js. Common.js will run before MediaWiki:ImportJS.
window.preloadRedLinks_rules
* It could be the full page name of the configuration page. The default value is "MediaWiki:Custom-PreloadRedLinks".
* It could be a JavaScript function that defines the rule. It should take the page name of the redlinks' targets, and returns the page name of the corresponding preload template, or null if no preload templates is needed.
== ==
To use the tool, you have to create the required pages:
* MediaWiki:Custom-PreloadRedLinks (or whatever you set as window.preloadRedLinks_rules. Or ignore it if a JS callback function is used as the rule.)
** You will add here the list of the templates you want to preload, followed by a pipe (|) and the regex which matches the target page name. Everything in a wikitext bulleted list (the list made by *) will be treated as a template name. Rules at the top will have higher priority.
* For each preload template you listed, you have to create it.
== ==
=== Default ===
Using the default configuration, if on MediaWiki:Custom-PreloadRedLinks we add:
* Template:Preload/version | Version/.+
* Template:Preload/Template doc | Template:.+/doc
With this code, all red links which which is a subpage of Version will come with their preload template created as Template:Preload/version. And all red links of template documents will come with Template:Preload/Template doc.
=== Equivalent JS function ===
{{{example-JS-desc|Defining JS functions as the rules can be more flexible and allows more complex rules. As no config page in MediaWiki namespace is needed in this way, the script can be used fully personally (though you have to make sure that the preload templates you use exist).
As an example, the above default rule can be achieved by:
window.preloadRedLinks_rules = function(pagename){
 if (pagename.startsWith("Version/")) { 
 return "Template:Preload/version";
 }
 if (pagename.startsWith("Template:") && pagename.endsWith("/doc")) { 
 return "Template:Preload/Template doc";
 }
 return null
}