Modul:Sort/cellText
Erscheinungsbild
aus Wikipedia, der freien Enzyklopädie
Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus
Dies ist die (produktive) Mutterversion eines global benutzten Lua-Moduls.
Wenn die serial-Information nicht übereinstimmt, müsste eine Kopie hiervon in das lokale Wiki geschrieben werden.
Wenn die serial-Information nicht übereinstimmt, müsste eine Kopie hiervon in das lokale Wiki geschrieben werden.
Versionsbezeichnung auf WikiData:
2024年07月02日localSort={suite="Sort", sub="cellText", serial="2024年07月02日", item=90147626, globals={Sorter=24205172, Cell=90144855, WLink=19363224}} --[=[ Sort/cellText -- support table cells with lexically sortable wikitext ]=] localFailsafe=Sort localGlobalMod=Sort localforeignModule=function(access,advanced,append,alt,alert) -- Fetch global module -- Precondition: -- access -- string, with name of base module -- advanced -- true, for require(); else mw.loadData() -- append -- string, with subpage part, if any; or false -- alt -- number, of wikidata item of root; or false -- alert -- true, for throwing error on data problem -- Postcondition: -- Returns whatever, probably table -- 2020年01月01日 localstorage=access localfiner=function() ifappendthen storage=string.format("%s/%s", storage, append) end end localfun,lucky,r,suited ifadvancedthen fun=require else fun=mw.loadData end GlobalMod.globalModules=GlobalMod.globalModulesor{} suited=GlobalMod.globalModules[access] ifnotsuitedthen finer() lucky,r=pcall(fun,"Module:"..storage) end ifnotluckythen ifnotsuitedand type(alt)=="number"and alt>0then suited=string.format("Q%d",alt) suited=mw.wikibase.getSitelink(suited) GlobalMod.globalModules[access]=suitedortrue end iftype(suited)=="string"then storage=suited finer() lucky,r=pcall(fun,storage) end ifnotluckyandalertthen error("Missing or invalid page: "..storage) end end returnr end-- foreignModule() localfetch=function(access,append) -- Fetch global library -- Precondition: -- access -- string|false, with name of base module -- append -- string, with subpage part, if any; or false -- Postcondition: -- library added to Sort object, if available localstore,sub,suite ifaccessthen suite=access store=access else suite=Sort.suite ifappendthen sub=append:lower() store=append else store="Sorter" end end iftype(Sort[store])=="nil"then localbib=foreignModule(suite, true, sub, Sort.globals[store], true) iftype(bib)=="table"and type(bib[suite])=="function"then Sort[store]=bib[suite]()-- MIGRATE = bib() else error(tostring(bib)) end end end-- fetch() localfiat=function(args) -- Execute task -- Parameter: -- args -- table, parameters -- Postcondition: -- Returns string, or expands .cell -- Throws error on failure localr fetch(false,"Cell") iftype(args)=="table"then localpresent=Sort.Cell.first(args,true) Sort.Cell.fair(args,"source",present) ifpresent.sourcethen locals=mw.text.unstrip(present.source) ifs:find("<",1,true)then s=s:gsub("(</?%l[^>]*>)","") end ifs:find("'",1,true)then s=s:gsub("'''(.+)'''","%1") :gsub("''(.+)''","%1") end ifs:find("[",1,true)then fetch("WLink") s=Sort.WLink.getPlain(s) end s=mw.text.decode(s) s=mw.ustring.gsub(s,mw.ustring.char(160)," ") s=mw.text.trim(s) s=mw.ustring.gsub(s,"%s+"," ") ifs~=""then r=present.source fetch() s=Sort.Sorter.lex(s,"latin") ifs~=rorpresent.prethen Sort.Cell.faced(present,s) end ifpresent.prethen r=Sort.Cell.fore(present.pre,"-",r) end r=Sort.Cell.finalize(present,r) end end ifnotrthen r=Sort.Cell.fault("?????",present) end else error("'args' is not a table") end returnr end-- fiat() Sort.f=function(args) -- Create table cell start or equip table cell object -- Parameter: -- Parameter: -- args -- table, parameters -- .source -- string, with sortable wikitext -- .pre -- string, with preceding wikitext -- .cell -- table|nil, sort environment -- .rowspan -- number|string, for cell attribute -- .colspan -- number|string, for cell attribute -- .class -- string, for cell attribute -- .style -- string|table, for cell attribute -- .id -- string, for cell attribute -- .lang -- string, for cell attribute -- .dir -- string, for cell attribute -- .cat -- string|nil, for error category -- Postcondition: -- Returns string, or expands .cell locallucky,r=pcall(fiat,args) ifnotluckythen locale=mw.html.create("span") :addClass("error") :wikitext("Module:Sort/cell * "..r) iftype(args.cell)=="table"and type(args.cell.wikitext)=="function"then args.cell:node(e) else r=tostring(e) end end returnr end-- Sort.f() Failsafe.failsafe=function(atleast) -- Retrieve versioning and check for compliance -- Precondition: -- atleast -- string, with required version -- or wikidata|item|~|@ or false -- Postcondition: -- Returns string -- with queried version/item, also if problem -- false -- if appropriate -- 2024年03月01日 localsince=atleast locallast=(since=="~") locallinked=(since=="@") locallink=(since=="item") localr iflastorlinkorlinkedorsince=="wikidata"then localitem=Failsafe.item since=false iftype(item)=="number"anditem>0then localsuited=string.format("Q%d",item) iflinkthen r=suited else localentity=mw.wikibase.getEntity(suited) iftype(entity)=="table"then localseek=Failsafe.serialPropertyor"P348" localvsn=entity:formatPropertyValues(seek) iftype(vsn)=="table"and type(vsn.value)=="string"and vsn.value~=""then iflastandvsn.value==Failsafe.serialthen r=false elseiflinkedthen ifmw.title.getCurrentTitle().prefixedText ==mw.wikibase.getSitelink(suited)then r=false else r=suited end else r=vsn.value end end end end elseiflinkthen r=false end end iftype(r)=="nil"then ifnotsinceorsince<=Failsafe.serialthen r=Failsafe.serial else r=false end end returnr end-- Failsafe.failsafe() -- Export localp={} p.f=function(frame) -- Template call Sort.frame=frame returnSort.f(frame.args)or"" end-- p.f p.failsafe=function(frame) -- Versioning interface locals=type(frame) localsince ifs=="table"then since=frame.args[1] elseifs=="string"then since=frame end ifsincethen since=mw.text.trim(since) ifsince==""then since=false end end returnFailsafe.failsafe(since)or"" end-- p.failsafe p.Sort=function() -- Module interface returnSort end setmetatable(p,{__call=function(func,...) setmetatable(p,nil) returnFailsafe end}) returnp