יחידה:Wikibase-stub
מתוך ויקיפדיה, האנציקלופדיה החופשית
פעולות נוספות
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:Wikibase-stub/תיעוד
-- ==============================================================
-- Module:Wikibase-stub ([Pinkas] — local, self-contained)
-- ==============================================================
-- Drop-in no-op replacement for the mw.wikibase library.
--
-- The Wikibase Client extension is intentionally NOT installed and this
-- wiki never fetches any external (Wikidata/Commons) data. Modules that
-- call mw.wikibase.* receive this stub via a one-line guard prepended to
-- each such module:
--
-- if not mw.wikibase then mw.wikibase = require( 'Module:Wikibase-stub' ) end
--
-- Effect: every Wikidata-backed value resolves to nil / empty, so templates
-- fall back to their locally-supplied parameters and NO red script errors
-- appear. The semantics deliberately mimic "this page has no linked Wikidata
-- item" — a state every well-written Wikidata module already handles:
-- * value / entity / label / sitelink getters -> nil
-- * statement / list getters -> {} (safe for ipairs/#)
-- * existence checks -> false
-- * any other/unknown member (via __index) -> a function returning nil
-- ==============================================================
local function nilfn() return nil end
local function emptyfn() return {} end
local function falsefn() return false end
local wikibase = {
-- entity / id getters
getEntity = nilfn,
getEntityObject = nilfn,
getEntityIdForCurrentPage = nilfn,
getEntityIdForTitle = nilfn,
getEntityUrl = nilfn,
getReferencedEntityId = nilfn,
-- value getters
getBestValue = nilfn,
getBestValues = emptyfn,
getBestStatements = emptyfn,
getAllStatements = emptyfn,
-- labels / descriptions / sitelinks
getLabel = nilfn,
getLabelByLang = nilfn,
getLabelWithLang = nilfn,
getDescription = nilfn,
getDescriptionByLang = nilfn,
getDescriptionWithLang = nilfn,
getSitelink = nilfn,
getBadges = emptyfn,
-- properties / formatting
getPropertyOrder = nilfn,
getPropertyDataType = nilfn,
resolvePropertyId = nilfn,
orderProperties = emptyfn,
renderSnak = nilfn,
renderSnaks = nilfn,
formatValue = nilfn,
formatValues = nilfn,
-- misc
getGlobalSiteId = nilfn,
isValidEntityId = falsefn,
entityExists = falsefn,
}
-- Some modules reach for the entity prototype table (mw.wikibase.entity.*).
-- Give them a table whose members are all no-op functions returning nil.
wikibase.entity = setmetatable( {}, { __index = function() return nilfn end } )
-- Anything not listed above still returns a callable that yields nil,
-- so `mw.wikibase.<anyMethod>( ... )` never indexes a nil value.
return setmetatable( wikibase, { __index = function() return nilfn end } )