Module:Module link
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
![]() | This module depends on the following other modules: |
This module provides a link for all Scribunto module pages. It checks if a sandbox page of the module exists and if truly it exists then it returns both the link for the module and the link for the sandbox. This module can be used in wikitext pages and in Scribunto module pages.
- For wikitext pages(templates):
{{#invoke:Module link|main|Module:[name]}}
- For Scribunto module pages [example]:
local p = {}
local mModuleLink = require('Module:Module link')._main
function p.example(frame)
return mModuleLink({link="Module:Example"})
end
return p
Note: Change example to the name of the Module you want. This module implements {{Module link}} please use the template instead.
Examples
Wikitext
Gives
{{#invoke:Module link|main|Module:Arguments}}
{{#invoke:Module link|main|Module:Module link}}
Module:Module link (sandbox) -- because Module:Module link has a sandbox page, the link to the sandbox appears.
{{#invoke:Module link|main|Module:Module link|detectSandbox=off}}
Module:Module link -- because detectSandbox is set to off, the link to the sandbox page is now hidden.
Errors
When the link parameter is not provided, or it might but the value maybe empty, then the module returns an error stating: Error: parameter, value or both maybe missing, please inspect the codes carefully.
Error handling
- Please check, if you made a mistake in the coding, and try again. If the error continues then feel free to leave a message at this page's talkpage or at Codemini's talkpage. But sincerely speaking the error might be your mistake. You might want to check the parameter to see if it is in accordance with the one below.
Parameters
|1=
|link=
- A specific module name.
|detectSandbox=
- For advanced template coding, when set to detectSandbox="off" hides the link to the sandbox page. Please refer to the examples below on how to use on pages and modules. Go to this page's talkpage to discuss any issue.
Example(templates): {{#invoke:Module link|link=Module:Example|detectSandbox=off}} or {{ml|link=Module:Example|detectSandbox=off}}
Example(modules):
local p = {}
local mModuleLink = require('Module:Module link')._main
function p.main(frame)
args = frame.args
link = args[1] or args.link
return mModuleLink({link=link, detectSandbox = "off"}) .. ' ([[Module talk:'..link..'|talk]])'
end
return p
-- implements {{ml}}
local ml = {} -- in this case ml serves as the package name
local getArgs = require('Module:Arguments').getArgs
local format = mw.ustring.format -- alternatively we can use string.format
local function err(msg) -- get errors
return format('<strong class="error">Error: %s</strong>', msg)
end
-- new function »
function ml.main(frame) -- this is for only templates
args = getArgs(frame)
return ml._main(args)
end
function ml._main(args) -- this is for modules only
name = args[1] or args.link
if name then
name = args[1] or args.link
elseif name == nil then
return err('parameter, value or both maybe missing, please inspect the codes carefully.') -- make new error
end
sandbox = mw.title.new(name .. '/sandbox')
if args.detectSandbox and args.detectSandbox == "off"
then
return format("[[:%s]]", name)
elseif sandbox and sandbox.exists then
return format("[[:%s]] ([[:%s|sandbox]])", name, sandbox.fullText)
else return format("[[:%s]]", name)
end
end
return ml