Difference between revisions of "Module:Sandbox/Nyoron/revisionuser"
Jump to navigation
Jump to search
blackwiki>にょろん (←Created page with 'p={} local function err(message) return mw.ustring.format("<span class='error'>Error: %s</span>", message) end local function isTrue(x) if ( type(x)==...') |
m (5 revisions imported) |
||
| (4 intermediate revisions by one other user not shown) | |||
| Line 6: | Line 6: | ||
local function isTrue(x) | local function isTrue(x) | ||
| − | + | if type(x)=='boolean' then | |
| − | + | return x | |
end | end | ||
| − | + | if type(x)=='number' then | |
| − | + | if x == 0 then | |
| + | return false | ||
| + | else | ||
| + | return true | ||
| + | end | ||
end | end | ||
if type(x)=='string' then | if type(x)=='string' then | ||
x = mw.ustring.lower(x) | x = mw.ustring.lower(x) | ||
| − | if x == 'true' or x == ' | + | if x == 't' or x == 'true' or x == 'y'or x == 'yes' or x == 'on' then |
return true | return true | ||
end | end | ||
| + | n = tonumber(x) | ||
| + | if n then | ||
| + | if n == 0 then | ||
| + | return false | ||
| + | else | ||
| + | return true | ||
| + | end | ||
| + | end | ||
end | end | ||
| Line 24: | Line 36: | ||
p.REVISIONUSER = function(frame) | p.REVISIONUSER = function(frame) | ||
local pageName = frame.args[1] or nil | local pageName = frame.args[1] or nil | ||
| + | local ignore_errors = frame.args.ignore_errors or false | ||
-- args[1] is blank | -- args[1] is blank | ||
if pageName == nil or pageName == "" then | if pageName == nil or pageName == "" then | ||
| Line 37: | Line 50: | ||
-- you may want try relative path | -- you may want try relative path | ||
if mw.ustring.sub(pageName,1,1) == '/' then | if mw.ustring.sub(pageName,1,1) == '/' then | ||
| − | fullpageName = frame:preprocess("{{FULLPAGENAME}}") | + | local fullpageName = frame:preprocess("{{FULLPAGENAME}}") |
| − | pageTitle = mw.title.new(fullpageName .. pageName) | + | local pageTitle = mw.title.new(fullpageName .. pageName) |
if pageTitle.exists then | if pageTitle.exists then | ||
return frame:preprocess("{{REVISIONUSER:" .. pageTitle.prefixedText .. "}}") | return frame:preprocess("{{REVISIONUSER:" .. pageTitle.prefixedText .. "}}") | ||
| Line 44: | Line 57: | ||
end | end | ||
-- The pageTitle does not exist | -- The pageTitle does not exist | ||
| − | |||
if isTrue(ignore_errors) then | if isTrue(ignore_errors) then | ||
return "" | return "" | ||
Latest revision as of 10:32, 27 September 2020
| 40x40px | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
Comparison
| Case | Input | Output |
|---|---|---|
{{REVISIONUSER}} |
Blackwikiadmin | |
{{REVISIONUSER|}} |
Template:REVISIONUSER | |
| page exists | {{REVISIONUSER|Oleic acid}} |
Template:REVISIONUSER |
| page not exist | {{REVISIONUSER|Oreic acid}} |
Template:REVISIONUSER |
| relative path | {{REVISIONUSER|/doc}} |
Template:REVISIONUSER |
{{REVISIONUSER:}} |
||
| page exists | {{REVISIONUSER:Oleic acid}} |
|
| page not exist | {{REVISIONUSER:Oreic acid}} |
|
| relative path | {{REVISIONUSER:/doc}} |
|
| {{#invoke:REVISIONUSER|REVISIONUSER}} | Script error: No such module "REVISIONUSER". | |
| page exists | {{#invoke:REVISIONUSER|REVISIONUSER|Oleic acid}} | Script error: No such module "REVISIONUSER". |
| page not exist | {{#invoke:REVISIONUSER|REVISIONUSER|Oreic acid}} | Script error: No such module "REVISIONUSER". |
| page not exist | {{#invoke:REVISIONUSER|REVISIONUSER|Oreic acid|ignore_errors=t}} | Script error: No such module "REVISIONUSER". |
| relative path | {{#invoke:REVISIONUSER|REVISIONUSER|/doc}} | Script error: No such module "REVISIONUSER". |
| relative path | {{#invoke:REVISIONUSER|REVISIONUSER|/doc|ignore_errors=1}} | Script error: No such module "REVISIONUSER". |
p={}
local function err(message)
return mw.ustring.format("<span class='error'>Error: %s</span>", message)
end
local function isTrue(x)
if type(x)=='boolean' then
return x
end
if type(x)=='number' then
if x == 0 then
return false
else
return true
end
end
if type(x)=='string' then
x = mw.ustring.lower(x)
if x == 't' or x == 'true' or x == 'y'or x == 'yes' or x == 'on' then
return true
end
n = tonumber(x)
if n then
if n == 0 then
return false
else
return true
end
end
end
return false
end
p.REVISIONUSER = function(frame)
local pageName = frame.args[1] or nil
local ignore_errors = frame.args.ignore_errors or false
-- args[1] is blank
if pageName == nil or pageName == "" then
-- with no colon
return frame:preprocess("{{REVISIONUSER}}")
end
-- args[1] is not blank
pageTitle = mw.title.new(pageName)
if pageTitle.exists then
-- with colon
return frame:preprocess("{{REVISIONUSER:" .. pageTitle.prefixedText .. "}}")
end
-- you may want try relative path
if mw.ustring.sub(pageName,1,1) == '/' then
local fullpageName = frame:preprocess("{{FULLPAGENAME}}")
local pageTitle = mw.title.new(fullpageName .. pageName)
if pageTitle.exists then
return frame:preprocess("{{REVISIONUSER:" .. pageTitle.prefixedText .. "}}")
end
end
-- The pageTitle does not exist
if isTrue(ignore_errors) then
return ""
end
return err("The page [" .. pageTitle.prefixedText .. "] does not exist.")
end
return p