Minecraft Wiki
Advertisement

Dit is de documentatiepagina voor Module:Downloadlinks

Dit is de documentatiepagina, het moet worden getranscludeerd op de bijbehorende pagina. Zie Sjabloon:Documentatie voor meer informatie.

Description

This module creates download links based on hashes stored in subpage /hashes. It looks up hashes there based on template calls.

It is highly recommended to also have some JavaScript which removes empty p elements. Those are apparantly also generated by the module, yet there doesn't seem to be any good reason to do so.

Individual elements

Table i18n

local i18n = {
    process_args = 'Module:ProcessArgs',
    hashes = 'Module:DarkShadowTNT/downloadlinks/hashes',
    category = 'Categorie:Ongeldige downloadlink',

    version_error = '[[Sjabloon:Downloadlink|Geen of incorrecte versie gegeven]]',
    variant_error = '[[Sjabloon:Downloadlink|Geen of incorrecte variant gegeven]]',
    hash_error = '[[Sjabloon:Downloadlink|Geen hash gevonden]]',

    client = 'Client',
    server = 'Server',
    windows_server = 'Windowsserver',
    json = '.json',
    json_package = '.json',
    
    nowiki_template = 'nw',
}

In here:

  • process_args: Module where process arguments are located.
  • hashes: Module where hashes are stored.
  • category: (including namespace) Category where pages should be added to when no download link could be constructed.
  • version_error: What to show when no version could be found in the hash module.
  • variant_error: What to show when no variant could be found (e.g. client, server, etc.).
  • hash_error: What to show when no hash could be found.
  • client: Default text for a client download link.
  • server: Default text for a server download link.
  • windows_server: Default text for a Windows server download link.
  • json: Default text for a JSON download link.
  • json_package: Default text for JSON shown in-browser.
  • nowiki_template: Name of template where a self-closing nowiki element is located. This is necessary to prevent the module from generating illogical pres.

Getting and checking arguments from template call

Getting

Using

-- Checks before constructing
if args[1] then
	version = mw.text.trim(tostring(args[1])):lower()
elseif args.v then -- args.v is deprecated, yet still here for backwards compatibility
	version = mw.text.trim(tostring(args.v)):lower()
end
	
if args[2] then
	variant = mw.text.trim(tostring(args[2])):lower()
elseif args.s then -- args.s is deprecated, yet still here for backwards compatibility
	variant = mw.text.trim(tostring(args.s)):lower()
end

the module gets the mandatory arguments from the template call.

NOTICE: If a previous version of this module has not been used ever before, the deprecated argument checks may be safely removed.

Checking

After the module got the arguments, a further check is done to find out if all arguments are valid, that is, if the given mandatory parameters (version and variant) in the template are in the hashes module.

-- Check if version or variant outputs nil
if version_data[version] == nil then
    text = i18n['version_error']
    return text .. category
elseif version_data[version][variant] == nil then
    text = i18n['variant_error']
    return text .. category
end

If version or variant do not pass this test, the module stops, returns an error message and adds the page to the given category (category = if the page is in the main namespace).

If the hash is somehow nil (either set to that or unintended) in the hashes module, the module returns a 'download link' with text explaining no hash could be found (this might be redundant after the version and variant checks, but better safe than sorry).

Downloaded and in-browser JSON

By utilising

-- Start constructing
-- Check if variant also outputs a hash as 'json_package' (only works when force_download is NOT set)
if variant == 'json' and not args.force_download then
    hash = version_data[version]['json_package']
    if hash ~= nil then
    	variant = 'json_package'
    else
    	variant = 'json'
    	hash = version_data[version]['json']
    end
end

the module checks if there's also a json_package hash in the hashes module for the specified version. If there's such a hash found, it'll construct a link based on json_package rather than a download link. To prevent this from happening, set parameter {{{force_download}}}.

windows shorthand

If, rather than windows_server, windows is used for a Windows server download link, the module converts that to windows_server internally by utilising

-- Check if variant is 'windows' and then change it to 'windows_server'
if variant == 'windows' then
	variant = 'windows_server'
end

Custom link text

If default text is unwanted, the module can add custom text using

-- Check if text parameter exists, if not, use default
if args[3] then
	text = args[3]
elseif args.beschrijving then -- args.beschrijving is deprecated, yet still here for backwards compatibility
	text = args.beschrijving
else
	text = i18n[variant]
end

NOTICE: If a previous version of this module has not been used ever before, the deprecated argument check may be safely removed.

Other

When a link is returned by the module, it will be an external link, plus the nowiki template put behind it. This will prevent unwanted pres from happening.



Advertisement