Editing Module:Set page header

Jump to: navigation, search

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
isParentSet = nil,
 
 
}
 
}
  
 
local function getRegion( pagename )
 
local function getRegion( pagename )
-- Get content after the first hyphen after the last `(` in the page name
+
local index = pagename:match( 'CG%-(%a+)%-?' )
-- up until the next `-` or `)`
 
-- More specifically match
 
-- `(`
 
-- Any amount of non-`(` non-`-`
 
-- `-`
 
-- Any amount of non-`(` non-`-` (Capture the text in this group)
 
-- An optional `-`
 
-- An optional amout of non-`(` non-`-`
 
-- A `)`
 
-- the end of the string
 
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 )
-- Get content after the second hyphen after the last `(` in the page name.
+
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 ) )
 
-- If there is a release date, show it in the header
 
if ( releaseData.releaseDate ) then
 
header:tag( 'div' ):wikitext( '(Release date: ' .. releaseData.releaseDate .. ')' )
 
end
 
  
 
return tostring( header )
 
return tostring( header )
Line 113: Line 95:
  
 
local function makeCategories( ns )
 
local function makeCategories( ns )
local categories = {
+
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 ),
 
}
 
}
 
if ( releaseData.edition ) then
 
table.insert( categories, ( '[[Category:%s %s]]' ):format( releaseData.edition.full, ns ) )
 
end
 
 
if ( ns == 'Set Card Lists' and releaseData.isParentSet ) then
 
table.insert( categories, '[[Category:Set Card Lists for parent sets]]' )
 
end
 
 
-- Set lists with no release dates
 
-- Excludes lists for parent sets, whose children each have individual release dates
 
if ( ns == 'Set Card Lists' and not releaseData.releaseDate and not releaseData.isParentSet ) then
 
table.insert( categories, '[[Category:Set Card Lists with no release date]]' )
 
end
 
 
return table.concat(categories)
 
 
end
 
end
  
Line 138: Line 105:
 
['Set page']    = releaseData.set,
 
['Set page']    = releaseData.set,
 
['Local name']  = releaseData.localName,
 
['Local name']  = releaseData.localName,
['Release']      = releaseData.medium and releaseData.medium.full,
 
 
['Language']    = releaseData.language.full,
 
['Language']    = releaseData.language.full,
['Locality']     = releaseData.region and releaseData.region.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()
local results = mw.smw.ask{
+
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',
-- Bit sloppy, but we need to fallback to this if "Worldwide English release date" is empty
 
'?English release date = englishReleaseDate',
 
'?-Parent set = isParentSet',
 
 
mainlabel = '-'
 
mainlabel = '-'
 
}
 
}
 
-- Reurn the first result, if there is one
 
return results and results[ 1 ]
 
 
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( ns, currentPageName, args )
+
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()
 
-- Exit early if no results were found
 
if ( not queriedData ) then
 
-- todo: Tracking category
 
return
 
end
 
  
 
-- 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.isParentSet = queriedData.isParentSet and true or false
+
releaseData.releaseDate = args.releaseDate or queriedData.releaseDate
 
 
-- For now, only do the release date for list pages
 
-- Don't add it to parent set lists e.g. the overall "Shonen Jump promotional cards" list
 
-- which have multiple releases, each with their own set list.
 
if ( ns == 'Set Card Lists' and not queriedData.isParentSet ) then
 
releaseData.releaseDate = args.releaseDate or queriedData.releaseDate
 
 
 
-- If 'Worldwide English' and the `releaseDate` is empty, check the `englishReleaseDate`
 
if ( not releaseData.releaseDate and releaseData.region.full == 'Worldwide English' ) then
 
releaseData.releaseDate = queriedData.englishReleaseDate
 
end
 
end
 
 
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( ns, currentTitle.text, args )
+
setReleaseData( currentTitle.text, args )
  
 
-- Get the header wikitext
 
-- Get the header wikitext

Please note that all contributions to Yugipedia are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International License (see Yugipedia:Licensing for more details). If you do not want your writing to be edited mercilessly and redistributed at will, 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. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)
Preview page with this template
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template