Module:Index template

விக்கிமூலம் இல் இருந்து
Jump to navigation Jump to search

Documentation for this module may be created at Module:Index template/doc

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=ta]]')
    	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('[[பகுப்பு:Indexes with a Wikidata ID]]<indicator name="wikidata">[[File:Wikidata.svg|20px|element Wikidata|link=d:' .. item.id .. ']]</indicator>')
        else
        html:wikitext('[[பகுப்பு:Indexes without a Wikidata ID]]')
	end

    --Left part
    local left = html:tag('div')
    if args.remarks or args.notes then
    	left:css('width', '53%')
    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")
        end
        if imageTitle == nil then
            imageContainer:wikitext(args.image)
        else
            local imageName, imagePage = splitFileNameInFileAndPage(imageTitle)
            if imagePage ~= nil then
	            imageContainer:wikitext('[[File:' .. imageName .. '|page=' .. imagePage .. '|250px]]')
	        else
	            imageContainer:wikitext('[[File:' .. imageName .. '|250px]]')
	        end
        end
    end
    --Metadata
    local metadataContainer = left:tag('div')
    if args.image then
    	metadataContainer:css('margin-left', '150px')
    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, 'தொகுதி', '[[' .. args.volume .. ']]' )
        html:wikitext('[[Category: Books with Volume]]')
    else 
        html:wikitext('[[Category: Books without Volume]]')
    end


    if args.edition then
        addRow(metadataTable, 'பதிப்பு', '[[' .. args.edition .. ']]')
        html:wikitext('[[Category: Books with Edition]]')
    else 
        html:wikitext('[[Category: Books without Edition]]')
    end

    if args.author then
    if item then
        addRow(metadataTable, 'ஆசிரியர்', withWikidataLink(args.author))
        html:wikitext('[[Category: Books with Author]]')
   --     html:wikitext('[[Category: Books by ' .. mw.text.nowiki(args.author)  ..  ']]')
 --       local author = mw.text.nowiki(args.author)
  --      html:wikitext('[[Category: Books by ' .. author  ..  ']]')

        --local author = {{delink|[[args.author]]}}
        --local author = {{#delink|I visited www.example.com example.com.}}
        --local author = {{#invoke:delink | args.author}}
        --local author = mw.text.unstrip( args.author )
        --html:wikitext('[[Category: Books by ' .. author  ..  ']]')

    else 
    addRow(metadataTable, 'ஆசிரியர்', '{{Al|' .. args.author  .. '}}')
    end
    else
        html:wikitext('[[Category: Books without Author]]')
    end


    if args.translator then
    if item then
        addRow(metadataTable, 'மொழிபெயர்ப்பு', withWikidataLink(args.translator))
        html:wikitext('[[Category: Books with Translator]]')
    else 
    addRow(metadataTable, 'மொழிபெயர்ப்பு', '{{Al|' .. args.translator .. '}}')
    end
    else
        html:wikitext('[[Category: Books without Translator]]')
    end


    if args.editor then
    if item then
        addRow(metadataTable, 'தொகுப்பாளர்', withWikidataLink(args.editor))
        html:wikitext('[[Category: Books with Editor]]')
    else
    addRow(metadataTable, 'தொகுப்பாளர்', '{{Al|' .. args.editor .. '}}')
    end
    else 
        html:wikitext('[[Category: Books without Editor]]')
    end
    
    if args.illustrator then
        addRow(metadataTable, 'விளக்கவுரை', withWikidataLink(args.illustrator))
        html:wikitext('[[Category: Books with Illustrator]]')
    else 
        html:wikitext('[[Category: Books without Illustrator]]')
    end

    if args.publisher then
    if item then
        addRow(metadataTable, 'பதிப்பகம்', withWikidataLink(args.publisher))
        html:wikitext('[[Category: Books with Publisher]]')
    -- {{suppress categories|html:wikitext[[Category:No Publisher]]}} 
    --    {{#invoke:Suppress categories|main|html:wikitext[[Category:No Publisher]]}} 
    else 
        addRow(metadataTable, 'பதிப்பகம்', withWikidataLink(args.publisher))
        html:wikitext('[[Category: Books with Publisher]]')
    end
    else
            html:wikitext('[[Category: Books with No Publisher]]')

    end


    if args.address then
        addRow(metadataTable, 'முகவரி', withWikidataLink(args.address))
        html:wikitext('[[Category:Books with Place of Publication]]')
    else 
        if args.publishedin then
            addRow(metadataTable, 'பதிப்பிடம்', withWikidataLink(args.publishedin))
            html:wikitext('[[Category:Books with Place of Publication]]')
          else 
            html:wikitext('[[Category:Books without Place of Publication]]')
        end
    end


    if args.year then
        addRow(metadataTable, 'ஆண்டு', withWikidataLink(args.year))
        html:wikitext('[[Category: Books with Year]]')
    else 
        html:wikitext('[[Category: Books without Year]]')
    end


    if args.printer then
        addRow(metadataTable, 'அச்சகம்', withWikidataLink(args.printer))
        html:wikitext('[[Category: Books with Printer]]')
    else 
        html:wikitext('[[Category: Books without Printer]]')
    end


    if args.source == 'djvu' or args.source == 'pdf' then
		addRow(metadataTable, 'மூலவடிவம்', '[[:File:' .. mw.title.getCurrentTitle().text .. '|' .. args.source .. ']]')

		--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://bn.wikisource.org/> . }\n  OPTIONAL { ?item wdt:P304 ?pages . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],bn".\n}}'

        html:wikitext('<indicator name="index-scan-wikidata">[[File:Wikidata Query Service Favicon.svg|20px|Wikidata items |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, 'மெய்ப்புநிலை', '[[Category:Completed Books]] [[:Category:Completed Books | Completed]]')
	elseif args.progress == 'V' then
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[category:Books to validate]] [[:Category:Books to validate | To validate]]')
	elseif args.progress == 'C' then
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[category:Books to correct]] [[:category:Books to correct|மெய்ப்புப்பணி முடியவில்லை]]')
	elseif args.progress == 'OCR' then
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[category:Books without a text layer]] [[:category:Books without a text layer | Add an OCR text layer]]')
	elseif args.progress == 'L' then
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[category:Books to repair]] <span style = "color: # FF0000;"> [[:category: Books to repair | Defective source file]]</span>')
   elseif args.progress == 'X' then
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[category:Extracts and compilations]] [[:category:Extracts and compilations | Incomplete source:extract or compilation]]')
	else
		addRow(metadataTable, 'மெய்ப்புநிலை', '[[Category:Unknown progress books]] [[:category:Unknown progress books | Unknown progress]]')
	end
	addRow(metadataTable, 'தொகுதிகள்', args.volumes)
	
	if args.pages then
		left:tag('div'):css('clear', 'both')
            left:tag('h3'):wikitext('நூற்பக்கங்கள்')
		left:tag('div'):attr('id', 'pagelist'):css({
			background = '#F0F0F0',
			['padding-left'] = '0.5em',
			['text-align'] = 'justify'
		}):newline():wikitext(args.pages):newline()
	else
		mw.addWarning('You must enter the pagination of the facsimile (Pages field) ')
	end

	if args.remarks or args.notes then
		local right = html:tag('div'):css({
			width = '44%;',
			['padding-left'] = '1em',
			float = 'right'
		})
		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
	
	if args.type == 'book' then
		html:wikitext('[[Category: Index - Books]] ')
	elseif args.type == 'journal' then
		html:wikitext('[[Category: Index - Periodicals]] ')
	 elseif args.type == 'collection' then
		html:wikitext('[[Category: Index - Collections]] ')
	elseif args.type == 'dictionary' then
		html:wikitext('[[Category: Index - Dictionaries]] ')
	elseif args.type == 'phdthesis' then
		html:wikitext('[[Category: Index - Theses]] ')
	end
	html:wikitext('[[Category: Index]] ')

	if args.source ~= 'djvu' then
		html:wikitext('[[Category: Non djvu book]] ')
	elseif args.source == 'pdf' then
		html: wikitext ('[[Category: PDF book]]') 
	elseif args.source == 'ogg' then
		html: wikitext ('[[Category: OGG file]]') 
	elseif args.source == 'webm' then
		html: wikitext ('[[Category: webm file]]') 
	end
	if not args.remarks then
		html: wikitext ('[[Category: Indexed pages]]') 
	end

	return tostring(html)
end

local p = {}
 
function p.indexTemplate( frame )
    return indexTemplate( frame )
end
 
return p
"https://ta.wikisource.org/w/index.php?title=Module:Index_template&oldid=1352314" இருந்து மீள்விக்கப்பட்டது