انتقل إلى المحتوى

وحدة:Distinguish

من ويكيبيديا، الموسوعة الحرة

local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments
local mTableTools
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType

local p = {}

local aliases = {
    selfref = {'مرجع', 'المرجع'},
    text = {'نص', 'النص'}
}

function p.distinguish(frame)
    mArguments = require('Module:Arguments with aliases')
    mTableTools = require('Module:TableTools')

    local args = mArguments.getArgs(frame, {
        aliases = aliases,
        removeBlanks = true
    })

    local selfref = args.selfref
    local textArg = args.text

    args.selfref = nil
    args.text = nil

    args = mTableTools.compressSparseArray(args)

    return p._distinguish(args, textArg, selfref)
end

function p._distinguish(pages, textArg, selfref)
    checkType('_distinguish', 1, pages, 'table')

    if (#pages == 0) and not textArg then
        return ''
    end

    local image = '[[ملف:Confusion grey.svg|20px|link=ويكيبيديا:توضيح]]'

    local parts = {}

    if #pages > 0 then
        table.insert(parts, mHatlist.andList(pages, true, true))
    end

    if textArg then
        table.insert(parts, textArg)
    end

    local finalText = string.format(
        'ميّز عن %s.',
        table.concat(parts, '، ')
    )

    finalText = image .. '  ' .. finalText

    return mHatnote._hatnote(finalText, { selfref = selfref })
end

return p