<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="rue">
	<id>https://wiki.kocky.cc/w/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3ACommon%2FSMW</id>
	<title>Модуль:Common/SMW - Історія едітовань</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kocky.cc/w/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3ACommon%2FSMW"/>
	<link rel="alternate" type="text/html" href="https://wiki.kocky.cc/w/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Common/SMW&amp;action=history"/>
	<updated>2026-04-04T11:01:05Z</updated>
	<subtitle>Історія едітовань той сторінкы на вікі</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://wiki.kocky.cc/w/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Common/SMW&amp;diff=120&amp;oldid=prev</id>
		<title>Бетярь: 1 ревізія: Module:Common from StarCitizenTools</title>
		<link rel="alternate" type="text/html" href="https://wiki.kocky.cc/w/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Common/SMW&amp;diff=120&amp;oldid=prev"/>
		<updated>2023-10-18T00:53:18Z</updated>

		<summary type="html">&lt;p&gt;1 ревізія: Module:Common from StarCitizenTools&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&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;rue&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Старша верзія&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Ревізія 02:53, 18 октовбра 2023&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key wiki:diff::1.12:old-119:rev-120 --&gt;
&lt;/table&gt;</summary>
		<author><name>Бетярь</name></author>
	</entry>
	<entry>
		<id>https://wiki.kocky.cc/w/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Common/SMW&amp;diff=119&amp;oldid=prev</id>
		<title>starcitizen&gt;Alistair3149 в 07:14, 26 юлія 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.kocky.cc/w/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Common/SMW&amp;diff=119&amp;oldid=prev"/>
		<updated>2023-07-26T07:14:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Нова сторінка&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local commonSMW = {}&lt;br /&gt;
&lt;br /&gt;
local common = require( &amp;#039;Module:Common&amp;#039; )&lt;br /&gt;
local libraryUtil = require( &amp;#039;libraryUtil&amp;#039; )&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeMulti = libraryUtil.checkTypeMulti&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Adds SMW properties to a table either from the API or Frame arguments&lt;br /&gt;
---&lt;br /&gt;
--- @param apiData table Data from the Wiki API&lt;br /&gt;
--- @param frameArgs table Frame args processed by Module:Arguments&lt;br /&gt;
--- @param smwSetObject table The SMW Object that gets passed to mw.smw.set&lt;br /&gt;
--- @param translateFn function The function used to translate argument names&lt;br /&gt;
--- @param moduleConfig table Table from config.json&lt;br /&gt;
--- @param moduleData table Table from data.json&lt;br /&gt;
--- @param moduleName string The module name used to retrieve fallback attribute names&lt;br /&gt;
--- @return void&lt;br /&gt;
function commonSMW.addSmwProperties( apiData, frameArgs, smwSetObject, translateFn, moduleConfig, moduleData, moduleName )&lt;br /&gt;
	checkTypeMulti( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 1, apiData, { &amp;#039;table&amp;#039;, &amp;#039;nil&amp;#039; } )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 2, frameArgs, &amp;#039;table&amp;#039; )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 3, smwSetObject, &amp;#039;table&amp;#039; )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 4, translateFn, &amp;#039;function&amp;#039; )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 5, moduleConfig, &amp;#039;table&amp;#039; )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 6, moduleData, &amp;#039;table&amp;#039; )&lt;br /&gt;
    checkType( &amp;#039;Module:Common/SMW.addSmwProperties&amp;#039;, 7, moduleName, &amp;#039;string&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
    local TNT = require( &amp;#039;Module:Translate&amp;#039; ):new()&lt;br /&gt;
    local lang&lt;br /&gt;
    if moduleConfig.module_lang then&lt;br /&gt;
        lang = mw.getLanguage( moduleConfig.module_lang )&lt;br /&gt;
    else&lt;br /&gt;
        lang = mw.getContentLanguage()&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
	--- Retrieve value(s) from the frame&lt;br /&gt;
	---&lt;br /&gt;
	--- @param datum table An entry from data.smw_data&lt;br /&gt;
	--- @param argKey string The key to use as an accessor to frameArgs&lt;br /&gt;
	--- @return string|number|table|nil&lt;br /&gt;
	local function getFromArgs( datum, argKey )&lt;br /&gt;
		local value&lt;br /&gt;
		-- Numbered parameters, e.g. URL1, URL2, URL3, etc.&lt;br /&gt;
		if datum.type == &amp;#039;range&amp;#039; and type( datum.max ) == &amp;#039;number&amp;#039; then&lt;br /&gt;
			value = {}&lt;br /&gt;
&lt;br /&gt;
			for i = 1, datum.max do&lt;br /&gt;
				local argValue = frameArgs[ argKey .. i ]&lt;br /&gt;
				if argValue then table.insert( value, argValue ) end&lt;br /&gt;
			end&lt;br /&gt;
		-- A &amp;quot;simple&amp;quot; arg&lt;br /&gt;
		else&lt;br /&gt;
			value = frameArgs[ argKey ]&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		return value&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Iterate through the list of SMW attributes that shall be filled&lt;br /&gt;
	for _, datum in ipairs( moduleData.smw_data ) do&lt;br /&gt;
		-- Retrieve the SMW key and from where the data should be pulled&lt;br /&gt;
		local smwKey, from&lt;br /&gt;
		for key, get_from in pairs( datum ) do&lt;br /&gt;
			if string.sub( key, 1, 3 ) == &amp;#039;SMW&amp;#039; then&lt;br /&gt;
				smwKey = key&lt;br /&gt;
				from = get_from or {}&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if type( from ) ~= &amp;#039;table&amp;#039; then&lt;br /&gt;
			from = { from }&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Iterate the list of data sources in order, later sources override previous ones&lt;br /&gt;
		-- I.e. if the list is Frame Args, API; The api will override possible values set from the frame&lt;br /&gt;
		for _, key in ipairs( from ) do&lt;br /&gt;
			local parts = mw.text.split( key, &amp;#039;_&amp;#039;, true )&lt;br /&gt;
			local value&lt;br /&gt;
&lt;br /&gt;
			-- Re-assemble keys with multiple &amp;#039;_&amp;#039;&lt;br /&gt;
			if #parts &amp;gt; 2 then&lt;br /&gt;
				local tmp = parts[ 1 ]&lt;br /&gt;
				table.remove( parts, 1 )&lt;br /&gt;
				parts = {&lt;br /&gt;
					tmp,&lt;br /&gt;
					table.concat( parts, &amp;#039;_&amp;#039; )&lt;br /&gt;
				}&lt;br /&gt;
			end&lt;br /&gt;
&lt;br /&gt;
			mw.logObject( parts, &amp;#039;Key Parts&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
			-- safeguard check if we have two parts&lt;br /&gt;
			if #parts == 2 then&lt;br /&gt;
				-- Retrieve data from frameArgs&lt;br /&gt;
				if parts[ 1 ] == &amp;#039;ARG&amp;#039; then&lt;br /&gt;
					value = getFromArgs( datum, translateFn( key ) or &amp;#039;&amp;lt;UNSET&amp;gt;&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
					-- Use EN lang as fallback for arg names that are empty&lt;br /&gt;
					if value == nil then&lt;br /&gt;
						local success, translation = pcall(&lt;br /&gt;
							TNT.formatInLanguage,&lt;br /&gt;
							&amp;#039;en&amp;#039;,&lt;br /&gt;
							string.format( &amp;#039;Module:%s/i18n.json&amp;#039;, moduleName ),&lt;br /&gt;
							key&lt;br /&gt;
                        )&lt;br /&gt;
						if success then&lt;br /&gt;
							value = getFromArgs( datum, translation )&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
				-- Retrieve data from API&lt;br /&gt;
				elseif parts[ 1 ] == &amp;#039;API&amp;#039; and apiData ~= nil then&lt;br /&gt;
					mw.logObject({&lt;br /&gt;
						key_access = parts[2],&lt;br /&gt;
						value = apiData:get( parts[ 2 ] )&lt;br /&gt;
					})&lt;br /&gt;
&lt;br /&gt;
					value = apiData:get( parts[ 2 ] )&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
&lt;br /&gt;
			-- Transform value based on &amp;#039;format&amp;#039; key&lt;br /&gt;
			if value ~= nil then&lt;br /&gt;
				if type( value ) ~= &amp;#039;table&amp;#039; then&lt;br /&gt;
					value = { value }&lt;br /&gt;
				end&lt;br /&gt;
&lt;br /&gt;
				for index, val in ipairs( value ) do&lt;br /&gt;
					-- This should not happen&lt;br /&gt;
					if type( val ) == &amp;#039;table&amp;#039; and datum.type ~= &amp;#039;minmax&amp;#039; and datum.type ~= &amp;#039;subobject&amp;#039; then&lt;br /&gt;
						val = string.format( &amp;#039;!ERROR! Key %s is a table value; please fix&amp;#039;, key )&lt;br /&gt;
					end&lt;br /&gt;
&lt;br /&gt;
					-- Format number for SMW&lt;br /&gt;
					if datum.type == &amp;#039;number&amp;#039; then&lt;br /&gt;
						val = common.formatNum( val )&lt;br /&gt;
					-- Multilingual Text, add a suffix&lt;br /&gt;
					elseif datum.type == &amp;#039;multilingual_text&amp;#039; and moduleConfig.smw_multilingual_text == true then&lt;br /&gt;
						val = string.format( &amp;#039;%s@%s&amp;#039;, val, moduleConfig.module_lang or mw.getContentLanguage():getCode() )&lt;br /&gt;
					-- String format&lt;br /&gt;
					elseif type( datum.format ) == &amp;#039;string&amp;#039; then&lt;br /&gt;
						if string.find( datum.format, &amp;#039;%&amp;#039;, 1, true  ) then&lt;br /&gt;
							val = string.format( datum.format, val )&lt;br /&gt;
						elseif datum.format == &amp;#039;ucfirst&amp;#039; then&lt;br /&gt;
							val = lang:ucfirst( val )&lt;br /&gt;
						elseif datum.format == &amp;#039;replace-dash&amp;#039; then&lt;br /&gt;
							val = string.gsub( val, &amp;#039;%-&amp;#039;, &amp;#039; &amp;#039; )&lt;br /&gt;
						-- Remove part of the value&lt;br /&gt;
						elseif datum.format:sub( 1, 6 ) == &amp;#039;remove&amp;#039; then&lt;br /&gt;
							val = tostring( val ):gsub( mw.text.split( datum.format, &amp;#039;:&amp;#039;, true )[ 2 ], &amp;#039;&amp;#039; )&lt;br /&gt;
						end&lt;br /&gt;
					-- Min/Max&lt;br /&gt;
					elseif datum.type == &amp;#039;minmax&amp;#039; then&lt;br /&gt;
						val = {&lt;br /&gt;
							common.formatNum( val.min ),&lt;br /&gt;
							common.formatNum( val.max ),&lt;br /&gt;
						}&lt;br /&gt;
					-- Subobject&lt;br /&gt;
					elseif datum.type == &amp;#039;subobject&amp;#039; then&lt;br /&gt;
						local api = require( &amp;#039;Module:Common/Api&amp;#039; )&lt;br /&gt;
						for _, data in ipairs( value ) do&lt;br /&gt;
							local subobject = {}&lt;br /&gt;
							data = api.makeAccessSafe( data )&lt;br /&gt;
							commonSMW.addSmwProperties( data, {}, subobject, translateFn, moduleConfig, datum, moduleName )&lt;br /&gt;
							mw.smw.subobject( subobject )&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
&lt;br /&gt;
					table.remove( value, index )&lt;br /&gt;
					table.insert( value, index, val )&lt;br /&gt;
				end&lt;br /&gt;
&lt;br /&gt;
				if datum.type ~= &amp;#039;subobject&amp;#039; and type( smwKey ) == &amp;#039;string&amp;#039; then&lt;br /&gt;
					if type( value ) == &amp;#039;table&amp;#039; and #value == 1 then&lt;br /&gt;
						value = value[ 1 ]&lt;br /&gt;
					end&lt;br /&gt;
&lt;br /&gt;
					smwSetObject[ translateFn( smwKey ) ] = value&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Adds SMW ask properties to the ask object, based on the keys defined in data.json (moduleData)&lt;br /&gt;
---&lt;br /&gt;
--- @param smwAskObject table The table that gets passed to mw.smw.ask&lt;br /&gt;
--- @param translateFn function The translate function used to translate argument names&lt;br /&gt;
--- @param moduleConfig table The module config from config.json&lt;br /&gt;
--- @param moduleData table The module data from data.json&lt;br /&gt;
--- @return void&lt;br /&gt;
function commonSMW.addSmwAskProperties( smwAskObject, translateFn, moduleConfig, moduleData )&lt;br /&gt;
	checkType( &amp;#039;Module:Common/SMW.addSmwAskProperties&amp;#039;, 1, smwAskObject, &amp;#039;table&amp;#039; )&lt;br /&gt;
	checkType( &amp;#039;Module:Common/SMW.addSmwAskProperties&amp;#039;, 2, translateFn, &amp;#039;function&amp;#039; )&lt;br /&gt;
	checkType( &amp;#039;Module:Common/SMW.addSmwAskProperties&amp;#039;, 3, moduleConfig, &amp;#039;table&amp;#039; )&lt;br /&gt;
	checkType( &amp;#039;Module:Common/SMW.addSmwAskProperties&amp;#039;, 4, moduleData, &amp;#039;table&amp;#039; )&lt;br /&gt;
&lt;br /&gt;
	local langSuffix = &amp;#039;&amp;#039;&lt;br /&gt;
	if moduleConfig.smw_multilingual_text == true then&lt;br /&gt;
		langSuffix = &amp;#039;+lang=&amp;#039; .. ( moduleConfig.module_lang or mw.getContentLanguage():getCode() )&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for _, queryPart in ipairs( moduleData.smw_data ) do&lt;br /&gt;
		local smwKey&lt;br /&gt;
		for key, _ in pairs( queryPart ) do&lt;br /&gt;
			if string.sub( key, 1, 3 ) == &amp;#039;SMW&amp;#039; then&lt;br /&gt;
				smwKey = key&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		local formatString = &amp;#039;?%s&amp;#039;&lt;br /&gt;
&lt;br /&gt;
		if queryPart.smw_format then&lt;br /&gt;
			formatString = formatString .. queryPart.smw_format&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- safeguard&lt;br /&gt;
		if smwKey ~= nil and translateFn( smwKey ) ~= nil then&lt;br /&gt;
			table.insert( smwAskObject, string.format( formatString, translateFn( smwKey ) ) )&lt;br /&gt;
&lt;br /&gt;
			if queryPart.type == &amp;#039;multilingual_text&amp;#039; then&lt;br /&gt;
				table.insert( smwAskObject, langSuffix )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return commonSMW&lt;/div&gt;</summary>
		<author><name>starcitizen&gt;Alistair3149</name></author>
	</entry>
</feed>