Wikimedia

[Lua task #02] Use Lua on English Wikipedia

To work on this, you must have successfully finished the task "[Lua task #01] Set up your sandbox for programming in Lua on English Wikipedia", although if you have already done two beginner tasks, that will not be available. In that case, follow the instructions at https://en.wikipedia.org/wiki/User:RexxS/sandbox/GCI01 carefully before starting this task.

A Wikipedia page can call a Lua module to do calculations, process text, format citations, fetch information from Wikidata, and many other jobs where a programming language is needed to get a result.

1 A Lua module is used inside a Wikipedia page by using a call something like

{{#invoke:RexxS|carousel}}

Type or copy that line as a new line at the end of your sandbox (not your sandbox module) and save it. You should see the filename of a JPG image. The line makes use of a module called Module:RexxS. Modules can contain many functions and the line you have entered calls a function in that module called "carousel".

2 Modify that line to read

[[File:{{#invoke:RexxS|carousel}} | thumb]]

and save it. This uses the standard MediaWiki image syntax to display the image. You can read a lot more about image syntax if you are interested.

3 Look at https://en.wikipedia.org/wiki/Module:RexxS and examine the code. See if you can work out how the function picks a filename. You may find the documentation helpful to learn how Lua works. In your sandbox, on a new line, write down the name of the list (a Lua table) that stores the filenames.

Task tags

  • lua
  • scribunto

Students who completed this task

Gammaburst_3000, Chen Xinpeng, Chiang Yu Hsuan, Adam Husain, Patryk, Kylie Cho, Gabriel CH Lee, Chen Wuyang, krithika jaikumar, Sathvik Hebbar, Om Desai, Cliff Chen, Tarun Prasad, suufi, Priyanshu Ahuja, Rhuta Akolkar-1, Vishal, Gabe Mitnick, Yeoh Yu Yong, PokkPol, Tai Chee Hian, Yajn Bollapragada, Sanath, Kid116, Linda Thelen, Jan Nowosielski, Shaun Lee, C. F. Fairfeld, Sai, Liza Amini, Yu Chenbo, Arthur Long, OHM OMAR, TimurO, Wade, Rafid Aslam, srflp

Task type

  • code Code
close

2017