Difference between revisions of "Module:Distinguish"

From blackwiki
Jump to navigation Jump to search
m (6 revisions imported)
Line 1: Line 1:
<noinclude>
+
local mHatnote = require('Module:Hatnote')
<languages/>
+
local mHatlist = require('Module:Hatnote list')
</noinclude>{{#switch:<translate></translate>
+
local mArguments --initialize lazily
| =
+
local mTableTools --initialize lazily
{{Hatnote|1=<translate><!--T:1--> Not to be confused with</translate> [[:{{{1}}}{{#if:{{{label 1|{{{l1|}}}}}}|{{!}}{{{label 1|{{{l1}}}}}}}}]]{{
+
local libraryUtil = require('libraryUtil')
    #if: {{{3|}}}{{{4|}}}
+
local checkType = libraryUtil.checkType
    |{{int|comma-separator}}[[:{{{2}}}{{#if:{{{label 2|{{{l2|}}}}}}|{{!}}{{{label 2|{{{l2}}}}}}}}]]{{int|comma-separator}} {{
+
local p = {}
      #if: {{{4|}}}
 
      | [[:{{{3}}}{{#if:{{{label 3|{{{l3|}}}}}}|{{!}}{{{label 3|{{{l3}}}}}}}}]]{{int|comma-separator}}<translate><!--T:2--> &nbsp;or</translate>{{int|word-separator}}[[:{{{4}}}{{#if:{{{label 4|{{{l4|}}}}}}|{{!}}{{{label 4|{{{l4}}}}}}}}]]
 
      |<translate><!--T:3--> &nbsp;or</translate>{{int|word-separator}}[[:{{{3}}}{{#if:{{{label 3|{{{l3|}}}}}}|{{!}}{{{label 3|{{{l3}}}}}}}}]]
 
    }}
 
    | {{
 
      #if: {{{2|}}}
 
      |<translate><!--T:4--> &nbsp;or</translate>{{int|word-separator}}[[:{{{2}}}{{#if:{{{label 2|{{{l2|}}}}}}|{{!}}{{{label 2|{{{l2}}}}}}}}]]
 
    }}
 
  }}.}}
 
| #default=
 
  {{#invoke:Template translation|renderTranslatedTemplate|template=Template:Distinguish|noshift=1}}
 
}}<noinclude><!-- splitting these lines causes {{Documentation}} template to terminate green shading when Distinguish is used in /doc pages. -->
 
{{Documentation|content=
 
  
<translate>
+
function p.distinguish(frame)
== Usage == <!--T:6-->
+
mArguments = require('Module:Arguments')
 +
mTableTools = require('Module:TableTools')
 +
local args = mArguments.getArgs(frame)
 +
local selfref = args.selfref
 +
local text = args.text
 +
args = mTableTools.compressSparseArray(args)
 +
return p._distinguish(args, text, selfref)
 +
end
  
<!--T:7-->
+
function p._distinguish(args, text, selfref)
<tvar|1>{{tlx|Distinguish}}</> is used to create [[w:Wikipedia:Hatnote|hatnotes]] to warn about possible confusion with a small number of other, related, titles at the '''top''' of [[w:Help:Section|article sections]] according to [[w:Wikipedia:Layout|Wikipedia:Layout]].
+
checkType("_distinguish", 1, args, 'table')
 +
if #args == 0 and not text then return '' end
 +
local text = string.format(
 +
'Not to be confused with %s.',
 +
text or mHatlist.orList(args, true)
 +
)
 +
hnOptions = {selfref = selfref}
 +
return mHatnote._hatnote(text, hnOptions)
 +
end
  
<!--T:8-->
+
return p
It is not for use in the "See also" ''section'' at the bottom of an article.
 
</translate>
 
 
 
{{Tlx|Distinguish|<translate><!--T:9--> Article 1</translate>|...|''<translate><!--T:10--> Article 4</translate>''|''label 1{{=}}<translate><!--T:18--> label1</translate>''|...|''label 4{{=}}<translate><!--T:19--> label4</translate>''}}
 
 
 
<translate>
 
<!--T:13-->
 
* One to four articles can be listed.</translate>
 
<translate>
 
<!--T:14-->
 
* The word "or" is always placed between the final two entries when displayed.</translate>
 
<translate>
 
<!--T:15-->
 
* If more than 4 entries are supplied, a message will be displayed pointing out the problem.</translate><!-- this is relatively ungraceful failure -->
 
<translate>
 
<!--T:16-->
 
* You can use parameters label 1 to label 4 to specify alternative labels for the links.
 
</translate>
 
:<translate><!--T:17--> Adding newline characters will break article links.</translate> <!-- presumably because of the leading ":" -->
 
 
 
<translate>
 
== Examples == <!--T:5-->
 
</translate>
 
* {{tlx|Distinguish|article1}}
 
{{Distinguish|article1}}
 
* {{tlx|Distinguish|article1|article2}}
 
{{Distinguish|article1|article2}}
 
* {{tlx|Distinguish|article1|article2|article3}}
 
{{Distinguish|article1|article2|article3}}
 
* {{tlx|Distinguish|article1|article2|article3|article4}}
 
{{Distinguish|article1|article2|article3|article4}}
 
* {{tlx|Distinguish|article1|label 1{{=}}label1}}
 
{{Distinguish|article1|label 1=label1}}
 
* {{tlx|Distinguish|article1|article2|label 1{{=}}label1||label 2{{=}}label2}}
 
{{Distinguish|article1|article2|label 1=label1|label 2=label2}}
 
 
 
}}
 
 
 
{{Distinguish/doc}}
 
</noinclude>
 

Revision as of 14:43, 13 December 2020

local mHatnote = require('Module:Hatnote') local mHatlist = require('Module:Hatnote list') local mArguments --initialize lazily local mTableTools --initialize lazily local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local p = {}

function p.distinguish(frame) mArguments = require('Module:Arguments') mTableTools = require('Module:TableTools') local args = mArguments.getArgs(frame) local selfref = args.selfref local text = args.text args = mTableTools.compressSparseArray(args) return p._distinguish(args, text, selfref) end

function p._distinguish(args, text, selfref) checkType("_distinguish", 1, args, 'table') if #args == 0 and not text then return end local text = string.format( 'Not to be confused with %s.', text or mHatlist.orList(args, true) ) hnOptions = {selfref = selfref} return mHatnote._hatnote(text, hnOptions) end

return p