ഉള്ളടക്കത്തിലേക്ക് പോവുക

ഘടകം:Index template

വിക്കിഗ്രന്ഥശാല സംരംഭത്തിൽ നിന്ന്

ഈ ഘടകത്തിന്റെ വിവരണം ഘടകം:Index template/വിവരണം എന്ന താളിൽ നിർമ്മിക്കാവുന്നതാണ്

categoryForGenre = mw.loadData('Module:Work/genre')
categoryForForm = mw.loadData('Module:Work/form')
categoryForAward = mw.loadData('Module:Work/award')

function withWikidataLink(wikitext, category)
	if wikitext == nil then
		return nil
	end
	new_wikitext = mw.ustring.gsub(wikitext, '%[%[([^|%]]*)%]%]', function(page)
		return addWikidataToLink(page, mw.ustring.gsub(page, '%.*/', '') , category)
	end)
	if new_wikitext ~= wikitext then
		return new_wikitext
	end
	return mw.ustring.gsub(wikitext, '%[%[([^|]*)|([^|%]]*)%]%]', function(page, link)
		return addWikidataToLink(page, link, category)
	end)
end

function addWikidataToLink(page, label, category)
    local title = mw.title.new( page )
    if title == nil then
    	return '[[' .. page .. '|' .. label .. ']]'
    end
    if title.isRedirect then
        title = title.redirectTarget
    end

    local tag = mw.html.create('span')
    local itemId = mw.wikibase.getEntityIdForTitle(title.fullText)
	tag:wikitext('[[' .. page .. '|' .. label .. ']]')
    if itemId ~= nil then
  	tag:wikitext( ' [[Image:Reasonator small logo wider white stripes.svg|15px|link=https://reasonator.toolforge.org/?q=' .. itemId .. '&lang=ml]] [[Image:Wikidocumentaries-logo.png|15px|link=https://wikidocumentaries-demo.wmflabs.org/' .. itemId .. '?language=ml]]')
    	if category ~= nil then
    		tag:wikitext('[[വർഗ്ഗം:' .. category .. ']]')
    	end
  end
  return tostring(tag)
 end

function addRow(metadataTable, key, value)
	if value then
		metadataTable:tag('tr')
			:tag('th')
				:attr('score', 'row')
				:css('vertical-align', 'top')
				:wikitext(key)
				:done()
			:tag('td'):wikitext(value)
	end
end

function splitFileNameInFileAndPage(title)
    local slashPosition = string.find(title.text, "/")
    if slashPosition == nil then
    	return title.text,nil
    else
    	return string.sub(title.text, 1, slashPosition - 1), string.sub(title.text, slashPosition + 1)
    end
end

function indexTemplate(frame)
	--create a clean table of parameters with blank parameters removed
	local data = (require 'Module:Index_data').indexDataWithWikidata(frame)
	local args = data.args
	local item = data.item
	
	local page = mw.title.getCurrentTitle()
	local html = mw.html.create()
	
	if item then
		html:wikitext('[[Category:വിക്കിഡാറ്റയുമായി ലിങ്ക് ചെയ്ത സൂചിക]]<indicator name="wikidata">[[File:Wikidata.svg|20px|വിക്കിഡാറ്റ ഇനം|link=https://www.wikidata.org/wiki/' .. item.id .. '?uselang=ml]]</indicator>')

        if next(item:getBestStatements('P629')) ~= nil then
            local p629statementvalue = item:getBestStatements('P629')[1].mainsnak.datavalue.value.id
            local p629statementitem = mw.wikibase.getEntity(p629statementvalue)
            for _, statement in pairs(p629statementitem:getBestStatements('P136')) do
                if statement.mainsnak.datavalue ~= nil then
                    genreId = statement.mainsnak.datavalue.value.id
                    if categoryForGenre[genreId] then
                        html:wikitext('[[വർഗ്ഗം:' .. categoryForGenre[genreId] .. ']]')
                    end
                end
            end
            for _, statement in pairs(p629statementitem:getBestStatements('P7937')) do
                if statement.mainsnak.datavalue ~= nil then
                    formId = statement.mainsnak.datavalue.value.id
                    if categoryForForm[formId] then
                        html:wikitext('[[വർഗ്ഗം:' .. categoryForForm[formId] .. ']]')
                    end
                end
            end
            for _, statement in pairs(p629statementitem:getBestStatements('P166')) do
                if statement.mainsnak.datavalue ~= nil then
                    awardId = statement.mainsnak.datavalue.value.id
                    if categoryForAward[awardId] then
                        html:wikitext('[[വർഗ്ഗം:' .. categoryForAward[awardId] .. ']]')
                    end
                end
            end
        end
    else
        html:wikitext('[[Category:വിക്കിഡാറ്റയുമായി ലിങ്ക് ചെയ്യാത്ത താൾ]]')
	end

    --Left part
    local left = html:tag('div')
    if args.remarks or args.notes then
    	left:css('width', '60%')
    end
    left:css('float', 'left')
    --Image
    if args.image then
        local imageContainer = left:tag('div')
            :css({
                float = 'left',
                overflow = 'hidden',
                border = 'thin grey solid'
            })
        local imageTitle = nil
        if tonumber(args.image) ~= nil then
            -- this is a page number
            imageTitle = mw.title.getCurrentTitle():subPageTitle(args.image)
        else
            -- this is an other file
            imageTitle = mw.title.new(args.image, "Media")
            -- TODO mettre une catégorie pour les livres ayant une couverture qui ne provient pas du DJVU/PDF
        end
        if imageTitle == nil then
            imageContainer:wikitext(args.image)
            -- TODO mettre une catégorie de maintenance ici lorsque la couverture est manquante
        else
            local imageName, imagePage = splitFileNameInFileAndPage(imageTitle)
            if imagePage ~= nil then
	            imageContainer:wikitext('[[File:' .. imageName .. '|page=' .. imagePage .. '|200px]]')
	        else
	            imageContainer:wikitext('[[File:' .. imageName .. '|200px]]')
	        end
        end
    end
    --Metadata
    local metadataContainer = left:tag('div')
    if args.image then
    	metadataContainer:css('margin-left', '160px')
    end
    local metadataTable = metadataContainer:tag('table')

    if args.title then
       if item then
    		addRow(metadataTable, 'തലക്കെട്ട്', withWikidataLink(args.title, 'വിക്കിഡാറ്റയുമായി ലിങ്ക് ചെയ്യൽ'))
else 
     addRow(metadataTable, 'തലക്കെട്ട്', '' .. args.title .. '')
    	end
    else
    	mw.addWarning('പുസ്തകത്തിന്റെ പേര് ചേർത്തിട്ടില്ല')
    end

	addRow(metadataTable, 'അടിക്കുറിപ്പ്', withWikidataLink(args.subtitle))

if args.volume then
     addRow(metadataTable, 'വോള്യം', '{{#invoke:ConvertDigit|main|' .. args.volume .. '}}')
else 
end

if args.issue then
     addRow(metadataTable, 'number', '{{#invoke:ConvertDigit|main|' .. args.issue .. '}}')
else 
end

if args.edition then
	addRow(metadataTable, 'വാല്യം', '{{#invoke:ConvertDigit|main|' .. args.edition .. '}}')
else 
end

if args.author then
    if item then
        local p50stmt = item['claims']['P50'][1]
        if p50stmt['mainsnak']['snaktype'] == 'somevalue' then
            addRow(metadataTable, 'രചയിതാവ്', withWikidataLink('രചയിതാവ്:അറിയപ്പെടാത്ത രചയിതാവ്', 'അറിയപ്പെടാത്ത രചയിതാവിന്റെ സൃഷ്ടി'))
        else
            addRow(metadataTable, 'രചയിതാവ്', withWikidataLink(args.author))
            -- local authors = item:formatPropertyValues( 'P50', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
            -- for author in string.gmatch(authors, '([^,]+)') do
            --     html:wikitext('[[Category:' .. author  ..  ' Written by]]')
            -- end
            local authors = item:getBestStatements('P50')
            for i, author in pairs(authors) do
                if author.mainsnak.snaktype == 'value' then
                    local authorid = author.mainsnak.datavalue.value.id
                    local authoritem = mw.wikibase.getEntity(authorid)
                    local authorsitelink = authoritem:getSitelink('mlwikisource')
                    if authorsitelink ~= nil then
                        local authorsitelinkname = mw.ustring.sub(authorsitelink, 6)
                        html:wikitext('[[വർഗ്ഗം:' .. authorsitelinkname  ..  ' എഴുതിയത്]]')
                    end
                end
            end
        end
    else 
        addRow(metadataTable, 'രചയിതാവ്', '{{Al|' .. args.author .. '}} [[വർഗ്ഗം:' .. args.author .. ' എഴുതിയത്]]')
    end
else
end

if args.translator then
    if item then
        local p655stmt = item['claims']['P655'][1]
        if p655stmt['mainsnak']['snaktype'] == 'somevalue' then
            addRow(metadataTable, 'translate', withWikidataLink('[[Author:Unknown author]]', 'അറിയപ്പെടാത്ത വിവർത്തകന്റെ വിവർത്തനം'))
        else
            addRow(metadataTable, 'വിവർത്തകൻ', withWikidataLink(args.translator))
            -- local translators = item:formatPropertyValues( 'P655', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
            -- for translator in string.gmatch(translators, '([^,]+)') do
            --     html:wikitext('[[Category:' .. translator  ..  ' translated]]')
            -- end
            local translators = item:getBestStatements('P655')
            for i, translator in pairs(translators) do
                if translator.mainsnak.snaktype == 'value' then
                    local translatorid = translator.mainsnak.datavalue.value.id
                    local translatoritem = mw.wikibase.getEntity(translatorid)
                    local translatorsitelink = translatoritem:getSitelink('mlwikisource')
                    if translatorsitelink ~= nil then
                        local translatorsitelinkname = mw.ustring.sub(translatorsitelink, 6)
                        html:wikitext('[[വർഗ്ഗം:' .. translatorsitelinkname  ..  ' വിവർത്തനം ചെയ്തത്]] [[Category:Translated literature]]')
                    end
                end
            end
        end
    else 
        addRow(metadataTable, 'author', '{{Al|' .. args.translator .. '}} [[വർഗ്ഗം:' .. args.translator .. ' തർജ്ജമ ചെയ്തത്]]')
    end
else
end

if args.foreword_author then
if item then
    addRow(metadataTable, 'foreword author', withWikidataLink(args.foreword_author))
        local foreword_authors = item:formatPropertyValues( 'P2679', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for foreword_author in string.gmatch(foreword_authors, '([^,]+)') do
end
  else 
   addRow(metadataTable, 'foreword author', '{{Al|' .. args.foreword_author .. '}}')
 end
else 
end

if args.afterword_author then
if item then
    addRow(metadataTable, 'afterword author', withWikidataLink(args.afterword_author))
        local afterword_authors = item:formatPropertyValues( 'P2680', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for afterword_author in string.gmatch(afterword_authors, '([^,]+)') do
end
  else 
   addRow(metadataTable, 'afterword author', '{{Al|' .. args.afterword_author .. '}}')
 end
else 
end

if args.editor then
if item then
	addRow(metadataTable, 'എഡിറ്റർ', withWikidataLink(args.editor))
    local editors = item:formatPropertyValues( 'P98', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for editor in string.gmatch(editors, '([^,]+)') do
    html:wikitext('[[വർഗ്ഗം:' ..  editor  ..  ' തിരുത്തിയത്]]')
end
else
   addRow(metadataTable, 'എഡിറ്റർ', '{{Al|' .. args.editor .. '}}')
end
  else 
 end

	addRow(metadataTable, 'ഇല്ലുസ്ട്രേറ്റർ', withWikidataLink(args.illustrator))

if args.lyricist then
if item then
	addRow(metadataTable, 'ഗാനരചയിതാവ്', withWikidataLink(args.lyricist))
    local lyricists = item:formatPropertyValues( 'P676', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for lyricist in string.gmatch(lyricists, '([^,]+)') do
    html:wikitext('[[വർഗ്ഗം:' ..  lyricist  ..  ' രചിച്ചത്]]')
end
else
   addRow(metadataTable, 'ഗാനരചയിതാവ്', '{{Al|' .. args.lyricist .. '}}')
end
  else 
 end

if args.composer then
if item then
	addRow(metadataTable, 'രചയിതാവ്', withWikidataLink(args.composer))
    local composers = item:formatPropertyValues( 'P86', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for composer in string.gmatch(composers, '([^,]+)') do
    html:wikitext('[[വർഗ്ഗം:' ..  composer  ..  ' രചിച്ചത്]]')
end
else
   addRow(metadataTable, 'രചയിതാവ്', '{{Al|' .. args.composer .. '}}')
end
  else 
 end

if args.singer then
if item then
	addRow(metadataTable, 'പാട്ടുകാരൻ', withWikidataLink(args.singer))
    local singers = item:formatPropertyValues( 'P175', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for singer in string.gmatch(singers, '([^,]+)') do
end
else
   addRow(metadataTable, 'പാട്ടുകാരൻ', '{{Al|' .. args.singer .. '}}')
end
  else 
 end

if args.publisher then
if item then
	addRow(metadataTable, 'പബ്ലിഷർ', withWikidataLink(args.publisher))
    local publishers = item:formatPropertyValues( 'P123', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )['value']
   for publisher in string.gmatch(publishers, '([^,]+)') do
    html:wikitext('[[വർഗ്ഗം:' ..  publisher  ..  ' പ്രസിദ്ധീകരിച്ചത്]]')
end
  else 
   addRow(metadataTable, 'publisher', '[[Publisher:' .. args.publisher .. '|' .. args.publisher .. ']]')
 end
 else
html:wikitext( '[[വർഗ്ഗം:പ്രസാധകന്റെ വിവരങ്ങളില്ലാത്ത നിഘണ്ടു താൾ]]' )
end

if args.address then
if item then
	addRow(metadataTable, 'വിലാസം', withWikidataLink(args.address))
 else
   addRow(metadataTable, 'വിലാസം', '[[:w:ml:' .. args.address .. '|' .. args.address .. ']]')
end
  else 
html:wikitext('[[വർഗ്ഗം:പ്രസിദ്ധീകരണ വിവരങ്ങളില്ലാത്ത നിഘണ്ടു താൾ]]' )
 end

    if args.year then
	addRow ( metadataTable , 'പ്രസിദ്ധീകരിച്ച വർഷം' , '{{#invoke:ConvertDigit|main|' .. args . year .. '}} എഡി  [[Category:{{#invoke:ConvertDigit|main|' .. args . year .. '}} എഡി-യിൽ പ്രസിദ്ധീകരിച്ചത്]]' ) 
	else 
html:wikitext('[[വർഗ്ഗം:പ്രസിദ്ധീകരണ വർഷമില്ലാത്ത നിഘണ്ടു താൾ]]' )
end

	addRow(metadataTable, 'printer', withWikidataLink(args.printer))

	if args.source == 'djvu' then
		addRow(metadataTable, 'സ്രോതസ്സ്', '[[File:DjVu-logo.svg|25px|link=File:' .. mw.title.getCurrentTitle().text ..']] [[File:BookReader-favicon.svg|20px|link={{fullurl:toollabs:bookreader/ml/{{{n|{{PAGENAMEE}}}}}}}]]')
	elseif args.source == 'pdf' then
		addRow(metadataTable, 'സ്രോതസ്സ്', '[[File:Icon pdf.svg|25px|link=File:' .. mw.title.getCurrentTitle().text ..']] [[File:BookReader-favicon.svg|20px|link={{fullurl:toollabs:bookreader/ml/{{{n|{{PAGENAMEE}}}}}}}]]')
	elseif args.source == 'ogg' then
		addRow(metadataTable, 'സ്രോതസ്സ്', '[[File:Speaker Icon.svg|20px|link=File:' .. mw.title.getCurrentTitle().text ..']]')
	elseif args.source == 'webm' then
		addRow(metadataTable, 'സ്രോതസ്സ്', '[[File:Open Iconic video.svg|20px|link=File:' .. mw.title.getCurrentTitle().text ..']]')
	elseif args.source == 'mp3' then
		addRow(metadataTable, 'സ്രോതസ്സ്', '[[File:Speaker Icon.svg|20px|link=File:' .. mw.title.getCurrentTitle().text ..']]')

		--add an indicator linking to the usages
		local query = 'SELECT ?item ?itemLabel ?pages ?page WHERE {\n  ?item wdt:P996 <http://commons.wikimedia.org/wiki/Special:FilePath/' .. mw.uri.encode(mw.title.getCurrentTitle().text, 'PATH') .. '> .\n  OPTIONAL { ?page schema:about ?item ; schema:isPartOf <https://ml.wikisource.org/> . }\n  OPTIONAL { ?item wdt:P304 ?pages . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ml".\n}}'
		html:wikitext('<indicator name="index-scan-wikidata">[[File:Wikidata Query Service Favicon.svg|20px|Wikidata item|link=https://query.wikidata.org/embed.html#' .. mw.uri.encode(query, 'PATH') .. ']]</indicator>')
	else
		addRow(metadataTable, 'സ്രോതസ്സ്', args.source)
	end
	if args.progress == 'T' then
		addRow(metadataTable, 'പുരോഗതി', '[[വർഗ്ഗം:സൂചിക - സാധൂകരിച്ചവ]][[:വർഗ്ഗം:സൂചിക - സാധൂകരിച്ചവ]][[:വർഗ്ഗം:സൂചിക - സാധൂകരിച്ചവ|പൂർത്തിയായി.]]')
	elseif args.progress == 'V' then
		addRow(metadataTable, 'പുരോഗതി', '[[വർഗ്ഗം:സൂചിക - തെറ്റുതിരുത്തിയവ.]][[:വർഗ്ഗം:സൂചിക - തെറ്റുതിരുത്തിയവ | തെറ്റുതിരുത്തൽ വായന കഴിഞ്ഞവ]]')
	elseif args.progress == 'C' then
		addRow(metadataTable, 'പുരോഗതി', '[[വർഗ്ഗം:സൂചിക - തെറ്റുതിരുത്തേണ്ടവ]][[:Category:The printout of the dictionary has not been corrected|തെറ്റുതിരുത്തൽ വായന നടന്നിട്ടില്ലാത്തവ]]')
	elseif args.progress == 'OCR' then
		addRow(metadataTable, 'പുരോഗതി', '[[Category:Ready for transcription-OCR and print correction]][[:Category:Nirghanta-Ready for OCR and print correction|Ready for OCR and print correction]]')
	elseif args.progress == 'L' then
		addRow(metadataTable, 'പുരോഗതി', '[[Category:The dictionary file needs to be fixed.]]<span style="color: #FF0000; ">[[:Category:The dictionary file needs to be fixed | This file needs to be fixed before printing.]]</span>')
   elseif args.progress == 'X' then
		addRow(metadataTable, 'പുരോഗതി', '[[Category:The dictionary file needs to be checked.]][[:Category:The dictionary file needs to be checked | സൂചിക താൾ സൃഷ്ടിക്കാനുണ്ട്]]')
	else
		addRow(metadataTable, 'പുരോഗതി', '[[വർഗ്ഗം:സൂചിക - പുരോഗതി അടയാളപ്പെടുത്താത്തവ]][[:വർഗ്ഗം:സൂചിക - പുരോഗതി അടയാളപ്പെടുത്താത്തവ|പുരോഗതി തീർച്ചയില്ലാത്തവ]]')
	end
	addRow(metadataTable, 'fragments', args.volumes)
	
	if args.pages then
		left:tag('div'):css('clear', 'both')
		left:tag('h3'):wikitext('പുസ്തക താളുകൾ <br> {{പുരോഗതി|{{PAGENAME}}}}')
		left:tag('div'):attr('id', 'pagelist'):css({
			background = '#F0F0F0',
			['padding-left'] = '0.5em',
			['text-align'] = 'justify'
		}):newline():wikitext(args.pages):newline()
	else
		mw.addWarning('താളുകളുടെ പട്ടിക സൃഷ്ടിക്കുക')
	end

	if args.remarks or args.notes then
		local right = html:tag('div'):css({
			width = '35%;',
			['padding-left'] = '1em',
			float = 'left'
		})
		if args.remarks then
			right:tag('div'):attr('id', 'remarks'):wikitext(args.remarks)
		end
		if args.notes then
			right:tag('hr'):css({
				['margin-top'] = '1em',
				['margin-bottom'] = '1em'
			})
			right:tag('div'):attr('id', 'notes'):wikitext(args.notes)
		end
	end
	
	html:wikitext('[[Category:നിഘണ്ടു]]')

	if args.source == 'djvu' then
		html:wikitext('[[Category:Deja Vu നിഘണ്ടു താൾ]]')
	elseif args.source == 'pdf' then
		html:wikitext('[[Category:PDF നിഘണ്ടു താൾ‎]]')
	elseif args.source == 'ogg' then
		html:wikitext('[[Category:OGG നിഘണ്ടു താൾ]]')
	elseif args.source == 'webm' then
		html:wikitext('[[Category:webm നിഘണ്ടു താൾ‎]]')
	elseif args.source == 'mp3' then
		html:wikitext('[[Category:mp3 നിഘണ്ടു താൾ‎]]')
	end
	if not args.remarks then
		html:wikitext('[[Category:സൂചികയില്ലാത്ത നിഘണ്ടു താൾ]]')
	end

	return tostring(html)
end

local p = {}
 
function p.indexTemplate( frame )
    return indexTemplate( frame )
end
 
return p
"https://ml.wikisource.org/w/index.php?title=ഘടകം:Index_template&oldid=238504" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്