Modiwl:Wd: Gwahaniaeth rhwng fersiynau

Cynnwys wedi'i ddileu Cynnwys wedi'i ychwanegu
Janhrach (sgwrs | cyfraniadau)
Updated the module with some code readded from a past revision of enwiki
Tagiau: Golygiad drwy declyn symudol Golygiad ar declun symudol
diweddaru o en
Tagiau: Gwrthdröwyd
Llinell 1:
-- Original module located at [[:en:Module:Wd]] and [[:en:Module:Wd/i18n]].
-- This is a forked version.
 
require("strict")
Llinell 66 ⟶ 65:
eid = "eid",
page = "page",
date = "date",
globalSiteId = "globalSiteId"
}
 
Llinell 100:
column = "P3903",
subjectNamedAs = "P1810",
wikidataProperty = "P1687",
publishedIn = "P1433"
}
 
Llinell 1,801 ⟶ 1,802:
 
-- level 2 hook
-- This function is not identical to the one in enwiki.
function State:getReference(statement)
local key, citeWeb, citeQ, label
Llinell 1,811:
local value = ""
local ref = {}
local referenceEmpty = true -- will be set to false if at least one parameter is left unremoved
local numAuthorParameters = 0
local numAuthorNameStringParameters = 0
local tempLink
local additionalRefProperties = {} -- will hold properties of the reference which are not in statement.snaks, namely backup title from "subject named as" and URLlink from an external ID
local wikidataPropertiesOfSource -- will contain "Wikidata property" properties of the item in stated in, if any
 
local version = 47 -- increment this each time the below logic is changed to avoid conflict errors
 
if statement.snaks then
Llinell 1,858 ⟶ 1,859:
-- "stated in" was given but "reference URL" was not.
-- get "Wikidata property" properties from the item in "stated in"
-- if any of the returned properties of the external-id datatype is in statement.snaks, generate a URLlink from it and use the URLlink in the reference
-- find the "Wikidata property" properties in the item from "stated in"
Llinell 1,866 ⟶ 1,867:
tempLink = self.conf:getValue(statement.snaks[wikidataPropertyOfSource][1], false, true) -- not raw, linked
if mw.ustring.match(tempLink, "^%[%Z- %Z+%]$") then -- getValue returned a URL.
additionalRefProperties[aliasesP.referenceURL] = mw.ustring.gsub(tempLink, "^%[(%Z-) %Z+%]$", "%1") -- the URLlink is in wiki markup, so strip the square brackets and the display text
statement.snaks[wikidataPropertyOfSource] = nil
break
Llinell 1,889 ⟶ 1,890:
if i == aliasesP.author or i == aliasesP.authorNameString then
params[i] = self:getReferenceDetails(statement.snaks, i, false, self.linked, true) -- link = true/false, anyLang = true
elseif params[i == aliasesP.title]statedIn then
-- Get "stated in" raw, as it is wanted (for Cite Q) even if it doesn't have a local language label.
citeParams['q'][i18n['cite']['q'] params[aliasesP.statedIn]] = {self:getReferenceDetail(statement.snaks, aliasesP.statedIn, true)} -- raw = true
else
params[i] = {self:getReferenceDetail(statement.snaks, i, false, (self.linked or (i == aliasesP.statedIn)) and (statement.snaks[i][1].datatype ~= 'url'), true)} -- link = true/false, anyLang = true
end
end
 
if #params[i] == 0 then
params[i] = nil
else
referenceEmpty = false
end
if statement.snaks[i][1].datatype == 'external-id' then
key = "external-id"
Llinell 1,974 ⟶ 1,980:
citeQ = split(mw.wikibase.getSitelink(aliasesQ.citeQ) or "", ":")[2] -- split off namespace from front
 
-- (1) use the general template for citing web references if there is a match and if at least both "reference URL" and "title" areis present
if citeWeb and not citeMismatch['web'] and citeParams['web'][i18n['cite']['web'][aliasesP.referenceURL]] and citeParams['web'][i18n['cite']['web'][aliasesP.title]] then
-- we need thea rawprocessed "stated in" Q-identifier for the this template
citeParams['web'][i18n['cite']['web'][aliasesP.statedIn]] = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, false, self.linked, true)
useCite = citeWeb
useParams = citeParams['web']
Llinell 1,981 ⟶ 1,989:
-- (2) use the template that expands stated-in references into citations if there is a match and if at least "stated in" is present
elseif citeQ and not citeMismatch['q'] and citeParams['q'][i18n['cite']['q'][aliasesP.statedIn]] then
-- we need the raw "stated in" Q-identifier for the this template
citeParams['q'][i18n['cite']['q'][aliasesP.statedIn]] = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, true) -- raw = true
 
useCite = citeQ
useParams = citeParams['q']
Llinell 2,000 ⟶ 2,005:
end
 
-- (3) if the citation couldn't be displayed using Cite web or Cite Q, but has properties other than the removed ones, throw an error
-- The following code was readded to cywiki from the revision 1142771233 of enwiki.
elseif not referenceEmpty then
-- (3) else, do some default rendering of name-value pairs, but only if at least "stated in", "reference URL" or "title" is present
value = "<span style=\"color:#dd3333\">" .. errorText("malformed-reference") .. "</span>"
elseif params[aliasesP.statedIn] or params[aliasesP.referenceURL] or params[aliasesP.title] then
citeParams['default'] = {}
 
-- start by adding authors up front
if params[aliasesP.author] and #params[aliasesP.author] > 0 then
citeParams['default'][#citeParams['default'] + 1] = table.concat(params[aliasesP.author], "; ")
end
 
-- add authors from "author name string" to the same element as the authors from "author"
if params[aliasesP.authorNameString] and #params[aliasesP.authorNameString] > 0 then
citeParams['default'][#citeParams['default']] = citeParams['default'][#citeParams['default']] .. "; " .. table.concat(params[aliasesP.authorNameString], "; ")
end
 
-- combine "reference URL" and "title" into one link if both are present
if params[aliasesP.referenceURL] and params[aliasesP.title] then
citeParams['default'][#citeParams['default'] + 1] = '[' .. params[aliasesP.referenceURL][1] .. ' "' .. params[aliasesP.title][1] .. '"]'
elseif params[aliasesP.referenceURL] then
citeParams['default'][#citeParams['default'] + 1] = params[aliasesP.referenceURL][1]
elseif params[aliasesP.title] then
citeParams['default'][#citeParams['default'] + 1] = '"' .. params[aliasesP.title][1] .. '"'
end
 
-- then add "stated in"
if params[aliasesP.statedIn] then
citeParams['default'][#citeParams['default'] + 1] = "''" .. params[aliasesP.statedIn][1] .. "''"
end
 
-- remove previously added parameters so that they won't be added a second time
params[aliasesP.author] = nil
params[aliasesP.authorNameString] = nil
params[aliasesP.referenceURL] = nil
params[aliasesP.title] = nil
params[aliasesP.statedIn] = nil
 
-- add the rest of the parameters
for i, v in pairs(params) do
i = self.conf:getLabel(i)
 
if i ~= "" then
citeParams['default'][#citeParams['default'] + 1] = i .. ": " .. v[1]
end
end
 
value = table.concat(citeParams['default'], ". ")
 
if value ~= "" then
value = value .. "."
end
end
Llinell 2,246 ⟶ 2,204:
end
 
local function getEntityId(arg, eid, page, allowOmitPropPrefix, globalSiteId)
local id = nil
local prop = nil
Llinell 2,277 ⟶ 2,235:
end
 
id = mw.wikibase.getEntityIdForTitle(page, globalSiteId) or ""
end
 
Llinell 2,324 ⟶ 2,282:
 
-- 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], false, args[p.args.globalSiteId])
 
if cfg.entityID == "" then
Llinell 2,496 ⟶ 2,454:
 
-- get the entity ID from either the positional argument, the eid argument or the page argument
cfg.entityID = getEntityId(lastArg, args[p.args.eid], args[p.args.page], true, args[p.args.globalSiteId])
 
if cfg.entityID == "" or not mw.wikibase.entityExists(cfg.entityID) then