https://amanitaresearch.com/index.php?title=Module:IPAc-en&feed=atom&action=historyModule:IPAc-en - Revision history2024-03-28T11:30:25ZRevision history for this page on the wikiMediaWiki 1.33.0https://amanitaresearch.com/index.php?title=Module:IPAc-en&diff=5657&oldid=prevDesign-R: 1 revision imported: GABA2019-11-03T21:34:22Z<p>1 revision imported: GABA</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">Revision as of 21:34, 3 November 2019</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Design-Rhttps://amanitaresearch.com/index.php?title=Module:IPAc-en&diff=5656&oldid=prevwikipedia>Nardog: show tooltips as reference tooltips when MediaWiki:Gadget-ReferenceTooltips.js and "Show tooltips over text with a dotted underline" in its settings are enabled2019-10-31T16:02:54Z<p>show tooltips as reference tooltips when <a href="/index.php?title=MediaWiki:Gadget-ReferenceTooltips.js&action=edit&redlink=1" class="new" title="MediaWiki:Gadget-ReferenceTooltips.js (page does not exist)">MediaWiki:Gadget-ReferenceTooltips.js</a> and "Show tooltips over text with a dotted underline" in its settings are enabled</p>
<p><b>New page</b></p><div>-- This module implements [[Template:IPAc-en]].<br />
<br />
local data = mw.loadData('Module:IPAc-en/data')<br />
local p = {}<br />
<br />
-- Global container for tracking categories<br />
local categoryHandler = require('Module:Category handler').main<br />
local categories = {}<br />
<br />
-- Trims whitespace from a string<br />
local function trim(s)<br />
return s:match('^%s*(.-)%s*$')<br />
end<br />
<br />
-- This implements [[Template:Nowrap]].<br />
local function makeNowrapSpan(s)<br />
local span = mw.html.create('span')<br />
:addClass('rt-commentedText') -- Works with [[MediaWiki:Gadget-ReferenceTooltips.js]]<br />
:addClass('nowrap')<br />
:wikitext(s)<br />
return tostring(span)<br />
end<br />
<br />
local function makePronunciationText(id)<br />
id = id and string.lower(trim(id))<br />
if id and id ~= '' and data.pronunciation[id] then<br />
return data.pronunciation[id].text<br />
end<br />
end<br />
<br />
-- This adds a tooltip icon to a label. It implements [[Template:H:title]].<br />
local function makeTooltip(label, tooltip)<br />
local span = mw.html.create('span')<br />
:attr('title', tooltip)<br />
:wikitext(label)<br />
return tostring(span)<br />
end<br />
<br />
local function formatPhonemeGroup(phonemes)<br />
if #phonemes > 0 then<br />
local span = mw.html.create('span')<br />
:css('border-bottom', '1px dotted')<br />
:wikitext(table.concat(phonemes))<br />
return tostring(span)<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
local function renderCategories()<br />
local ret = ''<br />
ret = categoryHandler{<br />
[1] = 'yes', -- Add categories in these namespaces<br />
main = 1,<br />
wikipedia = 1,<br />
file = 1,<br />
template = 1,<br />
help = 1,<br />
category = 1,<br />
portal = 1,<br />
book = 1,<br />
draft = 1,<br />
module = 1,<br />
}<br />
<br />
if ret == 'yes' then<br />
ret = {}<br />
for cat in pairs(categories) do<br />
table.insert(ret, string.format('[[Category:%s]]', cat))<br />
end<br />
table.sort(ret)<br />
ret = table.concat(ret)<br />
else<br />
ret = ''<br />
end<br />
return ret<br />
end<br />
<br />
function p._main(args)<br />
local ret = {}<br />
local i = 0 -- Keeps track of numbered args<br />
<br />
-- Pronunciation<br />
do<br />
local pron = {}<br />
while true do<br />
i = i + 1<br />
local pronItem = makePronunciationText(args[i])<br />
if pronItem then<br />
pron[#pron + 1] = pronItem<br />
pron[#pron + 1] = ' '<br />
else<br />
break<br />
end<br />
end<br />
if #pron > 0 then<br />
ret[#ret + 1] = string.format(<br />
'<small>%s</small>',<br />
table.concat(pron)<br />
)<br />
end<br />
end<br />
<br />
-- Phonemes<br />
do<br />
-- Loop through the numbered args, separating them into phoneme groups<br />
-- and separator strings (both called "words" for convenience). We only<br />
-- underline the phoneme groups, not the separators.<br />
local words = {}<br />
words[#words + 1] = '/' -- Opening slash<br />
i = i - 1 -- Set up i again as it was changed in the pronunciation loop<br />
local id<br />
repeat<br />
local phonemes = {}<br />
local isWordEnd = false<br />
while not isWordEnd do<br />
i = i + 1<br />
id = args[i]<br />
id = id and trim(id)<br />
if not id then<br />
isWordEnd = true<br />
words[#words + 1] = formatPhonemeGroup(phonemes)<br />
elseif id ~= '' then<br />
local t = data.phonemes[id]<br />
if not t then<br />
-- We were passed an invalid id.<br />
isWordEnd = true<br />
categories["Ill-formatted IPAc-en transclusions"] = true<br />
words[#words + 1] = formatPhonemeGroup(phonemes)<br />
words[#words + 1] = makeTooltip(<br />
string.format(<br />
"<strong class=\"error\">[invalid input: '%s']</strong>",<br />
id<br />
),<br />
'Unrecognized symbol'<br />
)<br />
elseif not t.label then<br />
-- The data module contains bad data, so throw an error.<br />
error(string.format(<br />
"no label was found for id '%s'",<br />
tostring(id)<br />
))<br />
elseif t.tooltip then<br />
-- We are dealing with a regular phoneme.<br />
phonemes[#phonemes + 1] = makeTooltip(<br />
t.label,<br />
t.tooltip<br />
)<br />
else<br />
-- We are dealing with a separator.<br />
isWordEnd = true<br />
words[#words + 1] = formatPhonemeGroup(phonemes)<br />
words[#words + 1] = t.label <br />
end<br />
end<br />
end<br />
until not id<br />
words[#words + 1] = '/' -- Closing slash<br />
<br />
-- Wrap the words in a link to IPA help.<br />
local span = mw.html.create('span')<br />
-- Suppress Navigation popups and Page Previews (aka Hovercards)<br />
:addClass('IPA nopopups noexcerpt')<br />
:wikitext(string.format(<br />
'[[Help:IPA/English|%s]]',<br />
table.concat(words)<br />
))<br />
<br />
ret[#ret + 1] = tostring(span)<br />
end<br />
<br />
-- Audio link<br />
do<br />
local file = args.audio and trim(args.audio)<br />
if file and file ~= '' then<br />
if args[1] and string.lower(trim(args[1])) == 'uk' then<br />
categories["Pages including recorded pronunciations (UK English)"] = true<br />
elseif args[1] and string.lower(trim(args[1])) == 'us' then<br />
categories["Pages including recorded pronunciations (US English)"] = true<br />
else<br />
categories["Pages including recorded pronunciations (English)"] = true<br />
end<br />
<br />
ret[#ret + 1] = mw.getCurrentFrame():expandTemplate{<br />
title = 'Template:IPA audio link', args = { file } }<br />
end<br />
end<br />
<br />
-- Nowrap and categories<br />
ret = makeNowrapSpan(table.concat(ret)) .. renderCategories()<br />
<br />
-- Reset the categories table in case we are run again.<br />
categories = {}<br />
<br />
return ret<br />
end<br />
<br />
function p.main(frame)<br />
return p._main(frame:getParent().args)<br />
end<br />
<br />
return p</div>wikipedia>Nardog