642
回編集
template>Fryed-peach (en:Module:InfoboxImage 2014年8月10日 (日) 07:38 より) |
Triple-Zeta (トーク | 投稿記録) 細 (10版 をインポートしました) |
||
(5人の利用者による、間の6版が非表示) | |||
1行目: | 1行目: | ||
-- Inputs: | -- Inputs: | ||
-- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link | -- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link | ||
-- page - page to display for multipage images (DjVu) | |||
-- size - size to display the image | -- size - size to display the image | ||
-- maxsize - maximum size for image | -- maxsize - maximum size for image | ||
87行目: | 88行目: | ||
"Project Trains no image.png", | "Project Trains no image.png", | ||
"Image-request.png", | "Image-request.png", | ||
"Noimage.gif", | |||
} | } | ||
92行目: | 94行目: | ||
-- change underscores to spaces | -- change underscores to spaces | ||
image = mw.ustring.gsub(image, "_", " "); | image = mw.ustring.gsub(image, "_", " "); | ||
assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil') | |||
-- if image starts with [[ then remove that and anything after | | -- if image starts with [[ then remove that and anything after | | ||
if mw.ustring.sub(image,1,2) == "[[" then | if mw.ustring.sub(image,1,2) == "[[" then | ||
image = mw.ustring.sub(image,3); | image = mw.ustring.sub(image,3); | ||
image = mw.ustring.gsub(image, "([^|]*)|.*", "%1"); | image = mw.ustring.gsub(image, "([^|]*)|.*", "%1"); | ||
assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil') | |||
end | end | ||
-- Trim spaces | -- Trim spaces | ||
image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1'); | image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1'); | ||
assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil") | |||
-- remove prefix if exists | -- remove prefix if exists | ||
local allNames = mw.site.namespaces[6].aliases | local allNames = mw.site.namespaces[6].aliases | ||
160行目: | 165行目: | ||
if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then | if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then | ||
return image .. "[[Category:Infobox内でサムネイル画像を使用しているページ]]"; | return image .. "[[Category:Infobox内でサムネイル画像を使用しているページ]]"; | ||
elseif mw.title.getCurrentTitle().namespace == 0 then | |||
return image .. ""; | |||
else | else | ||
return image; | return image; | ||
168行目: | 175行目: | ||
return image; | return image; | ||
elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then | elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then | ||
-- Found strip marker at begining, so pass don't process at all | |||
return image; | |||
elseif mw.ustring.sub(image,4,9) == "`UNIQ-" then | |||
-- Found strip marker at begining, so pass don't process at all | -- Found strip marker at begining, so pass don't process at all | ||
return image; | return image; | ||
else | else | ||
local result = ""; | local result = ""; | ||
local page = frame.args["page"]; | |||
local size = frame.args["size"]; | local size = frame.args["size"]; | ||
local maxsize = frame.args["maxsize"]; | local maxsize = frame.args["maxsize"]; | ||
211行目: | 222行目: | ||
if (tonumber(size) or 0) > 0 then | if (tonumber(size) or 0) > 0 then | ||
size = size .. "px"; | size = size .. "px"; | ||
end | |||
-- add px to sizedefault if just a number | |||
if (tonumber(sizedefault) or 0) > 0 then | |||
sizedefault = sizedefault .. "px"; | |||
end | end | ||
result = "[[File:" .. image; | result = "[[File:" .. image; | ||
if page ~= "" and page ~= nil then | |||
result = result .. "|page=" .. page; | |||
end | |||
if size ~= "" and size ~= nil then | if size ~= "" and size ~= nil then | ||
result = result .. "|" .. size; | result = result .. "|" .. size; | ||
233行目: | 251行目: | ||
result = result .. "|border"; | result = result .. "|border"; | ||
end | end | ||
if upright ~= "" then | if upright == "yes" then | ||
result = result .. "|upright"; | |||
elseif upright ~= "" then | |||
result = result .. "|upright=" .. upright; | result = result .. "|upright=" .. upright; | ||
end | end |