Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Wikibase-navigation
Create a new Item
Create a new Property
Query Service
Item by title
wikibase
Search
Search
English
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:AuthorsDisplay
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Page information
In other projects
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- Module:AuthorsDisplay -- Purpose: Display all authors linked to a Wikibase item via P2 (Has author), -- along with each author's country from P14 (Has Country) -- Usage: {{#invoke:AuthorsDisplay|main}} local p = {} --- Main function: Fetches authors from the current page's sitelinked Wikibase item -- and renders them in a wiki table with their countries. -- -- @function p.main -- @param frame The Lua frame object (contains template arguments) -- @return string A wiki table showing authors and their countries, or error message function p.main(frame) -- Fetch the Wikibase entity linked to the current MediaWiki page -- mw.wikibase.getEntity() with no parameter gets the sitelinked item local entity = mw.wikibase.getEntity() -- Validate: Check if entity exists and has P2 (author) claims if not entity or not entity.claims or not entity.claims.P2 then return "<i>No authors found.</i>" end -- Extract all P2 (Has author) statements from the entity local authors = entity.claims.P2 -- Initialize the wiki table with headers local output = '{| class="wikitable" style="border-collapse: collapse;"\n' output = output .. '|-\n! Author !! Country\n' -- Loop through each author claim in P2 for _, claim in ipairs(authors) do -- Verify this claim is a valid wikibase-item with an actual value -- (not a "somevalue" or "novalue" placeholder) if claim.mainsnak.datatype == "wikibase-item" and claim.mainsnak.snaktype == "value" then -- Extract the item ID of the author (e.g., "Q5") local authorId = claim.mainsnak.datavalue.value.id -- Fetch the full Wikibase entity for this author local authorEntity = mw.wikibase.getEntity(authorId) -- Process this author only if the entity was successfully retrieved if authorEntity then -- Get the author's label (human-readable name) -- Falls back to the item ID if no label exists local authorLabel = authorEntity:getLabel() or authorId -- Initialize country as "Unknown" (default value) local country = "Unknown" -- Try to retrieve P14 (country) from the author's statements if authorEntity.claims and authorEntity.claims.P14 then -- Get the first P14 claim (in case there are multiple) local countryClaim = authorEntity.claims.P14[1] -- Extract the country value only if it's a string datatype if countryClaim and countryClaim.mainsnak.datatype == "string" then country = countryClaim.mainsnak.datavalue.value end end -- Append a new table row with author label and country output = output .. '|-\n| ' .. authorLabel .. ' || ' .. country .. '\n' end end end -- Close the wiki table output = output .. '|}\n' -- Return the formatted wiki table as a string return output end -- Return the module table containing the main function return p
Summary:
Please note that all contributions to wikibase may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Wikibase:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Page included on this page:
Module:AuthorsDisplay/doc
(
edit
)
Search
Search
Editing
Module:AuthorsDisplay
Add languages
Add topic