Page MenuHomePhabricator

Expose ExternalData functions to Lua
Closed, ResolvedPublic

Description

Expose ExternalData functions to Lua, when Scribunto is enabled, e.g. mw.external.web for {{#get_web_data:}}, since hacks like frame:callParserFunction ('#get_web_data', …) are of limited use.

Pass parameters to them as tables, e.g., make the effectively named, e.g.:

local cities = mw.external.web {
    url = 'https://discoursedb.org/GermanyCSV.txt'
  , data = 'bordered countries=Borders,population=Population,area=Area,capital=Capital'
  , format = 'CSV with header'
}

Allow to pass comma-separated strings as tables:

local cities = mw.external.web {
    url = 'https://discoursedb.org/GermanyCSV.txt'
  , data = {
        ['bordered countries']  = 'Borders'
      , population = 'Population'
      , area = 'Area'
      , capital = 'Capital'
    }
  , format = 'CSV with header'
}

Make them return the fetched values as tables.

Add flip parameter to bound functions that makes returned tables row-based rather than column-based, which will be more natural in Lua context, e.g.:

local articles = mw.external.web {
    'flip'
  , url = 'https://www.apn.ru/index.php?do=authors&author=637'
  , data = 'url=div.left_cell>h2>a.attr(href),title=div.left_cell>h2>a,date=div.left_cell>ul>li:nth-of-type(2)'
  , format = 'HTML'
}

or

local articles = mw.external.web {
    flip = true
  , url = 'https://www.apn.ru/index.php?do=authors&author=637'
  , data = 'url=div.left_cell>h2>a.attr(href),title=div.left_cell>h2>a,date=div.left_cell>ul>li:nth-of-type(2)'
  , format = 'HTML'
}

mw.dumpObject (articles) should return

table#1 {

 table#2 {
   ["date"] = "16 май 2020, 08:40",
   ["title"] = "Без Крылова",
   ["url"] = "https://www.apn.ru/index.php?newsid=38277",
 },
 table#3 {
   ["date"] = "20 апрель 2019, 19:53",
   ["title"] = "Стать героем",
   ["url"] = "https://www.apn.ru/index.php?newsid=37794",
 },
 table#4 {
   ["date"] = "05 сентябрь 2017, 02:55",
   ["title"] = "Из огня да в полымя",
   ["url"] = "https://www.apn.ru/index.php?newsid=36623",
 },

(skipped)

}

Correspondence:

{{#get_web_data:}}mw.external.web
{{#get_file_data:}}mw.external.file
{{#get_soap_data:}}mw.external.soap
{{#get_ldap_data:}}mw.external.ldap
{{#get_db_data:}}mw.external.db

Event Timeline

alex-mashin updated the task description. (Show Details)
alex-mashin updated the task description. (Show Details)
alex-mashin updated the task description. (Show Details)
alex-mashin updated the task description. (Show Details)

Change 611933 had a related patch set uploaded (by Alex Mashin; owner: mashin):
[mediawiki/extensions/ExternalData@master] Expose five parser functions to Scribunto/Lua

https://gerrit.wikimedia.org/r/611933

Change 611933 merged by jenkins-bot:
[mediawiki/extensions/ExternalData@master] Expose five parser functions to Scribunto/Lua

https://gerrit.wikimedia.org/r/611933