Module:utilities
Appearance
- De neikommendedokumintaasjestiet opModule:utilities/dokumintaasje.[bewurkje]
Oernommen fanen:Module:utilities.
Oerset:
- foutmeldingen
- nammeromten
Oanpast:
- efterheaksel fan in kategorynamme
localexport={}
localdata=mw.loadData("Module:utilities/data")
localnotneeded=data.notneeded
localneededhassubpage=data.neededhassubpage
-- A helper function to escape magic characters in a string
-- Magic characters: ^$()%.[]*+-?
functionexport.pattern_escape(text)
iftype(text)=="table"then
text=text.args[1]
end
text=mw.ustring.gsub(text,"([%^$()%%.%[%]*+%-?])","%%%1")
returntext
end
functionexport.plain_gsub(text,pattern,replacement)
localinvoked=false
iftype(text)=="table"then
invoked=true
iftext.argsthen
localframe=text
localparams={
[1]={},
[2]={},
[3]={allow_empty=true},
}
localargs=require("Module:parameters").process(frame.args,params)
text=args[1]
pattern=args[2]
replacement=args[3]
else
error("At it earste argumint foar plain_gsub in tabel is, moat it in frameobjekt wêze.")
end
else
ifnot(type(pattern)=="string"ortype(pattern)=="number")then
error("It twadde argumint foar plain_gsub moat in tekenrige of in getal wêze.")
end
ifnot(type(replacement)=="string"ortype(replacement)=="number")then
error("It tredde argumint foar plain_gsub moat in tekenrige of in getal wêze.")
end
end
pattern=export.pattern_escape(pattern)
ifinvokedthen
text=mw.ustring.gsub(text,pattern,replacement)
returntext
else
returnmw.ustring.gsub(text,pattern,replacement)
end
end
--[[
Format the categories with the appropriate sort key. CATEGORIES is a list of
categories.
-- LANG is an object encapsulating a language; if nil, the object for
language code 'und' (undetermined) will be used.
-- SORT_KEY is placed in the category invocation, and indicates how the
page will sort in the respective category. Normally this should be nil,
and a default sort key based on the subpage name (the part after the
colon) will be used.
-- SORT_BASE lets you override the default sort key used when SORT_KEY is
nil. Normally, this should be nil, and a language-specific default sort
key is computed from the subpage name (e.g. for Russian this converts
Cyrillic ё to a string consisting of Cyrillic е followed by U+10FFFF,
so that effectively ё sorts after е instead of the default Wikimedia
sort, which (I think) is based on Unicode sort order and puts ё after я,
the last letter of the Cyrillic Alpha bet.
-- FORCE_OUTPUT forces normal output in all namespaces. Normally, nothing
is output if the page isn't in the main, Appendix:, Reconstruction: or
Citations: namespaces.
]]
functionexport.format_categories(categories,lang,sort_key,sort_base,force_output,sc)
localNAMESPACE=mw.title.getCurrentTitle().nsText
iftype(lang)=="table"andnotlang.getCodethen
error("It twadde argumint foar format_categories moat in taalobjekt wêze.")
end
ifforce_outputordata.allowedNamespaces[NAMESPACE]then
localPAGENAME=mw.title.getCurrentTitle().text
localSUBPAGENAME=mw.title.getCurrentTitle().subpageText
ifnotlangthen
lang=require("Module:languages").getByCode("und")
end
-- Generate a default sort key
sort_base=lang:makeSortKey(sort_baseorSUBPAGENAME,sc)
ifsort_keyandsort_key~=""then
-- Gather some statistics regarding sort keys
ifmw.ustring.upper(sort_key)==sort_basethen
table.insert(categories,"Sort key tracking/redundant")
end
else
sort_key=sort_base
end
--[[ If the resulting key is the same as the wiki software's
default, or if the sortkey is empty, remove it ]]
ifsort_key==PAGENAMEorsort_key==""then
sort_key=nil
end
localout_categories={}
forkey,catinipairs(categories)do
out_categories[key]="[[Kategory:"..cat..(sort_keyand"|"..sort_keyor"").."]]"
end
returntable.concat(out_categories,"")
else
return""
end
end
-- Used by {{categorize}}
functionexport.template_categorize(frame)
localNAMESPACE=mw.title.getCurrentTitle().nsText
localformat=frame.args["format"]
localargs=frame:getParent().args
locallangcode=args[1];iflangcode==""thenlangcode=nilend
localsort_key=args["sort"];ifsort_key==""thensort_key=nilend
localcategories={}
ifnotlangcodethen
ifNAMESPACE=="Berjocht"thenreturn""end
error("Taalkoade is net opjûn. Set a.j.w. parameter 1 yn it berjocht.")
end
locallang=require("Module:languages").getByCode(langcode)
ifnotlangthen
ifNAMESPACE=="Berjocht"thenreturn""end
error("De taalkoade\ ""..langcode.."\ "is net jildich. ")
end
localprefix,suffix="",""
ifformat=="pos"then
suffix="yn it"..lang:getCanonicalName()
elseifformat=="topic"then
prefix=lang:getCode()..":"
end
locali=2
localcat=args[i]
whilecatdo
ifcat~=""then
table.insert(categories,prefix..cat..suffix)
end
i=i+1
cat=args[i]
end
returnexport.format_categories(categories,lang,sort_key)
end
functionexport.catfix(lang,sc)
ifnotlangthen
require("Module:debug").track("catfix/no lang")
returnnil
elseiftype(lang)~="table"then
require("Module:debug").track("catfix/lang not table")
returnnil
end
localcanonicalName=lang:getCanonicalName()orerror('It earste argumint foar de funksje "catfix" moat in taalobjekt fan Module:languages wêze.')
ifscandnotsc.getCodethen
error('It twadde argumint foar de funksje "catfix" moat in skriftobjekt fan Module:scripts wêze.')
end
-- To add script classes to links on pages created by category boilerplate templates.
ifnotscthen
sc=data.catfix_scripts[lang:getCode()]
ifscthen
sc=require("Module:scripts").getByCode(sc)
end
end
return"<span id=\ "catfix\ "style=\ "display:none;\ "class=\ "CATFIX- "..mw.uri.anchorEncode(canonicalName).."\ "> "..
require("Module:script utilities").tag_text("",lang,sc,nil)..
"</span>"
end
functionexport.catfix_template(frame)
localparams={
[1]={},
[2]={alias_of="sc"},
["sc"]={},
}
localargs=require("Module:parameters").process(frame:getParent().args,params)
locallang=require("Module:languages").getByCode(args[1])orrequire("Module:languages").err(args[1],1)
localsc=args.sc
ifscthen
sc=require("Module:scripts").getByCode(sc)orerror('De skriftkoade "'..sc..' ", jûn yn de twadde parameter, is net jildich.')
end
returnexport.catfix(lang,sc)
end
-- Not exporting because it is not used yet.
localfunctiongetDateTense(frame)
localname_num_mapping={["January"]=1,["February"]=2,["March"]=3,["April"]=4,["May"]=5,["June"]=6,
["July"]=7,["August"]=8,["September"]=9,["October"]=10,["November"]=11,["December"]=12,
[1]=1,[2]=2,[3]=3,[4]=4,[5]=5,[6]=6,[7]=7,[8]=8,[9]=9,[10]=10,[11]=11,[12]=12}
localmonth=name_num_mapping[frame.args[2]]
localdate=os.time({year=frame.args[1],day=frame.args[3],month=month})
localtoday=os.time()-- 12 AM/PM
localdiff=os.difftime(date,today)
localdaylength=24*3600
ifdiff<-daylength/2thenreturn"past"
else
ifdiff>daylength/2thenreturn"future"
elsereturn"present"end
end
end
functionexport.make_id(lang,str)
--[[ If called with invoke, first argument is a frame object.
If called by a module, first argument is a language object. ]]
localinvoked=false
iftype(lang)=="table"then
iflang.argsthen
invoked=true
localframe=lang
localparams={
[1]={},
[2]={},
}
localargs=require("Module:parameters").process(frame:getParent().args,params)
locallangCode=args[1]
str=args[2]
localm_languages=require("Module:languages")
lang=m_languages.getByCode(langCode)orm_languages.err(langCode,1)
elseifnotlang.getCanonicalNamethen
error("It earste argumint foar make_id moat in taalobjekt wêze.")
end
end
ifnot(type(str)=="string"ortype(str)=="number")then
error("It twadde argumint foar make_id moat in tekenrige of in getal wêze.")
end
localcanonicalName=lang:getCanonicalName()
str=mw.uri.encode(str,"WIKI")
localid=canonicalName.."-"..str
ifinvokedthen
return'<li class= "senseid" id= "'..id..' ">'
else
returnid
end
end
returnexport