<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ACore</id>
	<title>Module:Core - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ACore"/>
	<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Core&amp;action=history"/>
	<updated>2026-04-07T01:59:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:Core&amp;diff=11163&amp;oldid=prev</id>
		<title>Kg7qin: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Core&amp;diff=11163&amp;oldid=prev"/>
		<updated>2022-01-24T07:59:40Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 07:59, 24 January 2022&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key mediawiki:diff::1.12:old-11162:rev-11163 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kg7qin</name></author>
	</entry>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:Core&amp;diff=11162&amp;oldid=prev</id>
		<title>Mediawiki&gt;Jarekt: small tweak related to unsupported rtl languages</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:Core&amp;diff=11162&amp;oldid=prev"/>
		<updated>2021-03-08T04:29:20Z</updated>

		<summary type="html">&lt;p&gt;small tweak related to unsupported rtl languages&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[  &lt;br /&gt;
  __  __           _       _         ____               &lt;br /&gt;
 |  \/  | ___   __| |_   _| | ___ _ / ___|___  _ __ ___ &lt;br /&gt;
 | |\/| |/ _ \ / _` | | | | |/ _ (_) |   / _ \| '__/ _ \&lt;br /&gt;
 | |  | | (_) | (_| | |_| | |  __/_| |__| (_) | | |  __/&lt;br /&gt;
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)\____\___/|_|  \___|&lt;br /&gt;
                                                        &lt;br /&gt;
Core is a meta-module that consists of common and useful Lua functions that can &lt;br /&gt;
be used in many Lua scripts. It was writen as a core of several Lua &lt;br /&gt;
modules for creating file infobox templates on Commons. Many of the functions&lt;br /&gt;
are bare-bones versions of full functions found in other modules.&lt;br /&gt;
&lt;br /&gt;
Authors and maintainers:&lt;br /&gt;
* User:Jarekt  &lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local core = {}&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Based on frame structure create &amp;quot;args&amp;quot; table with all the input parameters:&lt;br /&gt;
 * table keys - equivalent to template parameters are converted to lower case &lt;br /&gt;
                so they will not be case-sensitive.&lt;br /&gt;
                Also underscored are treated the same way as speces. &lt;br /&gt;
 * table values - input values are trimmed (whitespaces removed from the beggining &lt;br /&gt;
                and the end) and empty string are converted to nils. &lt;br /&gt;
If &amp;quot;lang&amp;quot; is not provided than we substitute user's prefered language.&lt;br /&gt;
&lt;br /&gt;
This function collects inputs from both frame and frame's parent. See &lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#frame:getParent .&lt;br /&gt;
If both structures have the same field than value from &amp;quot;frame&amp;quot; takes priority.&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1) frame - frame objects see below for details&lt;br /&gt;
	https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#frame-object&lt;br /&gt;
&lt;br /&gt;
See also: Module:Arguments on enWiki - which is much larger single purpose module&lt;br /&gt;
]]&lt;br /&gt;
function core.getArgs(frame)&lt;br /&gt;
	local function normalize_input_args(input_args, output_args)&lt;br /&gt;
		for name, value in pairs( input_args ) do &lt;br /&gt;
			value = mw.text.trim(value) -- trim whitespaces from the beggining and the end of the string&lt;br /&gt;
			if value ~= '' then -- nuke empty strings&lt;br /&gt;
				if type(name)=='string' then &lt;br /&gt;
					name = string.gsub( string.lower(name), ' ', '_')&lt;br /&gt;
				end&lt;br /&gt;
				output_args[name] = value&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return output_args&lt;br /&gt;
	end&lt;br /&gt;
	local args = {}&lt;br /&gt;
	args = normalize_input_args(frame:getParent().args, args)&lt;br /&gt;
	args = normalize_input_args(frame.args, args)&lt;br /&gt;
	if (args.lang and mw.language.isSupportedLanguage(args.lang)) then &lt;br /&gt;
		args.lang = string.lower(args.lang)&lt;br /&gt;
	else&lt;br /&gt;
		args.lang = frame:callParserFunction(&amp;quot;int&amp;quot;,&amp;quot;lang&amp;quot;)  -- get user's chosen language&lt;br /&gt;
	end&lt;br /&gt;
	return args&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Simplified code equivalent to https://commons.wikimedia.org/wiki/Template:LangSwitch&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  text = langSwitch({en='text in english', pl='tekst po polsku'}, lang)&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
  1: args - table with translations by language&lt;br /&gt;
  2: lang - desired language (often user's native language)&lt;br /&gt;
  &lt;br /&gt;
Outputs:&lt;br /&gt;
  1: label - returned label&lt;br /&gt;
  2: lang  - language of the label (langSwitchWithLang only)&lt;br /&gt;
]]&lt;br /&gt;
function core.langSwitchWithLang(args, lang)&lt;br /&gt;
	local langList = mw.language.getFallbacksFor(lang)&lt;br /&gt;
	table.insert(langList,1,lang)&lt;br /&gt;
	for i,language in ipairs(langList) do&lt;br /&gt;
		if args[language] then&lt;br /&gt;
			return args[language], language&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function core.langSwitch(args, lang)&lt;br /&gt;
	local label, lang = core.langSwitchWithLang(args, lang)&lt;br /&gt;
	return label&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
display a language followed by a message. Like &amp;quot;English: Hello&amp;quot; with extensive HTML marking&lt;br /&gt;
Code equivalent to https://commons.wikimedia.org/wiki/Template:Description &lt;br /&gt;
Inputs:&lt;br /&gt;
  1) text_lang - language code for the above text, also used as a name of the CSS formating class&lt;br /&gt;
  2) text - description text to display&lt;br /&gt;
  3) args -  additional optional arguments. Numbers in perenthesis are parameter numbers in the original template.&lt;br /&gt;
	   * hover    - (3) hover aka mouseover aka tooltip text&lt;br /&gt;
	   * lang_tag - (4) standard code for lang tag in HTML (optional, default is same as text_lang)&lt;br /&gt;
	   * ext      - (5) extension text shown after the language name before colon (optional, default is empty)&lt;br /&gt;
       * inline - Optional, default is false. When set to true, forces the template to be displayed &lt;br /&gt;
            inline, so that it does not break the current paragraph (that makes possible to put several &lt;br /&gt;
	        descriptions side by side on a single line)	   &lt;br /&gt;
]]&lt;br /&gt;
function core.langWrapper(text_lang, text, args) &lt;br /&gt;
	local dir, space, colon, lang_name, hover&lt;br /&gt;
	local inline    = core.yesno(args.inline, false) and 'inline' or nil &lt;br /&gt;
	if 	mw.language.isKnownLanguageTag(text_lang) then -- supported language&lt;br /&gt;
		local langObj = mw.language.new( text_lang )&lt;br /&gt;
		dir       = langObj:getDir()          -- text direction&lt;br /&gt;
		space     = mw.message.new( &amp;quot;Word-separator&amp;quot; ):inLanguage(text_lang):plain() &lt;br /&gt;
		colon     = mw.message.new( &amp;quot;Colon&amp;quot; ):inLanguage(text_lang):plain() &lt;br /&gt;
		hover     = mw.language.fetchLanguageName( text_lang, args.user_lang or 'en')&lt;br /&gt;
		lang_name = mw.language.fetchLanguageName( text_lang, text_lang)&lt;br /&gt;
		lang_name = langObj:ucfirst(lang_name)&lt;br /&gt;
	else -- unsuported language&lt;br /&gt;
		local RTL_LUT = {['fa-af']=1, prd=1, ydd=1}&lt;br /&gt;
		dir   = (RTL_LUT[text_lang]==1 or text_lang:gsub('-arab', '')~=text_lang) and 'rtl' or 'ltr'&lt;br /&gt;
		space = ' '&lt;br /&gt;
		colon = ':'&lt;br /&gt;
		hover = args.hover&lt;br /&gt;
		lang_name = text_lang or 'Unknown'&lt;br /&gt;
	end&lt;br /&gt;
	lang_name = args.lang_name or lang_name-- user provided args.lang_name takes presedent&lt;br /&gt;
	lang_name = '&amp;lt;b&amp;gt;' .. lang_name .. (args.ext or '') .. colon .. '&amp;lt;/b&amp;gt;'&lt;br /&gt;
	&lt;br /&gt;
	-- create HTML&lt;br /&gt;
	local ltag = mw.html.create('span')  -- bold language name string&lt;br /&gt;
		:addClass('language')  -- class: &amp;quot;language&amp;quot; &lt;br /&gt;
		:addClass(text_lang)   -- class:  &amp;quot;en&amp;quot;, &amp;quot;de&amp;quot; etc.	&lt;br /&gt;
		:attr('title', hover)  -- add hover aka mouseover aka tooltip text&lt;br /&gt;
		:wikitext(lang_name)&lt;br /&gt;
	local dtag = mw.html.create('div')&lt;br /&gt;
		:addClass('description')      -- div.description is tracked by mw:Extension:CommonsMetadata&lt;br /&gt;
		:addClass('mw-content-'..dir) -- mw-content-rtl and mw-content-ltr are defined in mediawiki-code (https://gerrit.wikimedia.org/r/c/mediawiki/core/+/208332)&lt;br /&gt;
		:addClass(text_lang)          -- not sure where &amp;quot;en&amp;quot;, &amp;quot;de&amp;quot; etc. are defined&lt;br /&gt;
		:attr('dir', dir)&lt;br /&gt;
		:attr('lang', text_lang)&lt;br /&gt;
		:css('display', inline) &lt;br /&gt;
		:wikitext(tostring(ltag) .. space .. text)&lt;br /&gt;
	return tostring(dtag)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Function allowing for consistent treatment of boolean-like wikitext input.&lt;br /&gt;
Inputs:&lt;br /&gt;
  1) val - value to be evaluated, outputs as a function of values:&lt;br /&gt;
		true  : true  (boolean), 1 (number), or strings: &amp;quot;yes&amp;quot;, &amp;quot;y&amp;quot;, &amp;quot;true&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
		false : false (boolean), 0 (number), or strings: &amp;quot;no&amp;quot;, &amp;quot;n&amp;quot;, &amp;quot;false&amp;quot;, &amp;quot;0&amp;quot;&lt;br /&gt;
  2) default - value to return otherwise&lt;br /&gt;
See Also: It works similarly to Module:Yesno&lt;br /&gt;
]]&lt;br /&gt;
function core.yesno(val, default)&lt;br /&gt;
	if type(val) == 'boolean' then&lt;br /&gt;
		return val&lt;br /&gt;
	elseif type(val) == 'number' then&lt;br /&gt;
		val = tostring(val)&lt;br /&gt;
	end&lt;br /&gt;
	if type(val) == 'string' then&lt;br /&gt;
		local LUT = {&lt;br /&gt;
			yes=true , y=true , ['true'] =true , t=true , ['1']=true , on =true,&lt;br /&gt;
			no =false, n=false, ['false']=false, f=false, ['0']=false, off=false }&lt;br /&gt;
	    val = LUT[mw.ustring.lower(val)]  -- put in lower case&lt;br /&gt;
	    if (val~=nil) then&lt;br /&gt;
			return val&lt;br /&gt;
		end&lt;br /&gt;
    end&lt;br /&gt;
    return default&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Read Commons Data:SOMENAME.tab dataset and look for message identified by a &lt;br /&gt;
&amp;quot;key&amp;quot; in a language &amp;quot;lang&amp;quot;. See editAtWikidata for an example. It uses&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.ext.data&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 1) dataset - name of commons page in &amp;quot;data&amp;quot; namespace. for example &amp;quot;I18n/EditAt.tab&amp;quot; &lt;br /&gt;
	for c:Data:I18n/EditAt.tab&lt;br /&gt;
 2) key - which message to pull&lt;br /&gt;
 3) lang - desired language of the message&lt;br /&gt;
Output: message as a string&lt;br /&gt;
]]&lt;br /&gt;
function core.formatMessage(dataset, key, lang)&lt;br /&gt;
	for _, row in pairs(mw.ext.data.get(dataset, lang).data) do&lt;br /&gt;
		local id, msg = unpack(row)&lt;br /&gt;
		if id == key then&lt;br /&gt;
			return mw.message.newRawMessage(msg):plain()&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	error('Invalid message key &amp;quot;' .. key .. '&amp;quot;')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Assembles the &amp;quot;Edit at Wikidata&amp;quot; pen icon with a link to Wikidata page or specific &lt;br /&gt;
property and returns it as wikitext string.&lt;br /&gt;
Inputs:&lt;br /&gt;
  1) entityID - wikidata entity object for a given page (output of wikibase.getEntity( id ))&lt;br /&gt;
  2) propertyID - string like 'P31' so the link will point to that specific property. Use &amp;quot;&amp;quot; &lt;br /&gt;
     to link to the whole page. &lt;br /&gt;
  3) lang - language of the &amp;quot;Edit at Wikidata&amp;quot;  message&lt;br /&gt;
Dependencies: Data:I18n/EditAt.tab&lt;br /&gt;
See Also: en:Module:EditAtWikidata&lt;br /&gt;
]]&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
function core.editAtWikidata(entityID, propertyID, lang)&lt;br /&gt;
	local msg  = core.formatMessage('I18n/EditAt.tab', 'EditAtWikidata', lang)&lt;br /&gt;
	local link = 'https://www.wikidata.org/wiki/' .. entityID .. (propertyID == &amp;quot;&amp;quot; and &amp;quot;&amp;quot; or (&amp;quot;#&amp;quot; .. propertyID))&lt;br /&gt;
	return &amp;quot;&amp;amp;nbsp;[[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=&amp;quot;..msg..&amp;quot;|link=&amp;quot;..link..&amp;quot;|&amp;quot;..msg..&amp;quot;]]&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Assembles the &amp;quot;Edit at SDC&amp;quot; pen icon with a link to a property in SDC part of the current file &lt;br /&gt;
page, and returns it as wikitext string.&lt;br /&gt;
Inputs:&lt;br /&gt;
  2) propertyID - string like 'P31' so the link will point to that specific property. Use 'ooui-php-4' &lt;br /&gt;
     to link to the label section. &lt;br /&gt;
  3) lang - language of the &amp;quot;Edit at Wikidata&amp;quot;  message&lt;br /&gt;
Dependencies: Data:I18n/EditAt.tab&lt;br /&gt;
See Also: en:Module:EditAtWikidata&lt;br /&gt;
]]&lt;br /&gt;
function core.editAtSDC(propertyID, lang)&lt;br /&gt;
	local msg  = core.formatMessage('I18n/EditAt.tab', 'EditAtSDC', lang)&lt;br /&gt;
	local link =  mw.title.getCurrentTitle():fullUrl() .. (propertyID == &amp;quot;&amp;quot; and &amp;quot;&amp;quot; or (&amp;quot;#&amp;quot; .. propertyID))&lt;br /&gt;
	return &amp;quot;&amp;amp;nbsp;[[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=&amp;quot;..msg..&amp;quot;|link=&amp;quot;..link..&amp;quot;|&amp;quot;..msg..&amp;quot;]]&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
This function returns a label translated to desired language, created based on wikidata&lt;br /&gt;
Code equivalent to require(&amp;quot;Module:Wikidata label&amp;quot;)._getLabel&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata's item's q-id or entity class&lt;br /&gt;
	2: userLang - desired language of the label&lt;br /&gt;
]]&lt;br /&gt;
function core.getLabel(item, userLang) &lt;br /&gt;
	local label, link&lt;br /&gt;
	-- build language fallback list&lt;br /&gt;
	local langList = mw.language.getFallbacksFor(userLang)&lt;br /&gt;
	table.insert(langList, 1, userLang) &lt;br /&gt;
	-- get label&lt;br /&gt;
	for _, lang in ipairs(langList) do  -- loop over language fallback list looking for label in the specific language&lt;br /&gt;
		label = mw.wikibase.getLabelByLang(item, lang)&lt;br /&gt;
		if label then break end                    -- label found and we are done&lt;br /&gt;
	end	&lt;br /&gt;
	label = label or item -- fallback value&lt;br /&gt;
	-- get link&lt;br /&gt;
	for _, lang in ipairs(langList) do  -- loop over language fallback list looking for label in the specific language&lt;br /&gt;
		link =  mw.wikibase.getSitelink(item, lang .. 'wiki')&lt;br /&gt;
		if link then&lt;br /&gt;
			link = mw.ustring.format('w:%s:%s', lang, link)&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	link = link or 'd:'..item -- fallback value&lt;br /&gt;
	-- look for description&lt;br /&gt;
	local desc = mw.wikibase.getDescription(item)&lt;br /&gt;
	if desc then  -- add description if we have one&lt;br /&gt;
		desc  = mw.text.nowiki(desc) -- add description as hover text&lt;br /&gt;
		label = '&amp;lt;span title=&amp;quot;' .. desc .. '&amp;quot;&amp;gt;' .. label .. '&amp;lt;/span&amp;gt;'&lt;br /&gt;
	end&lt;br /&gt;
   return '[['..link..'|'..label..']]'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
--[[&lt;br /&gt;
Core component of many &amp;quot;get property value&amp;quot; functions&lt;br /&gt;
Example: (core.parse_statements(entity:getBestStatements( prop ), nil) or {nil})[1] would &lt;br /&gt;
return the first best statement&lt;br /&gt;
Inputs:&lt;br /&gt;
 1: statements - can be provided by:&lt;br /&gt;
   * entity:getBestStatements( prop )&lt;br /&gt;
   * entity:getAllStatements( prop )&lt;br /&gt;
   * mw.wikibase.getBestStatements( item, prop )&lt;br /&gt;
   * mw.wikibase.getAllStatements( item, prop )&lt;br /&gt;
 2: lang - language code (like &amp;quot;en&amp;quot;), if provided than item IDs will be &lt;br /&gt;
     changed to a label&lt;br /&gt;
Output:&lt;br /&gt;
 * table of strings or nil&lt;br /&gt;
]]&lt;br /&gt;
function core.parseStatements(statements, lang)&lt;br /&gt;
	local output = {}&lt;br /&gt;
	for _, statement in ipairs(statements) do&lt;br /&gt;
		if (statement.mainsnak.snaktype == &amp;quot;value&amp;quot;) and (statement.rank ~= 'deprecated')  then&lt;br /&gt;
			local val = statement.mainsnak.datavalue.value&lt;br /&gt;
			if val.id then &lt;br /&gt;
				val = val.id&lt;br /&gt;
				if lang ~= nil then&lt;br /&gt;
					val = core.getLabel(val, lang)&lt;br /&gt;
				end&lt;br /&gt;
			elseif val.text then&lt;br /&gt;
				val = val.text&lt;br /&gt;
			elseif val.amount then&lt;br /&gt;
				val = tonumber(val.amount)&lt;br /&gt;
			end&lt;br /&gt;
			table.insert(output, val)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if #output==0 then return nil end&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return core&lt;/div&gt;</summary>
		<author><name>Mediawiki&gt;Jarekt</name></author>
	</entry>
</feed>