User:Wikid77/Module:Echo
local str = {}
-- Function: len -- -- This function returns the length of the target string. -- -- Usage: -- Script error: No such module "Echo". -- OR -- Script error: No such module "Echo". -- -- Parameters -- s: The string whose length to report -- -- If invoked using named parameters, Mediawiki will automatically -- remove any leading/trailing whitespace from the target string.
function str.len( frame )
local new_args = str._getParameters( frame.args, {'s'} ); local s = new_args['s'] or ; return mw.ustring.len( s )
end
-- Function: echo -- -- This function returns the contents of the target string. -- -- Usage: -- Script error: No such module "Echo". -- OR -- Script error: No such module "Echo". -- -- Parameters -- s: The string whose contents to display -- -- If invoked using named parameters, Mediawiki will automatically -- remove any leading/trailing whitespace from the target string.
function str.echo( frame )
local new_args = str._getParameters( frame.args, {'s'} ); local s = new_args['s'] or ; return s
end
-- Function: cite -- -- This function displays cite parameters. -- -- Usage: -- Script error: No such module "Echo". -- -- Parameters -- author, title, url, date: strings to display
function str.cite( frame )
-- local args = str._getParameters( frame.args, -- {'author','last','first','last1','first1','title','url','date'} ); local p1 = frame.args[1] or 'web'; local author = frame.args['author'] or ; local last = frame.args['last'] or ; local last1 = frame.args['last1'] or ; local first = frame.args['first'] or ; local first1 = frame.args['first1'] or ; local title = frame.args['title'] or ; local url = frame.args['url'] or ; local date = frame.args['date'] or ;
local work = frame.args['work'] or ; local periodical = frame.args['periodical'] or ; local newspaper = frame.args['newspaper'] or ; local journal = frame.args['journal'] or ;
local day = frame.args['day'] or ; local month = frame.args['month'] or ; local year = frame.args['year'] or ; local accessdate = frame.args['accessdate'] or ; local agency = frame.args['agency'] or ; local publisher = frame.args['publisher'] or ; local location = frame.args['location'] or ; local place = frame.args['place'] or ; local volume = frame.args['volume'] or ; local edition = frame.args['edition'] or ; local issue = frame.args['issue'] or ; local number = frame.args['number'] or ; local pages = frame.args['pages'] or ; local page = frame.args['page'] or ; local at = frame.args['at'] or ; local archivedate = frame.args['archivedate'] or ; local archiveurl = frame.args['archiveurl'] or ;
local text = author if author ~= or last ~= or last1 ~= then if last ~= or last1 ~= then text = text .. last ..last1 ..', '.. first ..first1 end if date ~= then text = text .. " (" ..date .."). " else if year ~= then text = text .. " (" ..day ..month ..year .."). " else if string.sub(text,-1,-1) == '.' then text = text .. ' ' else text = text .. '. ' end end end --endif-else date end
Title
local type = '"' if p1=='book' then type = "" end if url ~= then text = text .. '[' ..url .. ' ' ..type ..title ..type .. ']' else text = text .. type ..title .. type end if periodical ~= then text = text .. ". " ..periodical .. "" end if newspaper ~= then text = text .. ". " ..newspaper .. "" end if journal ~= then text = text .. ". " ..journal .. "" end if work ~= then text = text .. ". " ..work.."" end
Pub/location/volume
if journal ~= or work~= or newspaper~= then if location ~= or place ~= then text = text ..' (' .. location .. place if publisher ~= or agency ~= then text = text ..': ' ..publisher .. agency end text = text ..')' else if publisher ~= or agency ~= then text = text ..'. ' .. publisher .. agency end end -- endif-else location/place else -- else not journal/work/newspaper if agency ~= then text = text .. '. ' .. agency end if location ~= or place ~= then text = text ..'. ' .. location .. place if publisher ~= then text = text ..': ' .. publisher end else if publisher ~= then text = text .. '. ' .. publisher end end -- endif-else location/place #2 end --endif-else journal/newspaper if volume ~= then if string.len(volume) > 4 then text = text .. '. ' .. volume text = text .. " " .. volume .. "" end --endif volume #len > 4 end if issue ~= or number ~= then text = text .. ' (' ..issue ..number ..')' end --if issue/number if edition ~= then text = text .. ' (' ..edition ..' ed.)' end --if edition
Date/year
if last ~= or author ~= or last1 ~= or editor~= then -- then omit date here -- else --show date/year if date ~= then text = text .. '. ' ..date else if year ~= then text = text .. '. ' ..day ..month ..year end end --endif-else date end --endif-else last/author/last1..
Pages/page
if pages ~= then if p1 == 'journal' then text = text .. ": " ..pages else text = text .. ". pp. " ..pages end else if page ~= then if p1 == 'journal' then text = text .. ": " ..page else text = text .. ". p. " ..page end end end --endif-else pages if at ~= then text = text .. ". " ..at end
Access date
if accessdate ~= then text = text .. ". Retrieved " ..accessdate end
text = text .. "." return text
end
-- Helper function that populates the argument list given that user -- may need to use a mix of named and unnamed parameters. This is -- relevant because named parameters are not identical to unnamed -- parameters due to string trimming, and when dealing with strings, -- there can be a need to either preserve or remove that whitespace -- depending on the application.
function str._getParameters( frame_args, arg_list )
local new_args = {}; local index = 1; local value; for i,arg in ipairs( arg_list ) do value = frame_args[arg] if value == nil then value = frame_args[index]; index = index + 1; end new_args[arg] = value; end return new_args;
end
return str