Editing Module:Set page header
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.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.
Latest revision | Your text | ||
Line 40: | Line 40: | ||
medium = {}, | medium = {}, | ||
edition = nil, | edition = nil, | ||
− | releaseDate = nil | + | releaseDate = nil |
− | |||
} | } | ||
local function getRegion( pagename ) | local function getRegion( pagename ) | ||
− | + | local index = pagename:match( 'CG%-(%a+)%-?' ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local index = pagename:match( '% | ||
local region = DATA.getRegion( index ) -- TODO: handle erroneous region (nil)? | local region = DATA.getRegion( index ) -- TODO: handle erroneous region (nil)? | ||
Line 64: | Line 52: | ||
local function getEdition( pagename ) | local function getEdition( pagename ) | ||
− | + | local index = pagename:match( 'CG%-%a+%-(%w+)' ) | |
− | local index = pagename:match( '% | ||
local edition = DATA.getEdition( index ) -- TODO: handle erroneous edition (nil)? | local edition = DATA.getEdition( index ) -- TODO: handle erroneous edition (nil)? | ||
Line 103: | Line 90: | ||
:wikitext( releaseData.region.full ) | :wikitext( releaseData.region.full ) | ||
:wikitext( releaseData.edition and ( ' - %s' ):format( releaseData.edition.full ) ) | :wikitext( releaseData.edition and ( ' - %s' ):format( releaseData.edition.full ) ) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
return tostring( header ) | return tostring( header ) | ||
Line 113: | Line 95: | ||
local function makeCategories( ns ) | local function makeCategories( ns ) | ||
− | + | return table.concat{ | |
− | ( '[[Category:%s %s]]' ):format( releaseData.region.full, ns ) | + | ( '[[Category:%s %s]]' ):format( releaseData.region.full, ns ), |
+ | releaseData.edition and ( '[[Category:%s %s]]' ):format( releaseData.edition.full, ns ), | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 138: | Line 105: | ||
['Set page'] = releaseData.set, | ['Set page'] = releaseData.set, | ||
['Local name'] = releaseData.localName, | ['Local name'] = releaseData.localName, | ||
− | |||
['Language'] = releaseData.language.full, | ['Language'] = releaseData.language.full, | ||
− | [' | + | ['Region'] = releaseData.region and releaseData.region.full, |
['Edition'] = releaseData.edition and releaseData.edition.full, | ['Edition'] = releaseData.edition and releaseData.edition.full, | ||
['Release date'] = releaseData.releaseDate | ['Release date'] = releaseData.releaseDate | ||
Line 149: | Line 115: | ||
-- @return table name, localName, releaseDate | -- @return table name, localName, releaseDate | ||
local function querySetData() | local function querySetData() | ||
− | + | return mw.smw.ask{ | |
'[[' .. releaseData.set .. ']]', | '[[' .. releaseData.set .. ']]', | ||
'?English name = name' , | '?English name = name' , | ||
'?' .. releaseData.language.full .. ' name = localName', | '?' .. releaseData.language.full .. ' name = localName', | ||
'?' .. releaseData.region.full .. ' release date = releaseDate', | '?' .. releaseData.region.full .. ' release date = releaseDate', | ||
− | |||
− | |||
− | |||
mainlabel = '-' | mainlabel = '-' | ||
} | } | ||
− | |||
− | |||
− | |||
end | end | ||
-- Set data for the `releaseData` table based on the page name and parameters | -- Set data for the `releaseData` table based on the page name and parameters | ||
− | local function setReleaseData( | + | local function setReleaseData( currentPageName, args ) |
-- Set the set page equal to the supplied set | -- Set the set page equal to the supplied set | ||
-- or defaul to to the one that can be inferred from the page name | -- or defaul to to the one that can be inferred from the page name | ||
Line 187: | Line 147: | ||
-- Query the set page to find more information | -- Query the set page to find more information | ||
local queriedData = querySetData() | local queriedData = querySetData() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
-- Update the `releaseData` object based on the results of the query | -- Update the `releaseData` object based on the results of the query | ||
Line 198: | Line 152: | ||
releaseData.name = queriedData.name | releaseData.name = queriedData.name | ||
releaseData.localName = args.name or queriedData.localName | releaseData.localName = args.name or queriedData.localName | ||
− | + | releaseData.releaseDate = args.releaseDate or queriedData.releaseDate | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 228: | Line 170: | ||
-- Update the `releaseData` object based on information from the page name | -- Update the `releaseData` object based on information from the page name | ||
-- and the supplied arguments. | -- and the supplied arguments. | ||
− | setReleaseData( | + | setReleaseData( currentTitle.text, args ) |
-- Get the header wikitext | -- Get the header wikitext |