W3TPL/tag/let: Difference between revisions

From Woozle Writes Code
< W3TPL‎ | tag
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
'''Action''': Assigns a value to a variable.
'''Action''': Assigns a value to a variable.


This page is based on a close examination of the code as it existed on 2022-04-11, after extended debugging and reworking.
This tag has many operations in common with {{l/w3tpl/tag|get}}; a comparison is [[../get-let|here]].
==Tag Attributes==
==Tag Attributes==
Each attribute is processed within a given stage, where stages are processed in essentially this order:
* <code>GetTagInput()</code>:
** '''(input)''' = input stage (determining where the input value should come from, and retrieving it)
* <code>UseTagInput()</code>:
** '''(calc)''' = doing things with the retrieved input
** '''(output)''': = putting the results other places besides the target variable
Attributes within a set are processed in the order in which w3tpl sees them, though there is no guarantee that this will be the same order in which they appear in the tag (since MediaWiki does the tag-parsing).
===core===
===core===
Support for this attribute is required in order for the tag to fulfill its basic purpose.
Support for this attribute is required in order for the tag to fulfill its basic purpose.
* '''name=''': name of variable to receive the calculated value
* '''name=''': name of variable to receive the calculated value
===supported===
===supported===
* '''append''' (calc): append the input string to the current value
All {{l/same|get-let}} common attributes are supported, as well as these:
* '''arg=''' (input): name of POST field to retrieve as tag input
** USAGE: form processing
* '''chr=''' (input): ASCII number of character to use as tag input
* '''copy=''' (input): name of another variable whose value should become the input
* '''echo''' (output): display the resulting value (at the tag's location in the page)
* '''echo''' (output): display the resulting value (at the tag's location in the page)
** This should probably be deprecated. 2022-04-11
* '''self''' (input): takes starting value from same variable, to allow unary operations (e.g. increment, append)
* '''lcase''' (calc): apply <code>strtolower()</code>, i.e. convert the input to lower case
** opposite of "ucase"
* '''lcfirst''' (calc): apply <code>lcfirst()</code>, i.e. convert the first character of the input to lower case
** opposite of "ucfirst"
* '''len=''' (calc): use only the first {{arg|len}} characters of the input (this could probably stand some rethinking)
* '''parse''' (calc): have MediaWiki parse the input, and use the resulting string
* '''pre''' (calc): alias for "parse", for backwards compatibility
* '''self''' (input): use output variable's current value as input for processing
** e.g. for incremental operations
* '''self''' (input): takes starting value from same variable, to allow unary operations
* '''trim''' (calc): apply <code>trim()</code>
* '''ucase''' (calc): apply <code>strtoupper()</code>, i.e. convert the input to upper case
** opposite of "lcase"
* '''ucfirst''' (calc): apply <code>ucfirst()</code>, i.e. convert the first character of the input to upper case
** opposite of "lcfirst"
* '''val=''' (input): value to use as input
===unsupported===
===unsupported===
These are currently not enabled. Code to support some of them exists, though it may not be working.
These are currently not enabled. Code to support some of them exists, though it may not be working.
Line 44: Line 16:
* '''load''' (should probably be "fetch"): retrieve starting value from the current page's properties
* '''load''' (should probably be "fetch"): retrieve starting value from the current page's properties
** opposite of "save"
** opposite of "save"
* '''null''': set the calculated value to NULL
* '''null''' (input): use NULL as the input
* '''null''' (input): use NULL as the input
* '''oparse''' is now just "parse"
* '''oparse''' is now just "parse"
Line 78: Line 49:
*** STAGE 2 now replaced by UseTagInput() (operations are done on the input)
*** STAGE 2 now replaced by UseTagInput() (operations are done on the input)
** removed DoFromScalar()
** removed DoFromScalar()
* '''2022-04-20''' moved common attributes into the caTag_Var, so {{l/w3tpl/tag|get}} and {{l/w3tpl/tag|let}} can share the same processing code.
** Have not yet updated <code>get</code> to use this, though.

Latest revision as of 00:19, 21 April 2022

About

Action: Assigns a value to a variable.

This tag has many operations in common with <get>; a comparison is here.

Tag Attributes

core

Support for this attribute is required in order for the tag to fulfill its basic purpose.

  • name=: name of variable to receive the calculated value

supported

All get-let common attributes are supported, as well as these:

  • echo (output): display the resulting value (at the tag's location in the page)
  • self (input): takes starting value from same variable, to allow unary operations (e.g. increment, append)

unsupported

These are currently not enabled. Code to support some of them exists, though it may not be working.

  • index=: treats the target variable (specified by <name>) as an array, and specifies the element to use
  • load (should probably be "fetch"): retrieve starting value from the current page's properties
    • opposite of "save"
  • null (input): use NULL as the input
  • oparse is now just "parse"
  • page= (input): name of wiki page to use as input (instead of tag contents)
  • raw: if present, "save" will store the value as an unserialized string
    • The default is to serialize it, preserving variable type.
    • I think this only applied to <save>.
  • save (should probably be "store"): store the result in the properties for the current page
    • opposite of "load"

History

  • 2011-05-31 MainProcess()/DoFromScalar(): added "tag" attribute
  • 2016-09-22 MainProcess()/DoFromScalar(): adapting as method of LET tag object
  • 2017-10-30 MainProcess()/DoFromScalar(): major rewrite of everything
    • changing from static to dynamic
    • using internal properties
  • 2017-11-01 rewrite
    • Removing support for "load" attribute until we have a usage case.
    • It doesn't make sense to load a value you'd have to save anyway.
      • (Different page, perhaps? But when would we need that? Need usage case.)
    • (MainProcess()) copied code from DoFromScalar() to MainProcess(), which will replace it
    • replacing DoFromScalar() with MainProcess()
  • 2018-06-04 This currently saves the property values in RAW format (i.e. not serialized).
    • To change this, replace SaveValueRaw() with SaveValue().
  • 2020-08-17 (MainProcess()) upgrades and fixes
    • Somehow, Var::GetValue_fromExpression() wasn't being called to interpret "val=" expressions. I've reinstated it. Not sure if there are other attributes where it should be applied. If they come up, document them.
  • 2020-09-24 introducing the 'raw' attribute, which saves in non-serialized format
    • Now saving serialized by default.
  • 2022-04-08 Belatedly saving the figured value into the variable. Where was that being done before?
  • 2022-04-09
    • MainProcess() is, uh, no longer being called...
      • STAGE 1 was replaced by GetTagInput() (input is retrieved from somewhere)
      • STAGE 2 now replaced by UseTagInput() (operations are done on the input)
    • removed DoFromScalar()
  • 2022-04-20 moved common attributes into the caTag_Var, so <get> and <let> can share the same processing code.
    • Have not yet updated get to use this, though.