Modul:Text: Unterschied zwischen den Versionen

2019-11-12
w>PerfektesChaos
(Änderung 192539285 von Doc Taxon rückgängig gemacht; kein Konsens; Fehlfunktion bewirkt. Bitte erstmal WD:ZR oder WD:TYP aufsuchen; bekannt ist die vorangegangene Diskusion in der VWS. In jedem Fall unsinnig ist die Forderung nach Satzendezeichen hinter einer öffnenden runden Klammer.)
(2019-11-12)
Zeile 1: Zeile 1:
local Text = { serial = "2018-11-14",
local Text = { serial = "2019-11-12",
               suite  = "Text" }
               suite  = "Text",
              item  = 29387871 }
--[=[
--[=[
Text utilities
Text utilities
]=]
]=]
 
local Failsafe  = Text
 
local GlobalMod = Text


-- local globals
-- local globals
Zeile 14: Zeile 15:
local RangesLatin      = false
local RangesLatin      = false
local SeekQuote        = false
local SeekQuote        = false
local foreignModule = 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
    -- 2019-10-29
    local storage = access
    local finer = function ()
                      if append then
                          storage = string.format( "%s/%s",
                                                  storage,
                                                  append )
                      end
                  end
    local fun, lucky, r, suited
    if advanced then
        fun = require
    else
        fun = mw.loadData
    end
    GlobalMod.globalModules = GlobalMod.globalModules or { }
    suited = GlobalMod.globalModules[ access ]
    if not suited then
        finer()
        lucky, r = pcall( fun,  "Module:" .. storage )
    end
    if not lucky then
        if not suited  and
          type( alt ) == "number"  and
          alt > 0 then
            suited = string.format( "Q%d", alt )
            suited = mw.wikibase.getSitelink( suited )
            GlobalMod.globalModules[ access ] = suited or true
        end
        if type( suited ) == "string" then
            storage = suited
            finer()
            lucky, r = pcall( fun, storage )
        end
        if not lucky and alert then
            error( "Missing or invalid page: " .. storage, 0 )
        end
    end
    return r
end -- foreignModule()




Zeile 20: Zeile 74:
     -- Create quote definitions
     -- Create quote definitions
     if not Text.quoteLang then
     if not Text.quoteLang then
         local lucky, quoting = pcall( mw.loadData,
         local quoting = foreignModule( "Text",
                                      "Module:Text/quoting" )
                                      false,
                                      "quoting",
                                      Text.item )
         if type( quoting ) == "table" then
         if type( quoting ) == "table" then
             Text.quoteLang = quoting.langs
             Text.quoteLang = quoting.langs
Zeile 180: Zeile 236:
     -- Returns: true, if CJK detected
     -- Returns: true, if CJK detected
     local r
     local r
     if not patternCJK then
     if not PatternCJK then
         patternCJK = mw.ustring.char( 91,
         PatternCJK = mw.ustring.char( 91,
                                       13312, 45,  40959,
                                       13312, 45,  40959,
                                       131072, 45, 178207,
                                       131072, 45, 178207,
                                       93 )
                                       93 )
     end
     end
     if mw.ustring.find( analyse, patternCJK ) then
     if mw.ustring.find( analyse, PatternCJK ) then
         r = true
         r = true
     else
     else
Zeile 217: Zeile 273:
         :gsub( "''(.+)''", "%1" )
         :gsub( "''(.+)''", "%1" )
         :gsub( " ", " " )
         :gsub( " ", " " )
     return r
     return mw.text.unstrip( r )
end -- Text.getPlain()
end -- Text.getPlain()


Zeile 390: Zeile 446:
     --    analyse  -- string
     --    analyse  -- string
     -- Returns: true, if sentence terminated
     -- Returns: true, if sentence terminated
     local r
     local r = mw.text.trim( analyse )
     if not PatternTerminated then
     if not PatternTerminated then
         PatternTerminated = mw.ustring.char( 91,
         PatternTerminated = mw.ustring.char( 91,
Zeile 399: Zeile 455:
                             .. "!%.%?…][\"'%]‹›«»‘’“”]*$"
                             .. "!%.%?…][\"'%]‹›«»‘’“”]*$"
     end
     end
     if mw.ustring.find( analyse, PatternTerminated ) then
     if mw.ustring.find( r, PatternTerminated ) then
         r = true
         r = true
     else
     else
Zeile 554: Zeile 610:
     return r
     return r
end -- Text.uprightNonlatin()
end -- Text.uprightNonlatin()
Failsafe.failsafe = function ( atleast )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    atleast  -- string, with required version or "wikidata" or "~"
    --                or false
    -- Postcondition:
    --    Returns  string  -- with queried version, also if problem
    --              false  -- if appropriate
    -- 2019-10-15
    local last  = ( atleast == "~" )
    local since = atleast
    local r
    if last  or  since == "wikidata" then
        local item = Failsafe.item
        since = false
        if type( item ) == "number"  and  item > 0 then
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
                                                                item ) )
            if type( entity ) == "table" then
                local seek = Failsafe.serialProperty or "P348"
                local vsn  = entity:formatPropertyValues( seek )
                if type( vsn ) == "table"  and
                  type( vsn.value ) == "string"  and
                  vsn.value ~= "" then
                    if last  and  vsn.value == Failsafe.serial then
                        r = false
                    else
                        r = vsn.value
                    end
                end
            end
        end
    end
    if type( r ) == "nil" then
        if not since  or  since <= Failsafe.serial then
            r = Failsafe.serial
        else
            r = false
        end
    end
    return r
end -- Failsafe.failsafe()




Zeile 784: Zeile 885:




function p.failsafe()
p.failsafe = function ( frame )
     return Text.serial
    -- Versioning interface
end
    local s = type( frame )
    local since
    if s == "table" then
        since = frame.args[ 1 ]
    elseif s == "string" then
        since = frame
    end
    if since then
        since = mw.text.trim( since )
        if since == "" then
            since = false
        end
    end
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()




Anonymer Benutzer