Page namespace (page_namespace ) | 829 |
Page title without namespace (page_title ) | 'Color contrast' |
Full page title (page_prefixedtitle ) | 'Module talk:Color contrast' |
Edit protection level of the page (page_restrictions_edit ) | [] |
Last ten users to contribute to the page (page_recent_contributors ) | [
0 => 'Cewbot',
1 => 'Gonnym',
2 => 'DePiep',
3 => 'RexxS',
4 => 'Olivier Ph.',
5 => 'RichardW57',
6 => 'Chongkian'
] |
Page age in seconds (page_age ) | 188406402 |
Time since last page edit in seconds (page_last_edit_age ) | 16694786 |
Old content model (old_content_model ) | 'wikitext' |
New content model (new_content_model ) | 'wikitext' |
Old page wikitext, before the edit (old_wikitext ) | '{{WikiProject banner shell|
{{WikiProject Color}}
}}
{{copied|from1=Module:Color_contrast|from_oldid1=823705246|to1=:incubator:Module:Wp/nod/Color_contrast|to_diff1=4243085
|from2=Module:Color_contrast/colors|from_oldid2=673825843|to2=:incubator:Module:Wp/nod/Color_contrast/colors|to_diff2=4243093}}
== Making the lum function accessible from modules ==
I've made the lum function accessible from modules by changing the code from:
<pre>
function p.lum(frame)
return color2lum(frame.args[1] or frame:getParent().args[1])
end</pre>
to:
<pre>
function p.lum(frame)
local args = frame.args[1] or frame:getParent().args[1]
return p._lum(args)
end
function p._lum(args)
return color2lum(args)
end</pre>
The changes are on the [[Module:Color contrast/sandbox|sandbox]] and will implement them if there are no comments. --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 11:03, 6 January 2019 (UTC)
:
: {{re|Gonnym}} That looks like a very sensible and useful improvement. My only reservation is that passing the parameters as a table gives the person wanting to import the routine no idea of what values/types to supply to the routine without having to read through all of the code to determine them. In general I'd usually recommend either documenting a brief list of required values for the args table or passing the parameters as a list of obviously-named variables rather than a table. But that's just a minor point and shouldn't stop you from updating the main module. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 13:03, 6 January 2019 (UTC)
::{{ping|RexxS}} I don't mind doing either if that helps. I just followed the current style used for the other three public functions. Do you want me to change _lum(args) to _lum(color)? --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:27, 6 January 2019 (UTC)
::: {{re|Gonnym}} Sorry, my confusion: now I've looked harder at it, you're actually passing a string representing the colour, not a table (which is what args would most commonly indicate). I would suggest:<syntaxhighlight lang=Lua>
-- use {{#invoke:Color_contrast|somecolor}} directly or {{#invoke:Color_contrast}} from a wrapper template:
function p.lum(frame)
local color = frame.args[1] or frame:getParent().args[1]
return p._lum(color)
end
-- This exports the function for use in other modules.
-- The colour is passed as a string:
function p._lum(color)
return color2lum(color)
end</syntaxhighlight> I know we can put fuller information in the documentation, but I always suggest leaving small annotations in the code to help any re-users.
::: You could also write <code>p._lum = color2lum</code> instead of the second function definition, but setting it out explicitly, as you have done, helps whoever is importing the module to see what parameters to supply. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 15:41, 6 January 2019 (UTC)
::::Sure, looks good. I'll update the sandbox version. --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 15:43, 6 January 2019 (UTC)
== Possible typos in code? ==
Observing the code, I might have spotted a couple of typos:
=== In <code>p._greatercontrast</code> function, lines 160 and 161 ===
I think <syntaxhighlight lang='lua'>if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then</syntaxhighlight> should read <syntaxhighlight lang='lua'>if mw.ustring.match(c3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(c3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then</syntaxhighlight> instead. Here, <code>v3</code> is expected to be a number, thus there is no point in applying it a regular expression. Besides, given the four lines above, it seems logical to use <code>c3</code> variable here instead of <code>v3</code>.
=== In <code>p._styleratio</code> function, line 209 ===
I think <syntaxhighlight lang="lua">if( lum ~= '' ) then bg, lum_fg = v, lum end</syntaxhighlight> should read <syntaxhighlight lang="lua">if( lum ~= '' ) then fg, lum_fg = v, lum end</syntaxhighlight> instead, since at this point we have isolated a forecolor specification from input CSS.
My apologies if I would have misinterpreted your code.
Kindly, [[User:Olivier Ph.|Olivier Ph.]] ([[User talk:Olivier Ph.|talk]]) 12:11, 13 October 2020 (UTC)
== Categorisation broken? ==
Through Documentation subpage, [[:Category:Modules handling colors]] is added as expected. However, the page does not appear in {{clc|Modules handling colors}}. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 15:12, 7 January 2021 (UTC)
:
: {{re|DePiep}} categorisation behaves as something of a black art. The page appears in [[:Category:Modules handling colors]] now, but obviously didn't earlier today. [[Wikipedia:FAQ/Categorization #Why might a category list not be up to date?]] discusses some of the issues that may cause the lag. I usually try a null edit to "touch" the pages concerned and often find the page then appears in the category, but it's not always 100% successful. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:07, 7 January 2021 (UTC)
::I had just edited out the {{tl|Sandbox other}} [https://en.wikipedia.org/enwiki/w/index.php?title=Module:Color_contrast/doc&diff=998898289&oldid=998796533&diffmode=source]. So we have a cause (bug). Did not investigate problem further.-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 16:11, 7 January 2021 (UTC)
::: Yes I saw that. But because the category was being added via {{tl|Sandbox other}} and now is added directly via [[Module:Color contrast/doc]], that becomes effectively a different transclusion and the usual caveats about delays because of cached transclusions apply. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:56, 7 January 2021 (UTC)
::::{{tlf|Sandbox other}} should be checked for Module ns then? But [https://en.wikipedia.org/enwiki/w/index.php?title=Special%3AWhatLinksHere&target=Template%3ASandbox+other&namespace=828 here] it seems to work. (To be clear: before my edit the category was empty, and no delay was working, no recent edits). I'll leave it for now. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 17:18, 7 January 2021 (UTC)' |
New page wikitext, after the edit (new_wikitext ) | '{{WikiProject banner shell|
{{WikiProject Color}}
}}
{{copied|from1=Module:Color_contrast|from_oldid1=823705246|to1=:incubator:Module:Wp/nod/Color_contrast|to_diff1=4243085
|from2=Module:Color_contrast/colors|from_oldid2=673825843|to2=:incubator:Module:Wp/nod/Color_contrast/colors|to_diff2=4243093}}
== Making the lum function accessible from modules ==
I've made the lum function accessible from modules by changing the code from:
<pre>
function p.lum(frame)
return color2lum(frame.args[1] or frame:getParent().args[1])
end</pre>
to:
<pre>
function p.lum(frame)
local args = frame.args[1] or frame:getParent().args[1]
return p._lum(args)
end
function p._lum(args)
return color2lum(args)
end</pre>
The changes are on the [[Module:Color contrast/sandbox|sandbox]] and will implement them if there are no comments. --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 11:03, 6 January 2019 (UTC)
:
: {{re|Gonnym}} That looks like a very sensible and useful improvement. My only reservation is that passing the parameters as a table gives the person wanting to import the routine no idea of what values/types to supply to the routine without having to read through all of the code to determine them. In general I'd usually recommend either documenting a brief list of required values for the args table or passing the parameters as a list of obviously-named variables rather than a table. But that's just a minor point and shouldn't stop you from updating the main module. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 13:03, 6 January 2019 (UTC)
::{{ping|RexxS}} I don't mind doing either if that helps. I just followed the current style used for the other three public functions. Do you want me to change _lum(args) to _lum(color)? --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:27, 6 January 2019 (UTC)
::: {{re|Gonnym}} Sorry, my confusion: now I've looked harder at it, you're actually passing a string representing the colour, not a table (which is what args would most commonly indicate). I would suggest:<syntaxhighlight lang=Lua>
-- use {{#invoke:Color_contrast|somecolor}} directly or {{#invoke:Color_contrast}} from a wrapper template:
function p.lum(frame)
local color = frame.args[1] or frame:getParent().args[1]
return p._lum(color)
end
-- This exports the function for use in other modules.
-- The colour is passed as a string:
function p._lum(color)
return color2lum(color)
end</syntaxhighlight> I know we can put fuller information in the documentation, but I always suggest leaving small annotations in the code to help any re-users.
::: You could also write <code>p._lum = color2lum</code> instead of the second function definition, but setting it out explicitly, as you have done, helps whoever is importing the module to see what parameters to supply. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 15:41, 6 January 2019 (UTC)
::::Sure, looks good. I'll update the sandbox version. --[[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 15:43, 6 January 2019 (UTC)
== Possible typos in code? ==
Observing the code, I might have spotted a couple of typos:
=== In <code>p._greatercontrast</code> function, lines 160 and 161 ===
I think <syntaxhighlight lang='lua'>if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then</syntaxhighlight> should read <syntaxhighlight lang='lua'>if mw.ustring.match(c3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(c3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then</syntaxhighlight> instead. Here, <code>v3</code> is expected to be a number, thus there is no point in applying it a regular expression. Besides, given the four lines above, it seems logical to use <code>c3</code> variable here instead of <code>v3</code>.
=== In <code>p._styleratio</code> function, line 209 ===
I think <syntaxhighlight lang="lua">if( lum ~= '' ) then bg, lum_fg = v, lum end</syntaxhighlight> should read <syntaxhighlight lang="lua">if( lum ~= '' ) then fg, lum_fg = v, lum end</syntaxhighlight> instead, since at this point we have isolated a forecolor specification from input CSS.
My apologies if I would have misinterpreted your code.
Kindly, [[User:Olivier Ph.|Olivier Ph.]] ([[User talk:Olivier Ph.|talk]]) 12:11, 13 October 2020 (UTC)
== Categorisation broken? ==
Through Documentation subpage, [[:Category:Modules handling colors]] is added as expected. However, the page does not appear in {{clc|Modules handling colors}}. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 15:12, 7 January 2021 (UTC)
:
: {{re|DePiep}} categorisation behaves as something of a black art. The page appears in [[:Category:Modules handling colors]] now, but obviously didn't earlier today. [[Wikipedia:FAQ/Categorization #Why might a category list not be up to date?]] discusses some of the issues that may cause the lag. I usually try a null edit to "touch" the pages concerned and often find the page then appears in the category, but it's not always 100% successful. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:07, 7 January 2021 (UTC)
::I had just edited out the {{tl|Sandbox other}} [https://en.wikipedia.org/enwiki/w/index.php?title=Module:Color_contrast/doc&diff=998898289&oldid=998796533&diffmode=source]. So we have a cause (bug). Did not investigate problem further.-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 16:11, 7 January 2021 (UTC)
::: Yes I saw that. But because the category was being added via {{tl|Sandbox other}} and now is added directly via [[Module:Color contrast/doc]], that becomes effectively a different transclusion and the usual caveats about delays because of cached transclusions apply. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:56, 7 January 2021 (UTC)
::::{{tlf|Sandbox other}} should be checked for Module ns then? But [https://en.wikipedia.org/enwiki/w/index.php?title=Special%3AWhatLinksHere&target=Template%3ASandbox+other&namespace=828 here] it seems to work. (To be clear: before my edit the category was empty, and no delay was working, no recent edits). I'll leave it for now. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 17:18, 7 January 2021 (UTC)
== Template-protected edit request on 26 December 2024 ==
{{edit template-protected|Module:Color contrast|answered=no}}
{{subst:trim|1=
<!-- State UNAMBIGUOUSLY your suggested changes below this line, preferably in a "change X to Y" format. Other editors need to know what to add or remove. Blank edit requests will be declined. -->
<!-- Write your request ABOVE this line and do not remove the tildes and curly brackets below. -->
}} ~~~~' |
Unified diff of changes made by edit (edit_diff ) | '@@ -68,2 +68,13 @@
::: Yes I saw that. But because the category was being added via {{tl|Sandbox other}} and now is added directly via [[Module:Color contrast/doc]], that becomes effectively a different transclusion and the usual caveats about delays because of cached transclusions apply. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:56, 7 January 2021 (UTC)
::::{{tlf|Sandbox other}} should be checked for Module ns then? But [https://en.wikipedia.org/enwiki/w/index.php?title=Special%3AWhatLinksHere&target=Template%3ASandbox+other&namespace=828 here] it seems to work. (To be clear: before my edit the category was empty, and no delay was working, no recent edits). I'll leave it for now. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 17:18, 7 January 2021 (UTC)
+
+== Template-protected edit request on 26 December 2024 ==
+
+{{edit template-protected|Module:Color contrast|answered=no}}
+{{subst:trim|1=
+<!-- State UNAMBIGUOUSLY your suggested changes below this line, preferably in a "change X to Y" format. Other editors need to know what to add or remove. Blank edit requests will be declined. -->
+
+
+
+<!-- Write your request ABOVE this line and do not remove the tildes and curly brackets below. -->
+}} ~~~~
' |
Lines added in edit (added_lines ) | [
0 => '',
1 => '== Template-protected edit request on 26 December 2024 ==',
2 => '',
3 => '{{edit template-protected|Module:Color contrast|answered=no}}',
4 => '{{subst:trim|1=',
5 => '<!-- State UNAMBIGUOUSLY your suggested changes below this line, preferably in a "change X to Y" format. Other editors need to know what to add or remove. Blank edit requests will be declined. -->',
6 => '',
7 => '',
8 => '',
9 => '<!-- Write your request ABOVE this line and do not remove the tildes and curly brackets below. -->',
10 => '}} ~~~~'
] |