Module:Property page

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Property page/doc

Code

--[[  
                                                                                            
This module is intended to be the engine behind "Template:Property_page".

Please do not modify this code without applying the changes first at
"Module:Information/sandbox" and testing at "Module:Property_page/testcases".

Authors and maintainers:
* User:Jarekt - original version 
]]
-- =======================================
-- === Dependencies ======================
-- =======================================
require('strict') -- used for debugging purposes as it detects cases of unintended global variables
local Label = require('Module:Wikidata label')
local core  = require('Module:Core')

-- ===========================================================================
-- === functions to be called from template namespace
-- ===========================================================================
local p = {}

-------------------------------------------------------------------------------
function p.property_page(frame)
	-- get page name and extract property ID
	local pid
	local page = mw.title.getCurrentTitle()
	local namespace = page.namespace   -- get page namespace
	local pagename  = page.text
	if namespace==1 and mw.ustring.sub( pagename, 1, 9 ) == 'Property:' then -- "main" (Gallery) namespace
		pid = mw.ustring.sub( pagename, 10, -1 )
	else
		pid = 'P6243'
	end
	local page = {}
	local header = '=' .. mw.wikibase.getLabel(pid) .. ' (' .. pid .. ')='
	table.insert(page, header)
	table.insert(page, 'Page with all information related to property '.. pid .. ' and how it is used on Commons in [[Commons:Structured Data|SDC]] statements.')
	return table.concat(page,"\n")
end

return p