User:BillKing

From MediaWiki.org
Jump to navigation Jump to search

Scribunto and (Lua) and MediaWiki[edit]

Below is summary of findings etc. while creating modules with Scribunto (Lua)[edit]

  1. TESTED - Create modules containing either an array or matrix (array of arrays) as data source to other modules.
  2. TESTED - Create modules that use a string or an array or an array matrix as data sources.
    • Ability to use more than one array contained in a matrix in a module
    • Use list of delimited string as arguments to a module
  3. TESTED - Develop an approach for handling data in associative arrays
    • Ability to identify data elements
    • Ability to break apart data elements using subfields
  4. Types of working modules created on personal wiki
    • DONE - simplified infobox module - simple array
    • DONE - build sorted table from associative array with options:
      • Output column heads or not - no heads - array will not be sortable
      • Limited selection of rows to output
      • Limited selection of columns to output
      • Option to add entry number column to table (5 digit number)
    • DONE - use an array to perform lookups (ie. Find a state abbreviation and output the state's official flower or capitol etc.)
    • DONE - sort an input string (list) based on a delimiter
    • DONE - output string in delimited form or create a list
      • option to perform leading article lookups for "A, An, And, The" for sorting purposes
    • DONE - limited table check module for certain types of data arrays
    • TESTED - ability to create an array from a string (list)
  5. Sandbox TEST modules created on en.wikipedia
  6. TESTED - Use a variable (created by Variables extension) to pass to a module
  7. TESTED - Use output of one module and pass output as argument to another module
  8. DONE - Create Categories
    • Module created to read in a list and produce Categories on a page
  9. TESTED - Use a template with a ParserFunction switch statement to call preformed invoke to various modules
    • ie. Option 1 - invoke an infobox module with different parameters.
  10. TESTED - Can now use a multiline string inside a called Lua module (strings contained in Lua using double brackets), returning it as a single string.
    1. Note: fixed problematic issue with "\n" by editing the LuaStandalone engine for my installation on Windows 7...
    • page = [[
      * One
      * Two
      ;Term
      :Definition
      ]]
    • Also, can add variables to a multiline Lua string inside a module. I now use it to add a small section to various pages.
  11. TESTED - Can use an #invoke statement as an argument to a template.
  12. DONE - Module created to swap strings -- ie. swap dog n cat - 'The brown dog jumped over the cat' to 'The brown cat jumped over the dog'
  13. DONE - Module created to count number of elements of a list passed as a string.
  14. DONE - Module created to convert a Roman Numeral to number: ie. mmxiii to 2013
  15. DONE - Module created to repeat a string multiple times (ie. "test" to become "testtesttesttest")
    • also can specify another string and replace/repeat multiple times within initial string (ie. "this is a test" - other string "is" to become "this isisisis a test" etc.)
      • Specify how many times - 1st or last or a number of occurences etc.
  16. DONE - can check if mv.loadData() is successful or not and perform tasks based upon that condition without having the Script Error message appear because of a missing module or mistyped module name.
  17. TESTED - use a table to contain string arguments for gsub etc.
  18. DONE ELSEWHERE - ISBN digit check digit creation - validation
  19. TESTED - ability to pass multiple sets of template parameters to a template as a single parameter that invokes a Lua module..
  20. Other Notes
    1. Note: To trigger error message that will appear within RED Script Error can use following code: do return error("Your Error Message") end -- simpler just: error("Your Error Message")
    2. If a value of a parameter is 'nil' and want to assign a default value (rather than do an if else statement):
      • ie. local variable yesno = frame.args[2] or "no"
    3. Length of a string passed to a module (2 ways I found):
      • #frame.args[1] or if made into a variable string.len(variable)
    4. Less typing using string functions:
      • test = string.gsub("test","e","E") change to test = test:gsub("e","E")
    5. Important
      • An #invoke's parameter that is a string containing an '=' sign and to be handled by the invoked module will fail -- to resolve enclose the ='s sign in curly brackets -- see: https://en.wikipedia.org/wiki/Help:Templates#Usage_hints_and_workarounds.
      • One work around is to set a default in the Module to overcome the 'nil' error but that may or may not be appropriate for all cases.
      • Just something to remember!
        • Also Note: It is possible to define a variable and pass that variable to a module without having to resort to enclosing the ='s sign in curly brackets, yet other method - replacing the ='s sign with ='s curly brackets with Replace. However, neither the Variables nor the String Functions extensions are incorporated in mediawiki, wikipedia etc. - I use those extensions in my own small personal wikis.
        • Good idea when using a passed string to a Lua module to Escape those pesky magic Lua characters.
  21. Works in Progress
  22. DONE: Can pass multiple sets of like named parameters as a single parameter to a template's #invoke while avoiding having to put curly brackets around the ='s and |'s sign...
    • Investigating - adding rows and columns and outputting totals in a table
    • Investigating - removing numerous templates that I use and replacing them with Scribunto (Lua) modules
    • Investigating - creating categories & sub categories based on a simple taxonomy (ie. Basic Library of Congress Classification) ♙

infobox example[edit]



Some InformationInfobox
  1. Simple Infobox Builder
    • Uses an array as datasource : data source
    • Uses this Module to process data from wjkinfodata
    • Invoking Scribunto (Lua): {{#invoke:wjkinfobox|mkinfobox|wjkinfodata}}
  2. Data Source array numbered elements contain "@" subfield characters.
    • @t = Title of infobox
    • @i = Image for Infobox
      • @l = link (must have above @i subfield
      • @c = caption (must have above @i subfield
    • @h = section head
    • @s = sub-section head
    • @n = left side
    • @d = description
    • @o = Note (other)
    • ....... can use multiple combinations or mix up the order...
  3. Leave a message on my talk page if you so wish...

  • created by: BillKing (talk) 22:37, 6 May 2013 (UTC)
  • Only testing one Module wjkinfobox - have several others ready; don't want to flood this site.
My Simple InfoBox
noframe
Scribunto is Fun!
Simple Infobox Builder
Module(s)
wjkinfoboxBuilds Infobox
wjkinfodataSource for data for this Infobox.
Other Information!

This is a simple test of an idea using Scribunto