Wikipedia:Lua/Requests

From Wikipedia, the free encyclopedia
Jump to: navigation, search
  WP:Lua
Project
  WT:Lua
Project talk
  Help
 
  To do
 
  Requests
 
  Resources
en: m: mw: external
 
Shortcuts:

Lua scripts on Wikipedia are similar to templates but useful for performing more complex tasks for which templates are too complex or slow. Common examples include numeric computations, string manipulation and parsing, and decision trees. You can use this page to request help from Lua developers in writing a Lua module for a specific task on Wikipedia or another Wikimedia Foundation project. Both debugging help and full implementation are available.

To start a request, just make a new section below and describe what you need. You may wish to first check Special:PrefixIndex/Module: to see if you can find a suitable existing script.

It may help developers to provide examples of where the task is likely to be useful within Wikipedia. If the proposal would replace or improve upon existing templates, please note which ones.

scan for template text in category of articles[edit]

Is it possible to scan the contents of articles for specific text strings (actually template) based on a list of articles in a category and its sub-categories? I would like to make these table numbers dynamic. --Traveler100 (talk) 18:03, 4 January 2016 (UTC)

It would help if you were to spell out the operation required for an example, but I suspect the answer is that it is too complex to be achieved with a module. I think you need to list the articles in various categories, then read the wikitext from each page and work out if a certain template is used. I don't think "what links here" is available to a module so using that as a workaround wouldn't work. Some kind of bot would be needed. Johnuniq (talk) 22:16, 4 January 2016 (UTC)
On Wikivoyage the categories are very hierarchical and clean and the articles a standard format so not as risky as with Wikipedia. Task, take a category (say a country), progress through all sub-categories, for each article n categories do a text search for use of specific templates ({{outlinecity}}, {{guideregion}}, .. {{sleep , ..) if found at to count expression. Return count values. --Traveler100 (talk) 06:01, 5 January 2016 (UTC)
Modules don't have access to category members, so this is not possible in Lua at the moment. It is possible to load the wikitext of a given page, but then parsing that wikitext to find a list of templates is hard. You need to take into account things like nowiki tags, HTML comments, template redirects, capitalisation and whitespace allowed for template names/arguments, etc. (This kind of thing is the reason that we have Parsoid, but that data is not available from Lua by design.) The only practical way at the moment to do what you are proposing is to use a bot to update the table. — Mr. Stradivarius ♪ talk ♪ 13:03, 5 January 2016 (UTC)
Just a crazy idea... Could one use JS on the client side to run a mediawiki API to get categories then 'alert data' to call module (via expandtemplates) on server side to do some processing to get category/page names - then get page contents and parse for templates... I can imagine the CPU cycles would be a bit overwhelming and probably die, not to mention the complexity of data parsing. I would expect something like this would have to be limited. -- Definitely would be better if Lua could access category members!Matroc (talk) 01:53, 14 January 2016 (UTC)
in principle yes, though i think you are mixing your metaphors: the API call is "parse" - "expandtemplate" is something to use from lua, not on client side. you can call "parse" with any piece of wikicode, and even tell the backend to parse it "as if" this text was part of a specified page (so, for instance, magic words such as {{PAGENAME}} or {{PAGESIZE}} that the template might use, will receive the desired value.
this whole line of investigation may be wrong, IMO: i do not fully understand the requirements, but to me, it looks awfully close to a functionality cirrus-search already have: we now have meta-search words that can do what i think you want. specifically, "incategory:" and "hastemplate:". this will _not_ cover the "and its subcategories" part of the original request, so if this part is essential, my suggestion falls short. peace - קיפודנחש (aka kipod) (talk) 15:47, 14 January 2016 (UTC)
Thanks - I thought I might have been a bit off base, it was just something I had been thinking about - peace - Matroc (talk) 22:22, 14 January 2016 (UTC)