Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Description: Difference between revisions

From Neodyland Wiki
No edit summary
code cleanup
 
(32 intermediate revisions by the same user not shown)
Line 17: Line 17:
local p = {}
local p = {}


function p.langWrapper(text, textLang, inline)
------------------------------------------------------------------------------
-- code equivalent to https://commons.wikimedia.org/wiki/Template:Description
local function missing_text_error(args)
local wordsep  = mw.message.new( "Word-separator" ):inLanguage(textLang):plain()
-- Empty text field -> display error message and add maintenance category
local LangName = mw.language.fetchLanguageName( textLang, textLang)
-- <span class="plainlinks">[{{fullurl:Category:Language templates with no text displayed}} <span class="error">{{Description/i18n}}</span>]</span>
local language = mw.language.new( textLang )
local cat = 'Category:Language templates with no text displayed'
local dir      = language:getDir() 
local msg  = core.formatMessage('I18n/DescriptionError.tab', 'missing text', args.user_lang)
local ltag = mw.html.create('span') -- bold language name string
local frame = mw.getCurrentFrame()
:addClass('language '..textLang) -- classes: "language" and "en", "de" etc.
msg = mw.html.create('span'):addClass("error"):wikitext(msg)
:cssText(core.yesno(inline) and 'display:inline' or nil)
msg = '[' .. frame:callParserFunction{ name = 'fullurl', args={cat} }  .. tostring(msg) .. ']'
:wikitext('<b>' .. language:ucfirst(LangName)..':</b>')
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
desc = core.langWrapper(args.text_lang, tostring(msg), args)
-- mw-content-rtl and mw-content-ltr are defined in (?)
local namespace = mw.title.getCurrentTitle().namespace
-- https://gerrit.wikimedia.org/g/mediawiki/core/+/3825c4d04d9d9701ac04bb3bc6a2f2ca43253d10/resources/src/mediawiki.skinning/content.css
local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
local dtag = mw.html.create('div')
if LUT[namespace]==1 then
:addClass('description') -- div.description is tracked by mw:Extension:CommonsMetadata
desc = desc .. '[[' .. cat .. ']]'
:addClass('mw-content-'..dir) -- div.description is tracked by mw:Extension:CommonsMetadata
end
:addClass(textLang)
return desc
:attr('dir', dir)
:attr('lang', textLang)
:wikitext(tostring(ltag) .. wordsep .. text)
return tostring(dtag)
end
end


------------------------------------------------------------------------------
function p.description(frame)  
function p.description(frame)  
local args = core.getArgs(frame)
local args = core.getArgs(frame)
local desc = p.langWrapper(args.text, args.lang, args.inline)
args.user_lang = args.user_lang or args.lang -- core.getArgs sets args.lang
if args.text == nil then -- if no string than add error message and a category
if args.text == nil then -- if no string than add error message and a category
local cat = 'Category:Language templates with no text displayed'
return missing_text_error(args)  
local msg  = core.formatMessage('I18n/DescriptionError.tab', 'missing text', lang)
else
msg = mw.html.create('span'):addClass("error"):wikitext(msg)
return core.langWrapper(args.text_lang, args.text, args)
msg = '[{{fullurl:' .. cat .. '}} ' .. tostring(msg) .. ']'
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
local desc = p.langWrapper(msg, args.lang, args.inline)
local namespace = mw.title.getCurrentTitle().namespace
local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
if LUT[namespace]==1 then
desc = desc .. '[[' .. cat .. ']]'
end
end
end
return desc
end
end


return p
return p

Latest revision as of 19:55, 11 May 2022

Module documentation[ create · purge ]
This documentation is transcluded from Module:Description/doc.
--[[  
  __  __           _       _        ____                      _       _   _             
 |  \/  | ___   __| |_   _| | ___ _|  _ \  ___  ___  ___ _ __(_)_ __ | |_(_) ___  _ __  
 | |\/| |/ _ \ / _` | | | | |/ _ (_) | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \ 
 | |  | | (_) | (_| | |_| | |  __/_| |_| |  __/\__ \ (__| |  | | |_) | |_| | (_) | | | |
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)____/ \___||___/\___|_|  |_| .__/ \__|_|\___/|_| |_|
                                                               |_|                      

Description is a module implementing functionality of {{Description}}
template, which is used by {{en}}, {{de}} and other language templates.

Authors and maintainers:
* User:Jarekt  
]]

local core = require('Module:Core')
local p = {}

------------------------------------------------------------------------------
local function missing_text_error(args) 
	-- Empty text field -> display error message and add maintenance category
	-- <span class="plainlinks">[{{fullurl:Category:Language templates with no text displayed}} <span class="error">{{Description/i18n}}</span>]</span>
	local cat = 'Category:Language templates with no text displayed'
	local msg  = core.formatMessage('I18n/DescriptionError.tab', 'missing text', args.user_lang)
	local frame = mw.getCurrentFrame()
	msg = mw.html.create('span'):addClass("error"):wikitext(msg)
	msg = '[' .. frame:callParserFunction{ name = 'fullurl', args={cat} }  .. tostring(msg) .. ']'
	msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
	desc = core.langWrapper(args.text_lang, tostring(msg), args)
	local namespace = mw.title.getCurrentTitle().namespace
	local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
	if LUT[namespace]==1 then
		desc = desc .. '[[' .. cat .. ']]'
	end
	return desc
end

------------------------------------------------------------------------------
function p.description(frame) 
	local args = core.getArgs(frame)
	args.user_lang = args.user_lang or args.lang -- core.getArgs sets args.lang
	if args.text == nil then -- if no string than add error message and a category
		return missing_text_error(args) 
	else
		return core.langWrapper(args.text_lang, args.text, args)
	end
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.