Module:pages/templates
පෙනුම
- පහත දැක්වෙන උපදෙස්, Module:pages/templates/documentation හි පිහිටා ඇත. Module:pages/templates/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: root page • root page’s subpages • සබැඳි • transclusions • testcases • sandbox
This module implements {{pagename}} and {{pagetype}} and exports a template-callable function is_valid_pagename.
Detailed documentation
[සංස්කරණය]export.pagename_t
[සංස්කරණය]function export.pagename_t(frame)
Implementation of {{pagename}}.
export.pagetype_t
[සංස්කරණය]function export.pagetype_t(frame)
Implementation of {{pagetype}}.
export.page_is_large_t
[සංස්කරණය]function export.page_is_large_t(frame)
Implementation of {{page is large}}.
export.page_exists_t
[සංස්කරණය]function export.page_exists_t(frame)
Implementation of {{page exists}}.
export.is_valid_pagename
[සංස්කරණය]function export.is_valid_pagename(frame)
Adapted from Module:ugly hacks, which will be going away. Meant to be invoked directly.
Returns the string "valid" if the page name in |1= is a valid pagename, otherwise a blank string.
export.is_valid_page_name
[සංස්කරණය]function export.is_valid_page_name(frame)
Alternative entry point for is_valid_pagename.
-- Prevent substitution.
if mw.isSubsting() then
return require("Module:unsubst")
end
local export = {}
local en_utilities_module = "Module:en-utilities"
local headword_data_module = "Module:headword/data"
local headword_page_module = "Module:headword/page"
local languages_module = "Module:languages"
local scripts_module = "Module:scripts"
local links_module = "Module:links"
local pages_module = "Module:pages"
local parameters_module = "Module:parameters"
--[==[
Implementation of {{tl|pagename}}.
]==]
function export.pagename_t(frame)
local args = require(parameters_module).process(frame:getParent().args, {
["title"] = true,
})
local title = args.title
if not title then
return mw.loadData(headword_data_module).pagename
end
return require(headword_page_module).process_page(title, "no_fetch_content").pagename
end
--[==[
Implementation of {{tl|pagetype}}.
]==]
function export.pagetype_t(frame)
local args = require(parameters_module).process(frame:getParent().args, {
["article"] = {type = "boolean"},
["pagename"] = {demo = true},
})
local pagename = args.pagename
local pagetype = require(pages_module).get_pagetype(
pagename == nil and mw.title.getCurrentTitle() or
mw.title.new(pagename) or
error(("%s is not a valid page name"):format(mw.dumpObject(pagename)))
)
return args.article and (
pagetype:match("^user%f[%W]") and "a " .. pagetype or -- avoids "an user"
require(en_utilities_module).add_indefinite_article(pagetype)
) or pagetype
end
--[==[
Implementation of {{tl|page is large}}.
]==]
function export.page_is_large_t(frame)
local args = require(parameters_module).process(frame:getParent().args, {
[1] = true,
})
local pagename = args[1] or mw.loadData(headword_data_module).pagename
return require(headword_data_module).large_pages[pagename] and "true" or ""
end
--[==[
Implementation of {{tl|page exists}}.
]==]
function export.page_exists_t(frame)
local args = require(parameters_module).process(frame:getParent().args, {
[1] = {required = true, template_default = "a"},
use_exists = {type = "boolean"},
})
-- Here, we convert logical to physical not directly by calling logicalToPhysical(), which will not handle
-- non-mainspace pages correctly, but get_link_page(), which will do the same handling as full_link() does.
-- This will strip italics, bold, HTML comments, strip markers and soft hyphens (FIXME: this may or may not
-- be what we want), and normally will do diacritic stripping, but we turn this off by specifying Translingual
-- with script None. Specifying Translingual also has the effect that mammoth pages return the base page rather
-- than one of the splits.
local mul = require(languages_module).getByCode("mul", true)
local None = require(scripts_module).getByCode("None", true)
local physical_page = require(links_module).get_link_page(args[1], mul, None)
if not physical_page then
-- weird cases like a triple-brace parameter in the pagename
return ""
end
local title = mw.title.new(physical_page)
return title and (args.use_exists and title.exists or title:getContent()) and "true" or ""
end
--[==[
Adapted from [[Module:ugly hacks]], which will be going away. Meant to be invoked directly.
Returns the string {"valid"} if the page name in {{para|1}} is a valid pagename, otherwise a blank string.
]==]
function export.is_valid_pagename(frame)
local iargs = require(parameters_module).process(frame.args, {
[1] = true,
})
return require(pages_module).is_valid_page_name(iargs[1]) and "valid" or ""
end
--[==[
Alternative entry point for {{cd|is_valid_pagename}}.
]==]
function export.is_valid_page_name(frame)
return export.is_valid_pagename(frame)
end
return export