Module:Mainonly

From OtherX
Revision as of 12:40, 20 January 2024 by OtherXAdmin (talk | contribs) (Created page with "--[[ {{Helper module|name=Mainonly |fname1=_main(arg) |ftype1=Any value |fuse1=If the module is invoked in the content namespace, it will return arg, otherwise, it will return an empty string |fname2=on_main() |ftype2=N/A |fuse2=Returns true if invoked in the content namespace, otherwise false }} --]] -- -- Module to return text only when invoked in the content namespace -- local p = {} function p.main(frame) local ret = frame:getParent().args[1] or '' return p._main...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Mainonly/doc. [edit] [history] [purge]

This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
_main(arg)Any valueIf the module is invoked in the content namespace, it will return arg, otherwise, it will return an empty string
on_main()N/AReturns true if invoked in the content namespace, otherwise false

--[[
{{Helper module|name=Mainonly
|fname1=_main(arg)
|ftype1=Any value
|fuse1=If the module is invoked in the content namespace, it will return arg, otherwise, it will return an empty string
|fname2=on_main()
|ftype2=N/A
|fuse2=Returns true if invoked in the content namespace, otherwise false
}}
--]]
--
-- Module to return text only when invoked in the content namespace
--

local p = {}

function p.main(frame)
	local ret = frame:getParent().args[1] or ''
	return p._main(ret)
end

function p._main(text)
	if mw.title.getCurrentTitle().namespace == 0 then
		return text
	else
		return ''
	end
end

--
-- Boolean for whether or not the page is in the mainspace
-- Sometimes it might be better to just check first
-- Rather than spend processing time on something that won't be used
function p.on_main()
	return mw.title.getCurrentTitle().namespace == 0
end

return p