Модуль:ТСД/Данные по странице

Документация Документация
local moduleHeader = require('Module:Header')
-- local moduleFunc = require('Модуль:ТСД/Функции')

t = {
    ['title'] = '',
    ['pagename'] = '',
    ['currname'] = '',
    ['oldspell'] = '',
    ['tom'] = '',
    ['god'] = '',
    ['izdanie'] = '',
    [1] = {
        ['termin_so'] = '',
        ['termin_do'] = '',
        ['list'] = '',
        ['wordlist_str'] = '',
        ['numpage_scan'] = '',
        ['numpage_book'] = '',
        ['next'] = '',
        ['previous'] = '',
        ['indexlink'] = '',
        ['tom'] = '',
        ['god'] = '',
    },
    [2] = {
        ['termin_so'] = '',
        ['termin_do'] = '',
        ['list'] = '',
        ['wordlist_str'] = '',
        ['numpage_scan'] = '',
        ['numpage_book'] = '',
        ['next'] = '',
        ['previous'] = '',
        ['indexlink'] = '',
        ['tom'] = '',
        ['god'] = '',
    },
    [3] = {
        ['termin_so'] = '',
        ['termin_do'] = '',
        ['list'] = '',
        ['wordlist_str'] = '',
        ['numpage_scan'] = '',
        ['numpage_book'] = '',
        ['next'] = '',
        ['previous'] = '',
        ['indexlink'] = '',
        ['tom'] = '',
        ['god'] = '',
    },
    ['indexlinks_all'] = '',
    ['categories'] = '',
    ['bukvi_toma'] = {
        { 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З' },
        { 'И', 'І', 'К', 'Л', 'М', 'Н', 'О' },
        { 'П' },  -- в ТСД-3 буква 'Р' в 3-м томе
        { 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Ѣ', 'Э', 'Ю', 'Ѧ', 'Я', 'Ѳ', 'Ѵ' }
    },
    ['god_toma'] = { { 1863, 1865, 1865, 1866 }, { 1880, 1881, 1882, 1882 }, { 1903, 1905, 1907, 1909 } }
}

----------- helpers --
-- создание ссылки
function make_link(prefix, pagename, text)
    return '[[' .. prefix .. pagename .. '|' .. text .. ']]'
end

-- проверка переменной, возврат её или nil если пустая
function is(var)
    if (var == '' or var == nil) then return nil else return var end
end

--------------------------------------------

local currtitle = mw.title.getCurrentTitle() -- текущая страница
local currname = currtitle["text"]
local currlist = currtitle["rootText"]

local nameparts = mw.text.split(currname, "/")
if not is(nameparts[2]) then return t end

if nameparts[1] == 'ТСД' then
	t['title'] = nameparts[2] 	
	local pagename = nameparts[1]..'/'..nameparts[2]
	t['pagename'] = pagename
	if nameparts[3] == 'ДО' then t['oldspell'] = '/ДО' end
	
	for i = 1, 3 do -- izdanie
		
		local list, wordlist_str, tom, term_so, term_do, previous, next, pns, pnb
		
		list = moduleHeader.wordlist({ args = { nil, pagename, tostring(i) } })
		if is(list) then
			
		    t[i]['list'] = list
		    wordlist_str = 'ТСД-словник/'..tostring(i)..'/'..list
		    t[i]['wordlist_str'] = wordlist_str
		
			term_so = moduleHeader.title({ args = { pagename, wordlist_str, ['safe'] = true } })
		    if is(term_so) then 
		    	
		    	t[i]['termin_so'] = t['title']
		    	-- t[i]['termin_so'] = term_so
		    	t['categories'] = t['categories'] .. '[[Категория:ТСД:Статьи из '..tostring(i)..'-го издания]]' 
		    	
			    term_do = moduleHeader.title({ args = { pagename, wordlist_str, ['ДО'] = true, ['safe'] = true } })
			    if is(term_do) then t[i]['termin_do'] = term_do 
			    else t[i]['termin_do'] = term_so end
			
			    previous = moduleHeader.previous({ args = { pagename, wordlist_str, ['type'] = 'name', ['safe'] = true } })
			    if is(previous) then
			        t[i]['previous'] = previous
			        t[i]['link_previous'] = make_link( nameparts[1]..'/', t[i]['previous']..t['oldspell'], t[i]['previous']..t['oldspell'] )
			    end
		
			    next = moduleHeader.next({ args = { pagename, wordlist_str, ['type'] = 'name', ['safe'] = true } })
			    if is(next) then
			        t[i]['next'] = next
			        t[i]['link_next'] = make_link( nameparts[1]..'/', t[i]['next']..t['oldspell'], t[i]['next']..t['oldspell'] )
			    end
			    
				tom = moduleHeader.volume_calc({ args = {'ТСД'..tostring(i), t[i]['termin_do']} })
			    t[i]['tom'] = tom
			    t[i]['god'] = t['god_toma'][i][tom]
			
			    pnb = moduleHeader.pagenum({ args = { 'hard', ['name'] = pagename, ['list'] = wordlist_str } })
			    if is(pnb) then 
			    	t[i]['numpage_book'] = pnb
				    pns = moduleHeader.pagescan_calc({ args = { 'ТСД'..tostring(i), tom, pnb} })
				    if is(pns) then 
				    	t[i]['numpage_scan'] = pns 
			    	else
			    		t['categories'] = t['categories'] .. '[[Категория:ТСД:'..tostring(i)..'-е издание, не указана страница скана]]'
			    	end
				else 
					t['categories'] = t['categories'] .. '[[Категория:ТСД:'..tostring(i)..'-е издание, не указана страница книги]]'
			    end
		
				--[=[ перенесено в Модуль:Header
				local indexlink = moduleFunc.indexlink({ args = {i, tom, pns, pnb} })
			    if indexlink then 
			    	if is(t['indexlinks_all']) then 
			    		-- оформление: ' • ' между ссылками
			    		t['indexlinks_all'] = t['indexlinks_all']..' • '..indexlink
		    		else
		    			t['indexlinks_all'] = indexlink
	    			end
	    		end
	    		--]=]
	    		
		    end
		end
	end

elseif nameparts[1] == 'ТСД-словник' then
	local izdanie, tom
	if nameparts[3] then
		t['title'] = nameparts[3]
		-- local izdanie = tonumber(mw.ustring.sub(nameparts[3], 1, 1))   ---t['title']
		izdanie = tonumber(nameparts[2])
		tom = tonumber(moduleHeader.volume_calc({ args = {'ТСД'..tostring(izdanie), t['title']} }))
		t[izdanie]['tom'] = tom
		t[izdanie]['god'] = t['god_toma'][izdanie][tom]
		t['izdanie'] = izdanie
	--[[	else
		t['title'] = nameparts[2]
		if t['title'] == 'Ъ-Ы-Ь' or t['title'] == 'Ѣ' or t['title'] == 'Ѧ' or t['title'] == 'Ѳ' then
			tom = 4 end --]]
	end
end

--[==[
elseif mw.ustring.find(nameparts[1], 'Толковый словарь') then
	for god_page in mw.ustring.gmatch (nameparts[1], "(19%d%d)") do
		for i, v in pairs(t['god_toma']) do
			for god in pairs(v) do
				if god == god_page then izdanie = i end
			end
		end
	end
	-- local izdanie = tonumber(mw.ustring.sub(nameparts[3], 1, 1))
	izdanie = 3
	tom = 2
	local pattern
	if mw.ustring.find(nameparts[1], ' Часть ') then pattern = "[Чч]асть (%d)" else pattern = "[Тт]ом (%d)" end
	for tn in mw.ustring.gmatch (nameparts[1], pattern) do tom = tn end
	-- local tom = tonumber(tomcalc(izdanie, t['title']))
	t[izdanie]['tom'] = tom
	t[izdanie]['god'] = god -- t['god_toma'][izdanie][tom]
end
--]==]


return t