Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 02:08, 14 September 2016 by commons>Jarekt (Protected Module:City: Widely used template ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
Module documentation[ create · purge ]
This documentation is transcluded from Module:City/doc.
local p = {}

function p._city(place, lang, link)

    -- === STEP 1: if "place" is empty than do nothing ==============
	if (not place) or (place == "") then
		return ""
	end
	
	--=== STEP 2: Check if "place" already has a link and if so than skip the rest of the template  ==============
	if string.match(place, "[%{%{|%[%[].+[%}%}|%]%]]") then
		return place
	end
	
    -- === STEP 3: Check if "place"  holds a q-code or matches any of the hardwired names  ==============
	local wikidata = require("Module:Wikidata")
	if string.match(place, "^Q%d+$") then
		return wikidata._getLabel(place, {lang = lang, link = link})
	else
		local LookupTable = require("Module:City/data")
		local item = LookupTable[mw.ustring.lower(place)]
		if item then
			return wikidata._getLabel(item, {lang = lang, link = link})
		end
	end

	-- === STEP 4: Check if {{{1}}} matches existing template, gallery or category and if so provide the link  ===
	if #place>=3 and #place<40 then
		local page = mw.title.new( place, '' )
		if page and page.exists then
			return "[[" .. place .. "]]"
		end
		page = mw.title.new( place, 'category' )
		if page and page.exists then
			return string.format("[[:Category:%s|%s]]", place,place) 
		end 
	end

	-- return as is
	return place
end

function p.city(frame)
	local args = frame.args
	args.place = mw.text.trim(args.place)
	if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then 
		args.lang = mw.message.new( "lang" ):plain() -- get user's chosen language 
	end
	if (not args.link) or (mw.text.trim(args.link) == "") then
		args.link = "wikipedia"
	end
	return p._city(args.place, args.lang, args.link)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.