تعديل وحدة:Wd

اذهب إلى التنقل اذهب إلى البحث

تحذير: أنت غير مسجل الدخول. عنوان الأيبي الخاص بك سيكون معروضا بشكل علني لو قمت بأي تعديلات. لو أنك سجلت الدخول أو أنشأت حسابا، فتعديلاتك ستنسب لاسم المستخدم الخاص بك، بالإضافة إلى فوائد أخرى.

يمكن استرجاع التعديل. تحقق من المقارنة بالأسفل للتأكد من أن هذا هو ما تريد أن تفعله، ثم احفظ التغييرات بالأسفل للانتهاء من استرجاع التعديل.

المراجعة الحالية نصك
سطر 2٬214: سطر 2٬214:
 
return nil
 
return nil
 
end
 
end
end
 
 
local function claimCommand(args, funcName)
 
local cfg = Config:new()
 
cfg:processFlagOrCommand(funcName)  -- process first command (== function name)
 
 
local lastArg, parsedFormat, formatParams, claims, value
 
local hooks = {count = 0}
 
 
-- set the date if given;
 
-- must come BEFORE processing the flags
 
if args[p.args.date] then
 
cfg.atDate = {parseDate(args[p.args.date])}
 
cfg.periods = {false, true, false}  -- change default time constraint to 'current'
 
end
 
 
-- process flags and commands
 
repeat
 
lastArg = nextArg(args)
 
until not cfg:processFlagOrCommand(lastArg)
 
 
-- get the entity ID from either the positional argument, the eid argument or the page argument
 
cfg.entityID, cfg.propertyID = getEntityId(lastArg, args[p.args.eid], args[p.args.page])
 
 
if cfg.entityID == "" then
 
return ""  -- we cannot continue without a valid entity ID
 
end
 
 
cfg.entity = mw.wikibase.getEntity(cfg.entityID)
 
 
if not cfg.propertyID then
 
cfg.propertyID = nextArg(args)
 
end
 
 
cfg.propertyID = replaceAlias(cfg.propertyID)
 
 
if not cfg.entity or not cfg.propertyID then
 
return ""  -- we cannot continue without an entity or a property ID
 
end
 
 
cfg.propertyID = cfg.propertyID:upper()
 
 
if not cfg.entity.claims or not cfg.entity.claims[cfg.propertyID] then
 
return ""  -- there is no use to continue without any claims
 
end
 
 
claims = cfg.entity.claims[cfg.propertyID]
 
 
if cfg.states.qualifiersCount > 0 then
 
-- do further processing if "qualifier(s)" command was given
 
 
if #args - args.pointer + 1 > cfg.states.qualifiersCount then
 
-- claim ID or literal value has been given
 
 
cfg.propertyValue = nextArg(args)
 
end
 
 
for i = 1, cfg.states.qualifiersCount do
 
-- check if given qualifier ID is an alias and add it
 
cfg.qualifierIDs[parameters.qualifier..i] = replaceAlias(nextArg(args) or ""):upper()
 
end
 
elseif cfg.states[parameters.reference] then
 
-- do further processing if "reference(s)" command was given
 
 
cfg.propertyValue = nextArg(args)
 
end
 
 
-- check for special property value 'somevalue' or 'novalue'
 
if cfg.propertyValue then
 
cfg.propertyValue = replaceSpecialChars(cfg.propertyValue)
 
 
if cfg.propertyValue ~= "" and mw.text.trim(cfg.propertyValue) == "" then
 
cfg.propertyValue = " "  -- single space represents 'somevalue', whereas empty string represents 'novalue'
 
else
 
cfg.propertyValue = mw.text.trim(cfg.propertyValue)
 
end
 
end
 
 
-- parse the desired format, or choose an appropriate format
 
if args["format"] then
 
parsedFormat, formatParams = parseFormat(args["format"])
 
elseif cfg.states.qualifiersCount > 0 then  -- "qualifier(s)" command given
 
if cfg.states[parameters.property] then  -- "propert(y|ies)" command given
 
parsedFormat, formatParams = parseFormat(formats.propertyWithQualifier)
 
else
 
parsedFormat, formatParams = parseFormat(formats.qualifier)
 
end
 
elseif cfg.states[parameters.property] then  -- "propert(y|ies)" command given
 
parsedFormat, formatParams = parseFormat(formats.property)
 
else  -- "reference(s)" command given
 
parsedFormat, formatParams = parseFormat(formats.reference)
 
end
 
 
-- if a "qualifier(s)" command and no "propert(y|ies)" command has been given, make the movable separator a semicolon
 
if cfg.states.qualifiersCount > 0 and not cfg.states[parameters.property] then
 
cfg.separators["sep"..parameters.separator][1] = {";"}
 
end
 
 
-- if only "reference(s)" has been given, set the default separator to none (except when raw)
 
if cfg.states[parameters.reference] and not cfg.states[parameters.property] and cfg.states.qualifiersCount == 0
 
  and not cfg.states[parameters.reference].rawValue then
 
cfg.separators["sep"][1] = nil
 
end
 
 
-- if exactly one "qualifier(s)" command has been given, make "sep%q" point to "sep%q1" to make them equivalent
 
if cfg.states.qualifiersCount == 1 then
 
cfg.separators["sep"..parameters.qualifier] = cfg.separators["sep"..parameters.qualifier.."1"]
 
end
 
 
-- process overridden separator values;
 
-- must come AFTER tweaking the default separators
 
cfg:processSeparators(args)
 
 
-- define the hooks that should be called (getProperty, getQualifiers, getReferences);
 
-- only define a hook if both its command ("propert(y|ies)", "reference(s)", "qualifier(s)") and its parameter ("%p", "%r", "%q1", "%q2", "%q3") have been given
 
for i, v in pairs(cfg.states) do
 
-- e.g. 'formatParams["%q1"] or formatParams["%q"]' to define hook even if "%q1" was not defined to be able to build a complete value for "%q"
 
if formatParams[i] or formatParams[i:sub(1, 2)] then
 
hooks[i] = getHookName(i, 1)
 
hooks.count = hooks.count + 1
 
end
 
end
 
 
-- the "%q" parameter is not attached to a state, but is a collection of the results of multiple states (attached to "%q1", "%q2", "%q3", ...);
 
-- so if this parameter is given then this hook must be defined separately, but only if at least one "qualifier(s)" command has been given
 
if formatParams[parameters.qualifier] and cfg.states.qualifiersCount > 0 then
 
hooks[parameters.qualifier] = getHookName(parameters.qualifier, 1)
 
hooks.count = hooks.count + 1
 
end
 
 
-- create a state for "properties" if it doesn't exist yet, which will be used as a base configuration for each claim iteration;
 
-- must come AFTER defining the hooks
 
if not cfg.states[parameters.property] then
 
cfg.states[parameters.property] = State:new(cfg, parameters.property)
 
 
-- if the "single" flag has been given then this state should be equivalent to "property" (singular)
 
if cfg.singleClaim then
 
cfg.states[parameters.property].singleValue = true
 
end
 
end
 
 
-- if the "sourced" flag has been given then create a state for "reference" if it doesn't exist yet, using default values,
 
-- which must exist in order to be able to determine if a claim has any references;
 
-- must come AFTER defining the hooks
 
if cfg.sourcedOnly and not cfg.states[parameters.reference] then
 
cfg:processFlagOrCommand(p.claimCommands.reference)  -- use singular "reference" to minimize overhead
 
end
 
 
-- set the parsed format and the separators (and optional punctuation mark);
 
-- must come AFTER creating the additonal states
 
cfg:setFormatAndSeparators(cfg.states[parameters.property], parsedFormat)
 
 
-- process qualifier matching values, analogous to cfg.propertyValue
 
for i, v in pairs(args) do
 
i = tostring(i)
 
 
if i:match('^[Pp]%d+$') or aliasesP[i] then
 
v = replaceSpecialChars(v)
 
 
-- check for special qualifier value 'somevalue'
 
if v ~= "" and mw.text.trim(v) == "" then
 
v = " "  -- single space represents 'somevalue'
 
end
 
 
cfg.qualifierIDsAndValues[replaceAlias(i):upper()] = v
 
end
 
end
 
 
-- first sort the claims on rank to pre-define the order of output (preferred first, then normal, then deprecated)
 
claims = sortOnRank(claims)
 
 
-- then iterate through the claims to collect values
 
value = cfg:concatValues(cfg.states[parameters.property]:iterate(claims, hooks, State.claimMatches))  -- pass property state with level 1 hooks and matchHook
 
 
-- if desired, add a clickable icon that may be used to edit the returned values on Wikidata
 
if cfg.editable and value ~= "" then
 
value = value .. cfg:getEditIcon()
 
end
 
 
return value
 
 
end
 
end
  
 
return p
 
return p

من فضلك لاحظ أن جميع المساهمات في موسوعة المزرعة يمكن أن تعدل أو تتغير أو تزال من قبل المساهمين الآخرين. إذا لم تكن ترغب أن تعدل مشاركاتك بهذا الشكل، لا تضعها هنا.
أنت تقر أيضا أنك كتبت هذا بنفسك، أو نسخته من مصدر يخضع للملكية العامة، أو مصدر حر آخر (انظر المزرعة:حقوق التأليف والنشر للتفاصيل). لا تضف أي عمل ذي حقوق محفوظة بدون تصريح!

ألغ مساعدة التحرير (تفتح في نافذة جديدة)

القالب المستخدم في هذه الصفحة: