한국   대만   중국   일본 
Модуль:Wikidata/redLink ? В?к?педыя Перайсц? да зместу

Модуль : Wikidata/redLink

З В?к?педы?, свабоднай энцыклапеды?

local
 p
 =
 {};


function
 p
.
formatRedLink
(
title
,
 text
,
 entityId
,
 infobox
)

	if
 infobox
 ==
 nil
 or
 infobox
 ==
 ''
 then

		infobox
 =
 'Ун?версальная картка'

	end

	return
 mw
.
ustring
.
format
(

		'<span class="plainlinks">[//be.wikipedia.org/w/index.php?title=%s&action=edit <span style="color: #ba0000; text-decoration: inherit; -moz-text-decoration-color: #ba0000; text-decoration-color: #ba0000;">%s</span>]</span>'
,

		mw
.
uri
.
encode
(
title
),
 mw
.
text
.
nowiki
(
text
)

	)

end


function
 p
.
formatRedLinkWithInfobox
(
title
,
 text
,
 entityId
,
 defaultInfobox
)

	return
 p
.
formatRedLink
(
title
,
 text
,
 entityId
,
 p
.
getInfobox
(
entityId
,
 defaultInfobox
))

end


function
 p
.
getInfobox
(
entityId
,
 defaultInfobox
)

	if
 defaultInfobox
 then

		return
 defaultInfobox

	end

	if
 entityId
 then

		local
 result
 =
 mw
.
wikibase
.
getBestStatements
(
entityId
,
 'P31'
)

		for
 _
,
 statement
 in
 pairs
(
result
)
 do

			if
 statement
.
mainsnak
.
datavalue
 then

				local
 type
 =
 statement
.
mainsnak
.
datavalue
.
value
.
id

				if
		type
 ==
 'Q5'
	then
 return
 p
.
getBioInfobox
(
entityId
)

				elseif
	type
 ==
 'Q523'
	then
 return
 'Зорка'

				elseif
	type
 ==
 'Q318'
	then
 return
 'Галактыка'

				end

			end

		end

	end

	return
 'Ун?версальная картка'

end


function
 p
.
getBioInfobox
(
entityId
)

	if
 entityId
 then

		local
 result
 =
 mw
.
wikibase
.
getBestStatements
(
entityId
,
 'P106'
)

		for
 _
,
 statement
 in
 pairs
(
result
)
 do

			if
 statement
.
mainsnak
.
datavalue
 then

				local
 occupation
 =
 statement
.
mainsnak
.
datavalue
.
value
.
id

				if
 occupation
 ==
 'Q901'
 then
 return
 'Вучоны'

				end

			end

		end

	end

	return
 'Асоба'

end


function
 p
.
formatRedLinkFromTemplate
(
frame
)

	local
 args
 =
 frame
[
'args'
]

	if
 not
 args
[
1
]
 then
 -- may be arguments are passed from the parent template?

		args
 =
 frame
:
getParent
().
args

	end

	
	if
 not
 args
[
1
]
 then

		return
 '<span class="error">Не пазначаны элемент В?к?даных</span>'

	end

	local
 entityId
 =
 mw
.
text
.
trim
(
args
[
1
])


	local
 title
 =
 mw
.
wikibase
.
label
(
entityId
)

	if
 not
 title
 then

		return
 mw
.
ustring
.
format
(
'<span class="error">Няма метк? ? элемента %s</span>'
,
 entityId
)

	elseif
 mw
.
ustring
.
match
(
title
,
 '[%[%]:]'
)
 then
 -- cannot create page with this name

		return
 title

	end

	local
 text
 =
 title

	if
 args
[
2
]
 then

		text
 =
 mw
.
text
.
trim
(
args
[
2
])

	end

	
	local
 sitelink
 =
 mw
.
wikibase
.
sitelink
(
entityId
)

	if
 sitelink
 then

		if
 text
 ==
 sitelink
 then

			return
 '[['
 ..
 sitelink
 ..
 ']]'

		else

			return
 '[['
 ..
 sitelink
 ..
 '|'
 ..
 text
 ..
 ']]'

		end

	end
	

	return
 p
.
formatRedLinkWithInfobox
(
title
,
 text
,
 entityId
,
 args
[
3
])

end


return
 p