Module talk:Flags: Difference between revisions

Content deleted Content added
m <font> → span style>
 
(25 intermediate revisions by 9 users not shown)
Line 1:
==Code change ==
Hello I saw your module on it.wiki, and I woulwould like to make some changes to the code:
# declare local all variables, they are more efficient and quick to access and you dont pollute global namespace
# Why do you use a for loop to check if a key is in the table like:
Line 19:
end
</syntaxhighlight>
#3. Why check for <code>if territory.args[2] ~= "{{{2}}}" then</code> ? AFAIK a paremeter call will be resolved before call the module and substituded by its value.
 
I will upload my changes to the sandbox for test.--[[User:Moroboshi|Moroboshi]] ([[User talk:Moroboshi|talk]]) 11:14, 22 July 2013 (UTC)
:Thank you for the interest and the good advice! This is not only my first attempt with Lua programming, it is also my most serious attempt to program anything out of HTML/CSS. For instance, I wasn't aware that by not declaring variables explicitly local the module would pullute the global namespace (something that sounds obvious now that you say it).
: Your approach in 2) is definitely smarter and I'm happy to take it after testing that there are no side effects (I don't see why there should be any).
: <code>if territory.args[2] ~= "{{{2}}}" then</code> is the way I found to check whether a parameter for variants i.e. "1945" has been defined, after [[mw:Extension_talk:Scribunto#x.27Equal.27_character_used_in_template_parameter_messes_things:_bug_or_feature.3F__28646|asking at mediawiki.org]]. Improvements welcome.
::Now I comprend you check for a parameter not definited. I think its cleaner to set the parameter to <code><nowiki>{{{2|}}}</nowiki></code> in the template and check for null string <code>""</code> in the module.--[[User:Moroboshi|Moroboshi]] ([[User talk:Moroboshi|talk]]) 18:01, 22 July 2013 (UTC)
:::The same for <code>{{{link}}}</code> or <code>{{{text}}}</code>, set them to <code><nowiki>{{{link|}}}</nowiki></code> or <code><nowiki>{{{text|}}}</nowiki></code> and check for null string in the module. I uploaded the modified flags to [[Module:Flags/Sandbox]] with some comments about my changes. Apparently it works with the example test in the doc.--[[User:Moroboshi|Moroboshi]] ([[User talk:Moroboshi|talk]]) 18:49, 22 July 2013 (UTC)
::::I had a first look at you version in the sandbox. Looks good, and you are saving almost 20 LOC! But I want to be cautious taking the changes since the template is already transcluded in 600 articles at ca.wiki. Where is git when you need it? ;) I'm starting my holidays tomorrow, flying and then having less time in front of the laptop. Still, I should be able to connect in the evenings. Feel free to "merge" your changes, just trying to do it edit by edit with comments for posterity. Welcome to the team! :)
::::Just curious: why are you changing the sequence of the script? It makes comparing code a bit more difficult. I had the idea of going for 1 Name; 2 Variant; 3 Size; 4 Link; 5 Label - but if there are good reasons to change it I'm all ears.
::::I had trouble with other approaches for <code>{{{link}}}</code> or <code>{{{text}}}</code>. Null string is actually different from no parameter defined. Users can set <nowiki>link=</nowiki> or <nowiki>text=</nowiki> to give specific instructions to the template (no link and same label as name of flag).
I think the only thing I moved out of order was the function default_size (and obviously check_translation that is new), i assigned the name flag_code to territory.args[1] because is used in different points of the script (but maybe the name could be more specific).<br>
Regarding the use of parameters do you known that you can simplify the template call removing all parameters like <code><nowikI>{{Invoke|Flags|flag}}</nowiki></code> and access the parameters used in the template call directly in the lua module using <code>territory:parent().args()</code> ? Is sufficient to add this code to the start of the function:
<syntaxhighlight lang="lua">
function p.flag(territory)
-- get the frame of the calling calling template
local pframe = territory:getParent()
-- get all parameter and store them in a table (pframe return a table with limited function, see scribunto documentation)
local args = {}
for k, v in pairs( pframe.args ) do
args[k] = v
end
</syntaxhighlight >
And then you can check the parameter in the standard way, <code>args[1]</code> por positional parameter 1 and <code>args['text']</code> or <code>args.text</code> for named parameter "text". If text is not definet it will be nil, if its defined but empty <nowiki>text=</nowiki> then it will be equal to the null string <code>""</code>:
 
Good holiday, I will fly next week. --[[User:Moroboshi|Moroboshi]] ([[User talk:Moroboshi|talk]]) 22:25, 23 July 2013 (UTC)
:Changes tested and taken. Thank you very much!--[[User:QuimGil|QuimGil]] ([[User talk:QuimGil|talk]]) 03:56, 22 August 2013 (UTC)
 
== Problem with [[:File:Flag of the Soviet Union 1955.svg]] ==
 
There seems to be a problem with the flag for the Soviet Union. This is affecting at least 49 pages (the Winter Olympics articles at [[:Category:Articles with missing files]]). One file being called is [[:File:Flag of the Soviet Union 1955.svg]], which seems to be a redirect to [[:File:Flag of the Soviet Union (1938-1980).svg]]. Other Soviet Union flags redirecting to that one also seem to be missing, causing the bigger problem. - <b>[[User:Tucoxn|<span style="font-family:Verdana; color:#522C1B"><span style="font-size:large"><span class="Unicode">t</span></span>u</span><span style="color:#417DC1">coxn</span>]]</b>\<sup style="font-family:serif">[[User_talk:Tucoxn|talk]]</sup> 01:11, 13 February 2014 (UTC)
:Please spell it out with an example for dummies unfamiliar with the topic. I would like a link to an article and a brief description of how I can see there is something wrong (I don't mean the category, I mean where is the error in the article). [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:07, 13 February 2014 (UTC)
:I'd better add [[User:Tucoxn]] for a ping. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:09, 13 February 2014 (UTC)
::[[User:Johnuniq|Johnuniq]]: Thanks for your response but it looks like this got fixed. It looks like this was an issue with some changes on Commons due to a rename request. Here are some Commons file histories that might explain what the problem was: [https://commons.wikimedia.org/w/index.php?title=File:Flag_of_the_Soviet_Union_(1938-1980).svg&action=history history for "File:Flag of the Soviet Union (1938-1980).svg"], [https://commons.wikimedia.org/w/index.php?title=File:Flag_of_the_Soviet_Union_1955.svg&action=history history for "File:Flag of the Soviet Union 1955.svg"], and [https://commons.wikimedia.org/w/index.php?title=File:Flag_of_the_Soviet_Union_(1955-1980).svg&action=history history for "File:Flag of the Soviet Union (1955-1980).svg"] (a new file). Again, this seems fixed for now. Thanks! - <b>[[User:Tucoxn|<span style="font-family:Verdana; color:#522C1B"><span style="font-size:large"><span class="Unicode">t</span></span>u</span><span style="color:#417DC1">coxn</span>]]</b>\<sup style="font-family:serif">[[User_talk:Tucoxn|talk]]</sup> 09:43, 13 February 2014 (UTC)
 
== Performance ==
 
Is this module faster or slower than the old [[Wikipedia:WikiProject Flag Template|flag templates]] based on [[:Category:Country data templates|Country data system]]? <span style="font-family:Segoe Script">[[User:Petr Matas|Petr Matas]]</span> 01:15, 22 June 2014 (UTC)
: I have done some measurements myself. Analysis of a page with 50 {{tl|Flagicon}}s takes 429±65 ms, analysis of a page with 50 {{tl|Flags}} takes 472±66 ms of CPU time. The performance difference is lower than the measurement error. <span style="font-family:Segoe Script">[[User:Petr Matas|Petr Matas]]</span> 10:47, 23 June 2014 (UTC)
 
::Perhaps it would help performance to convert [[Module:Flags/MasterData]] to a JSON page and load its contents using <code>mw.text.jsonDecode()</code>. &ndash;&nbsp;[[User:Mxn|Minh <span style="font-variant: small-caps;">Nguyễn</span>]]&nbsp;<sup>[[User talk:Mxn|<span style="display: inline-block;">&#x1f4ac;</span>]]</sup> 05:33, 13 June 2019 (UTC)
 
== Chuuk creates a link to a dab page ==
 
{{tlc|flags|Chuuk}} creates a link to a dab page [[Chuuk]]. It should like to the article [[Chuuk State]] instead. Here's an illustration: {{flags|Chuuk}}. Can someone fix that? [[User:Coastside|Coastside]] ([[User talk:Coastside|talk]]) 05:16, 20 January 2020 (UTC)