Difference between revisions of "Publications"
From ACES
(Created page with "local getArgs = require('Module:Arguments').getArgs local cargo = mw.ext.cargo local p = {} local fields = { "entry", "address", "annote", "author", "booktitle", "chapter...") |
|||
| (12 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local getArgs = require( | local getArgs = require([[Module:Arguments]]).getArgs | ||
local date = require([[Module:Date]]) | |||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local fstr = mw.ustring.format | |||
local p = {} | local p = {} | ||
local fields = { | local fields = { | ||
entry = {}, | |||
address = {BibTeX = true}, | |||
annote = {BibTeX = true}, | |||
author = {BibTeX = true}, | |||
booktitle = {BibTeX = true}, | |||
chapter = {BibTeX = true}, | |||
edition = {BibTeX = true}, | |||
editor = {BibTeX = true}, | |||
howpublished = {BibTeX = true}, | |||
institution = {BibTeX = true}, | |||
journal = {BibTeX = true}, | |||
month = {BibTeX = true}, | |||
note = {BibTeX = true}, | |||
number = {BibTeX = true}, | |||
organization = {BibTeX = true}, | |||
pages = {BibTeX = true}, | |||
publisher = {BibTeX = true}, | |||
school = {BibTeX = true}, | |||
series = {BibTeX = true}, | |||
title = {BibTeX = true}, | |||
type = {BibTeX = true}, | |||
volume = {BibTeX = true}, | |||
year = {BibTeX = true}, | |||
doi = {BibTeX = true}, | |||
issn = {BibTeX = true}, | |||
isbn = {BibTeX = true}, | |||
url = {BibTeX = true}, | |||
_pageName = {}, | |||
pdf = {} | |||
} | } | ||
function p.getBibTeX(entry) | |||
local out = {} | |||
local pagename = entry._pageName | |||
pagename = mw.ustring.gsub(pagename, "%s", "") | |||
table.insert(out, fstr("@%s {%s", entry.entry, pagename)) | |||
for k, v in pairs(fields) do | |||
if v.BibTeX and entry[k] and entry[k] ~= "" and entry[k] ~= "0" then | |||
table.insert(out, fstr("%s = {%s}", k, entry[k])) | |||
end | |||
end | |||
if entry.pdf and entry.pdf ~= "" and entry.pdf ~= "0" then | |||
local titleobject = mw.title.new('File:' .. entry.pdf) | |||
if titleobject.fileExists then | |||
table.insert(out, fstr("%s = {%s}", "pdf", entry.pdf)) | |||
end | |||
end | |||
table.insert(out, fstr("%s = {%s}", "_pageName", entry._pageName)) | |||
return table.concat(out, ",\n") .. "\n}\n" | |||
end | |||
function p._main(args) | function p._main(args) | ||
local | local cargoFields = {} | ||
for k, _ in pairs(fields) do table.insert(cargoFields, k) end | |||
cargoFields = table.concat(cargoFields, ",") | |||
local args = { | local args = { | ||
where = nil, | where = nil, | ||
| Line 18: | Line 67: | ||
groupBy = nil, | groupBy = nil, | ||
having = nil, | having = nil, | ||
orderBy = ' | orderBy = 'year DESC, month DESC', | ||
limit = | limit = args.limit or "9999999", | ||
offset = nil | offset = nil | ||
} | } | ||
local results = cargo.query( | local results = cargo.query('publication', cargoFields, args) | ||
mw.logObject(results) | mw.logObject(results) | ||
local rSet = {} | |||
local out = {} | |||
for _, entry in ipairs(results) do | |||
if rSet[entry._pageName] ~= true then | |||
table.insert(out, p.getBibTeX(entry)) | |||
rSet[entry._pageName] = true | |||
end | |||
end | |||
return table.concat(out, "") | |||
end | end | ||
Latest revision as of 16:51, 9 November 2021
Documentation for this module may be created at Module:Publications/doc
local getArgs = require([[Module:Arguments]]).getArgs
local date = require([[Module:Date]])
local cargo = mw.ext.cargo
local fstr = mw.ustring.format
local p = {}
local fields = {
entry = {},
address = {BibTeX = true},
annote = {BibTeX = true},
author = {BibTeX = true},
booktitle = {BibTeX = true},
chapter = {BibTeX = true},
edition = {BibTeX = true},
editor = {BibTeX = true},
howpublished = {BibTeX = true},
institution = {BibTeX = true},
journal = {BibTeX = true},
month = {BibTeX = true},
note = {BibTeX = true},
number = {BibTeX = true},
organization = {BibTeX = true},
pages = {BibTeX = true},
publisher = {BibTeX = true},
school = {BibTeX = true},
series = {BibTeX = true},
title = {BibTeX = true},
type = {BibTeX = true},
volume = {BibTeX = true},
year = {BibTeX = true},
doi = {BibTeX = true},
issn = {BibTeX = true},
isbn = {BibTeX = true},
url = {BibTeX = true},
_pageName = {},
pdf = {}
}
function p.getBibTeX(entry)
local out = {}
local pagename = entry._pageName
pagename = mw.ustring.gsub(pagename, "%s", "")
table.insert(out, fstr("@%s {%s", entry.entry, pagename))
for k, v in pairs(fields) do
if v.BibTeX and entry[k] and entry[k] ~= "" and entry[k] ~= "0" then
table.insert(out, fstr("%s = {%s}", k, entry[k]))
end
end
if entry.pdf and entry.pdf ~= "" and entry.pdf ~= "0" then
local titleobject = mw.title.new('File:' .. entry.pdf)
if titleobject.fileExists then
table.insert(out, fstr("%s = {%s}", "pdf", entry.pdf))
end
end
table.insert(out, fstr("%s = {%s}", "_pageName", entry._pageName))
return table.concat(out, ",\n") .. "\n}\n"
end
function p._main(args)
local cargoFields = {}
for k, _ in pairs(fields) do table.insert(cargoFields, k) end
cargoFields = table.concat(cargoFields, ",")
local args = {
where = nil,
join = nil,
groupBy = nil,
having = nil,
orderBy = 'year DESC, month DESC',
limit = args.limit or "9999999",
offset = nil
}
local results = cargo.query('publication', cargoFields, args)
mw.logObject(results)
local rSet = {}
local out = {}
for _, entry in ipairs(results) do
if rSet[entry._pageName] ~= true then
table.insert(out, p.getBibTeX(entry))
rSet[entry._pageName] = true
end
end
return table.concat(out, "")
end
-- test: =p._main{}
function p.main(frame) return p._main(getArgs(frame)) end
return p