PreloadRedLinks adds the preload argument to red links on pages according to rules defined, which can be site-wide or user defined as needed.
Installation
Configuration
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.
Using configuration options with Fandom Developers Wiki scripts
The instructions on this page describe how to use configuration options with a script. Here on the Fandom Developers Wiki, many scripts provide optional configuration settings as a mean to alter or enhance the default behavior of the script. When installing configuration options in your JavaScript file, please note that they need to go above the import statement in order to work — unless the directions say otherwise. In case MediaWiki:ImportJS is used to load the scripts, it will be executed last.
// 1. AjaxRC import statement
importArticles({
type: 'script',
articles: [
'u:dev:MediaWiki:AjaxRC.js'
]
});
// 2. AjaxRC configuration option
window.ajaxRefresh = 30000;
// 1. AjaxRC configuration option
window.ajaxRefresh = 30000;
// 2. AjaxRC import statement
importArticles({
type: 'script',
articles: [
'u:dev:MediaWiki:AjaxRC.js'
]
});
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
nullif no preload templates is needed.
Usage
To use the tool, you have to create the required pages:
MediaWiki:Custom-PreloadRedLinks(or whatever you set aswindow.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.
- You will add here the list of the templates you want to preload, followed by a pipe (
- For each preload template you listed, you have to create it.
Example
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
}