Изменения

Перейти к навигации Перейти к поиску
м
Нет описания правки
Строка 119: Строка 119:  
-- Where 'userparam' consist of all the parameters that can not be fetched by symantic property:
 
-- Where 'userparam' consist of all the parameters that can not be fetched by symantic property:
 
-- * text = text to show; generally it is the original text of request - term or name
 
-- * text = text to show; generally it is the original text of request - term or name
-- * view = style of displaying information: подсказка, сноска, скобки, текст
+
-- * view = style of displaying information in any combination: подсказка, сноска, скобки
 
-- * type = type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
 
-- * type = type of term: понятие (по умолчанию), личность, выражение, литература, периодика / conception, person, expression, literature, periodical
-- * style= серый / gray
+
-- * style = серый, оригинал, описание
 
-- * specification = уточнение к литературному источнику: том, страница, глава и т.п.
 
-- * specification = уточнение к литературному источнику: том, страница, глава и т.п.
 
-- View, type and style are language dependent parameters, consider changes in code below.
 
-- View, type and style are language dependent parameters, consider changes in code below.
 
-- TODO: Всплывающую подсказку сделать вики текстом и добавить ссылку [[{{{БТС статья}}}|БТС]]  
 
-- TODO: Всплывающую подсказку сделать вики текстом и добавить ссылку [[{{{БТС статья}}}|БТС]]  
 
function ctd.info( frame )
 
function ctd.info( frame )
local term = ''
+
local term = '' -- term in simple form, as a title in dictionary = wiki page title (most likely)
local term_to_show = ''
+
local term_with_link = '' -- term with a link to wiki page
 +
local term_without_link = ''-- term without a link, but with diacritical marks
 
local reference = ''
 
local reference = ''
 
local description = ''
 
local description = ''
 
local origin = ''
 
local origin = ''
local lifetime = '' -- comment: date  
+
local lifetime = '' -- date with title
 
local lifetime_short = ''  -- just date
 
local lifetime_short = ''  -- just date
 
local term_link = ''
 
local term_link = ''
 
local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
 
local ctd_title = '<span style="border-bottom: 1px dotted gray; cursor:help;" title="Большой теософский словарь">БТС</span>'
+
local output_str = '' -- result string to show
-- split 'text@view' value of parameter 'userparam' in two variables
+
-- variables for 'view' parameter
--local i, j = string.find(frame.args['userparam'],'@',1,true)
+
local view_popup, view_footnote, view_brackets = false
--local text = string.sub(frame.args['userparam'], 1, i-1)
+
-- variables for 'style' parameter
--local view = string.sub( string.lower(frame.args['userparam']), j+1 )
+
local font_grey      = false  -- make font grey
 +
local add_origin      = false  -- add information on origin
 +
local add_description = false  -- add short description
 +
 
 
-- split 'userparam' in variables
 
-- split 'userparam' in variables
--local t = split_string(frame.args['userparam'],'@')
   
local t = mw.text.split(frame.args['userparam'],'@')
 
local t = mw.text.split(frame.args['userparam'],'@')
local text_original, view, term_type, style, specification = t[1], t[2], t[3], t[4], t[5]
+
local text, view, term_type, style, specification = t[1], t[2], t[3], t[4], t[5]
local text = text_original
+
local text_original = text -- keep 'text_original' unchanged
if isempty(view) then view = 'подсказка' end
+
-- set default
 +
if isempty(view)     then view     = 'подсказка' end
 
if isempty(term_type) then term_type = 'понятие' end
 
if isempty(term_type) then term_type = 'понятие' end
--if isempty(style) then style = 'серый' end
+
-- parse 'view' for values
 +
if mw.ustring.find(view,'подсказка',1,true) ~= nil then view_popup    = true end
 +
if mw.ustring.find(view,'сноска',1,true)    ~= nil then view_footnote = true end
 +
if mw.ustring.find(view,'скобки',1,true)    ~= nil then view_brackets = true end
 +
-- parse 'style' for values
 +
if mw.ustring.find(style,'серый',1,true)   ~= nil then font_grey      = true end
 +
if mw.ustring.find(style,'оригинал',1,true) ~= nil then add_origin    = true end
 +
if mw.ustring.find(style,'описание',1,true) ~= nil then add_description= true end
    
-- define term to show, i.e. with accent and diacritic
 
-- define term to show, i.e. with accent and diacritic
 
if not isempty(frame.args['term_to_show']) then
 
if not isempty(frame.args['term_to_show']) then
term_to_show = frame.args['term_to_show']
+
term_without_link = frame.args['term_to_show']
 
elseif not isempty(frame.args['term']) then
 
elseif not isempty(frame.args['term']) then
term_to_show = frame.args['term']
+
term_without_link = frame.args['term']
 
else
 
else
term_to_show = text
+
term_without_link = text
 
end
 
end
 
 
Строка 188: Строка 199:  
end
 
end
 
if not isempty(frame.args['origin']) and  
 
if not isempty(frame.args['origin']) and  
  not isempty(frame.args['lifetime']) or not isempty(frame.args['published'])then
+
  ( not isempty(frame.args['lifetime']) or not isempty(frame.args['published']) )then
 
origin = origin .. ', '
 
origin = origin .. ', '
 
end
 
end
Строка 200: Строка 211:     
-- construct lifetime string for pop-up message
 
-- construct lifetime string for pop-up message
if   not isempty(frame.args['lifetime']) then
+
if not isempty(frame.args['lifetime']) then
 
if term_type == 'личность' then
 
if term_type == 'личность' then
 
lifetime = ' Время жизни: '.. frame.args['lifetime']
 
lifetime = ' Время жизни: '.. frame.args['lifetime']
Строка 220: Строка 231:  
 
 
-- set hyperlink if there is a wiki page for a term
 
-- set hyperlink if there is a wiki page for a term
local term_without_link = term_to_show
   
if not isempty(frame.args['wiki_page']) then
 
if not isempty(frame.args['wiki_page']) then
term_to_show = '[['.. frame.args['wiki_page'] ..'|'.. term_to_show ..']]'
+
term_with_link = '[['.. frame.args['wiki_page'] ..'|'.. term_without_link ..']]'
 +
else
 +
term_with_link = term_without_link
 
end
 
end
 
 
-- set author if we deal with literature
+
-- LITERATURE features. Set author  
 
if not isempty(frame.args['author_short']) then
 
if not isempty(frame.args['author_short']) then
term_to_show = frame.args['author_short'] ..', «'.. term_to_show ..'»'
+
term_with_link    = frame.args['author_short'] ..', «'.. term_with_link ..'»'
 
term_without_link = frame.args['author_short'] ..', «'.. term_without_link ..'»'
 
term_without_link = frame.args['author_short'] ..', «'.. term_without_link ..'»'
 
elseif not isempty(frame.args['author']) then
 
elseif not isempty(frame.args['author']) then
term_to_show = frame.args['author'] ..', «'.. term_to_show ..'»'
+
term_with_link    = frame.args['author'] ..', «'.. term_with_link ..'»'
 
term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
 
term_without_link = frame.args['author'] ..', «'.. term_without_link ..'»'
 +
end
 +
-- add publishing date
 +
if term_type == 'литература' then
 +
term_without_link = term_without_link ..', '.. lifetime_short
 
end
 
end
 
-- add volume, chapter, page and so on
 
-- add volume, chapter, page and so on
 
if not isempty(specification) then
 
if not isempty(specification) then
term_to_show = term_to_show ..', '.. specification
+
term_with_link    = term_with_link    ..', '.. specification
 +
term_without_link = term_without_link ..', '.. specification
 
end
 
end
 
 
-- considering TYPE of VIEW
+
-- POPUP message should be added
if view == 'подсказка' or view == 'сноска и подсказка' or view == 'подсказка и сноска' then
+
if view_popup then
local popup_str = description .. lifetime
+
if term_type == 'литература' or term_type == 'личность' then
if term_type == 'литература' then
+
output_str = term_without_link ..', '.. lifetime_short
popup_str = term_without_link ..', '.. lifetime_short
+
else -- для 'понятие' и 'выражение'
elseif term_type == 'литература с оригиналом' then
+
output_str = description
popup_str = term_without_link ..', '.. lifetime_short ..' '.. origin
   
end
 
end
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. popup_str .. ' (БТС, ' .. term .. ').">' .. text .. '</span>'   
+
if add_origin   then output_str = output_str ..' '.. origin end
 +
if add_description then output_str = output_str ..'. – '.. description end
 +
text = '<span style="border-bottom: 1px dotted gray; cursor: help;" title="' .. output_str .. ' (БТС, ' .. term .. ').">' .. text .. '</span>'   
 
end
 
end
 
 
-- вид "сноска" и "текст" одинаковый; второй применяется в случаях, когда сноска указывается вручную, поэтому он повторяет вид "сноска", только без тега <ref>
+
-- FOOTNOTE should be added
if view == 'сноска' or view == 'сноска и подсказка' or view == 'подсказка и сноска'
+
if view_footnote then
  or view == 'текст' then
+
output_str = term_with_link
reference = term_to_show .. origin .. '. – ' .. description .. ' ('.. ctd_title ..').'
+
if add_origin then output_str = output_str ..' '.. origin end
if not isempty(style) then   -- there is only one additional style for now, so ignore the value
+
if add_description then output_str = output_str ..'. – '.. description end
reference = '<span style="color: gray;">' .. reference ..'</span>'
+
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
end
+
text = text ..'<ref>' .. output_str ..' ('.. ctd_title ..').</ref>'
if view ~= 'текст' then
  −
reference = '<ref>' .. reference ..'</ref>'
  −
end
   
end
 
end
 
 
if view == 'скобки' then
+
-- BRACKETS should be added
local comment = description
+
if view_brackets then
+
if term_type == 'литература' or term_type == 'личность' then
if term_type == 'литература' then
+
output_str = term_without_link ..', '.. lifetime_short
comment = term_to_show ..', '.. lifetime_short
+
else -- для 'понятие' и 'выражение'
elseif term_type == 'литература с оригиналом' then
+
output_str = description
comment = term_to_show ..', '.. lifetime_short ..' '.. origin
   
end
 
end
   −
if isempty(style) then
+
if add_origin then output_str = output_str ..' '.. origin end
text = text .. ' [' .. comment .. '.]'
+
if add_description then output_str = output_str ..'. – '.. description end
else
+
output_str = ' [' .. output_str .. '.]'
text = text .. ' <span style="color: gray;">[' .. comment .. '.]</span>'
+
if font_grey then output_str = '<span style="color: gray;">' .. output_str ..'</span>' end
end
+
text = text .. output_str
 
end
 
end
 
 
local final_output = text .. reference
+
-- DEBUG
 +
text = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..' ⇒ font_grey ='.. tostring(font_grey) ..'; add_origin ='.. tostring(add_origin) ..'; add_description ='.. tostring(add_description) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text
 +
return  text
   −
-- DEBUG
+
    --return frame:preprocess( text )
--final_output = 'userparam: '.. frame.args['userparam'] ..'\n- text ='.. text_original ..'\n- view ='.. view ..'\n- type ='.. term_type ..'\n- style ='.. tostring(style) ..'\n- specification ='.. specification ..'\nOUTPUT: '.. text .. reference
  −
--return  final_output
  −
  −
    return frame:preprocess( final_output )
   
end
 
end
    
return ctd
 
return ctd

Навигация