π Image
Module documentation[view] [edit] [history] [purge]
Module documentation[view] [edit] [history] [purge]
| π Image | This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| π Page template-protected | This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| π Image | This module depends on the following other modules: |
| π CSS | This module uses TemplateStyles: |
Implements {{Spoken Wikipedia}}. See tests at Template:Spoken Wikipedia/testcases.
Usage
{{#invoke:Spoken Wikipedia|main}}
Parameters
Mandatory parameters
|1=,|2=,|3=...- Filenames of the audio files.
|date=- Date of the version of the page, which was recorded.
Optional parameters
|page=- Overrides the "this article" text with a wikilinkβfor placement of the template for an article on another page.
|nocat=true- Suppress categorization.
See also
localgetArgs=require('Module:Arguments').getArgs localyesno=require('Module:Yesno') localDate=require('Module:Date')._Date locallang=mw.language.new('en') localcfg=mw.loadData('Module:Spoken Wikipedia/configuration') p={} localfunctionwikiError(message) localret=mw.html.create('div') :addClass(cfg.i18n.class.err) :wikitext(message) :done() returntostring(ret) end localfunctioncategory(c,nocat) ifnocatthen return'' else returnc end end localfunctionformatPageText(page) ifpagethen return'<span class="fn">[['..page..']]</span>' end ifmw.title.getCurrentTitle().namespace==0then returncfg.i18n.this_article else returncfg.i18n.this_page end end localfunctionformatFileLength(filenames) locallength=0 for_,filenameinipairs(filenames)do localfileTitle=mw.title.new(filename,'Media') iffileTitleandfileTitle.fileandfileTitle.file.existsthen length=length+fileTitle.file.length end end -- Add 30 to offset the rounding down localintervals=lang:getDurationIntervals(length+30,{'hours','minutes'}) localret=string.format( '<span class="min">%s</span> %s', intervals.minutesor0, intervals.minutes==1andcfg.i18n.minuteorcfg.i18n.minutes ) ifintervals.hoursthen ret=string.format( '<span class="h">%s</span> %s and %s', intervals.hours, intervals.hours==1andcfg.i18n.hourorcfg.i18n.hours, ret ) end return'<span class="duration">'..ret..'</span>' end localfunctionformatHeader(filenames,page) locallistento=mw.html.create('span') :addClass(cfg.i18n.class.listento) :wikitext(string.format( cfg.i18n.listento, formatPageText(page) )) :done() localfile_length if#filenames>1then file_length=string.format( cfg.i18n.n_files_length, tostring(#filenames), formatFileLength(filenames) ) else file_length=string.format( cfg.i18n.one_file_length, formatFileLength(filenames) ) end returnmw.html.create('div') :addClass(cfg.i18n.class.header) :node(listento) :wikitext(file_length) :done() end localfunctionformatIcon() returnmw.html.create('div') :addClass(cfg.i18n.class.icon) :wikitext(cfg.i18n.icon) :done() end localfunctionformatFiles(filenames,nocat) if#filenames==0then returnwikiError(cfg.i18n.err.no_filename).. category(cfg.i18n.cat.no_filename,nocat) end -- TODO: the else branch really wants to be a mw.html <ol> object rather than wikitext -- version of the same, so that we can style the numbers nicer localfiles={} if#filenames==1then table.insert(files,string.format(cfg.i18n.one_file,filenames[1])) else fori,filenameinipairs(filenames)do table.insert(files,string.format(cfg.i18n.n_files,filename,i)) end end returnmw.html.create('div') :addClass(cfg.i18n.class.files) :wikitext(table.concat(files)) :done() :newline() end localfunctionformatDateText(frame,dateArg,nocat) locald=dateArgandDate(dateArg)ornil returndandframe:expandTemplate{ title='Start date',args={ d.year, d.month, d.day, df='y' } }or(wikiError(cfg.i18n.err.no_date)..category(cfg.i18n.cat.no_date,nocat)) end localfunctionformatDisclaimer(frame,filenames,page,dateArg,nocat) localthisFileText='' localdisclaimer if#filenames==1then thisFileText=filenames[1] disclaimer=cfg.i18n.one_file_disclaimer else disclaimer=cfg.i18n.n_files_disclaimer end returnmw.html.create('div') :addClass(cfg.i18n.class.disclaimer) :wikitext(string.format( disclaimer, thisFileText, formatPageText(page), formatDateText(frame,dateArg,nocat) )) :done() end localfunctionformatFooter() returnmw.html.create('div') :addClass(cfg.i18n.class.footer) :wikitext(cfg.i18n.footer) :done() end localfunctionformatTopicon(frame,filenames) localwikilink if#filenames>0then wikilink='File:'..filenames[1] else wikilink=cfg.i18n.topicon_multiwikilink end returnframe:expandTemplate{ title="Top icon", args={ imagename='Gnome-mime-sound-openclipart.svg', wikilink=wikilink, text='Listen to this article', id='spoken-icon' } } end localfunctionextractFilenames(args) localfilenames={} forkey,rawValueinipairs(args)do localvalue=mw.text.trim(rawValue) iftype(key)=="number"andvalue~=''then table.insert(filenames,value) end end returnfilenames end localfunctionsidebox(nodes) root=mw.html.create('div') :addClass(cfg.i18n.class.box) for_,nodeinipairs(nodes)do root:node(node) end returnroot end functionmain(frame) localargs=getArgs(frame) -- Mandatory parameters localfilenames=extractFilenames(args) localdateArg=args['date'] -- Optional parameters localpage=args['page'] localnocat=yesno(args['nocat'],false)orfalse localroot=sidebox({ formatHeader(filenames,page), formatFiles(filenames,nocat), formatIcon(), formatDisclaimer(frame,filenames,page,dateArg,nocat), formatFooter() }) ifmw.title.getCurrentTitle().namespace==0then root:wikitext(formatTopicon(frame,filenames)) root:wikitext(category(cfg.i18n.cat.articles,nocat)) end returnframe:extensionTag{ name='templatestyles',args={src=cfg.templatestyles} }..tostring(root) end p.main=main returnp
