Module:Track listing: Difference between revisions
Content deleted Content added
Johnrdorazio (talk | contribs) m 1 revision imported |
rm non-working code related to the collapsed parameter; deprecated parameter checking can be implemented in the template easily |
||
Line 1:
local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType
local cfg = mw.loadData('Module:Track listing/configuration')
--------------------------------------------------------------------------------
Line 64 ⟶ 59:
if hours and hours:sub(1, 1) == '0' then
-- Disallow times like "0:12:34"
self:addWarning
string.format(cfg.leading_0_in_hours, mw.text.nowiki(length)),
cfg.input_error_category
)
return nil
end
Line 77 ⟶ 72:
-- Special case to disallow lengths like "01:23". This check has to
-- be here so that lengths like "1:01:23" are still allowed.
self:addWarning
string.format(cfg.leading_0_in_minutes, mw.text.nowiki(length)),
cfg.input_error_category
)
return nil
end
Line 87 ⟶ 82:
-- Add a warning and return if we did not find a match.
if not seconds then
self:addWarning
string.format(cfg.not_a_time, mw.text.nowiki(length)),
cfg.input_error_category
)
return nil
end
Line 96 ⟶ 91:
-- Check that the minutes are less than 60 if we have an hours field.
if hours and tonumber(minutes) >= 60 then
self:addWarning
string.format(cfg.more_than_60_minutes, mw.text.nowiki(length)),
cfg.input_error_category
)
return nil
end
Line 105 ⟶ 100:
-- Check that the seconds are less than 60
if tonumber(seconds) >= 60 then
self:addWarning
string.format(cfg.more_than_60_seconds, mw.text.nowiki(length)),
cfg.input_error_category
)
end
Line 122 ⟶ 117:
addMixin(Track, Validation)
Track.fields =
Track.cellMethods = {
Line 173 ⟶ 159:
function Track.makeSimpleCell(wikitext)
return mw.html.create('td')
:wikitext(wikitext or cfg.blank_cell)
end
function Track:makeNumberCell()
return mw.html.create('
:attr('id', string.format(cfg.track_id, self.number))
:
:wikitext(string.format(cfg.number_terminated, self.number))
end
function Track:makeTitleCell()
local titleCell = mw.html.create('td')
titleCell:wikitext(
self.title and string.format(cfg.track_title, self.title) or cfg.untitled
)
if self.note then
titleCell:wikitext(string.format(cfg.note, self.note))
end
return titleCell
Line 217 ⟶ 198:
function Track:makeLengthCell()
return mw.html.create('td')
:
:wikitext(self.length or cfg.blank_cell)
end
function Track:exportRow(
local row = mw.html.create('tr')
for i, column in ipairs(columns) do
local method = Track.cellMethods[column]
Line 244 ⟶ 221:
TrackListing.__index = TrackListing
addMixin(TrackListing, Validation)
TrackListing.fields = cfg.track_listing_field_names
TrackListing.
function TrackListing.new(data)
Line 273 ⟶ 231:
for deprecatedField in pairs(TrackListing.deprecatedFields) do
if data[deprecatedField] then
self:addCategory(
break
end
Line 337 ⟶ 295:
function TrackListing:makeIntro()
if self.all_writing then
return string.format(cfg.tracks_written, self.all_writing)
elseif self.all_lyrics and self.all_music then
return
cfg.lyrics_written_music_composed,
self.all_lyrics,
self.all_music
):plain()
elseif self.all_lyrics then
return string.format(cfg.lyrics_written, self.all_lyrics)
elseif self.all_music then
return string.format(cfg.music_composed, self.all_music)
else
return
end
end
Line 387 ⟶ 336:
function TrackListing:renderWarnings()
if not
return ''
end
Line 394 ⟶ 343:
local function addWarning(msg)
table.insert(ret, string.format(cfg.track_listing_error, msg))
end
Line 414 ⟶ 360:
function TrackListing:__tostring()
-- Root of the output
local root = mw.html.create('div')
:addClass('track-listing')
local intro = self:makeIntro()
if intro then
root:tag('p')
:wikitext(intro)
:done()
end
-- Start of track listing table
local tableRoot = mw.html.create('table')
tableRoot
:addClass('tracklist')
-- Header row
if self.headline then
tableRoot:tag('caption')
:wikitext(self.headline or cfg.track_listing)
end
-- Headers
local headerRow = tableRoot:tag('tr')
---- Track number
headerRow
:tag('th')
:addClass('tracklist-number-header')
:attr('scope', 'col')
:tag('abbr')
:attr('title', cfg.number)
:wikitext(cfg.number_abbr)
-- Find columns to output
local columns = {'number', 'title'}
Line 430 ⟶ 410:
end
columns[#columns + 1] = 'length'
-- Find
local nColumns = #columns
local nOptionalColumns = nColumns - 3
local titleColumnWidth = 100
if nColumns >= 5 then
titleColumnWidth = 40
elseif nColumns >= 4 then
titleColumnWidth = 60
end
local optionalColumnWidth = ((100 - titleColumnWidth) / nOptionalColumns) .. '%'
titleColumnWidth = titleColumnWidth .. '%'
---- Title column
headerRow:tag('th')
:attr('scope', 'col')
:css('width', self.title_width or titleColumnWidth)
:wikitext(cfg.title)
---- Optional headers: writer, lyrics, music, and extra
Line 505 ⟶ 435:
if self.optionalColumns[field] then
headerRow:tag('th')
:attr('scope', 'col')
:css('width', width or optionalColumnWidth)
:wikitext(headerText)
end
end
addOptionalHeader('writer',
addOptionalHeader('lyrics',
addOptionalHeader('music',
addOptionalHeader(
'extra',
self.extra_column or
self.extra_width
)
Line 524 ⟶ 451:
---- Track length
headerRow:tag('th')
:addClass('
:attr('scope', 'col')
:wikitext(cfg.length)
-- Tracks
for i, track in ipairs(self.tracks) do
tableRoot:node(track:exportRow(
end
Line 544 ⟶ 464:
tableRoot
:tag('tr')
:
:tag('th')
:attr('colspan', nColumns - 1)
:
:tag('span')
:
:done()
:done()
:tag('td')
:
end
root:node(tableRoot)
-- Warnings and tracking categories
root:wikitext(self:renderWarnings())
root:wikitext(self:renderTrackingCategories())
return
name = 'templatestyles', args = { src = 'Module:Track listing/styles.css' }
} .. tostring(root)
end
|