W3TPL/tags: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
(alphabetical listing)
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
==About==
==About==
Although the main "meat" of [[W3TPL]] is the (as-yet-unfinished) parser for text within {{xmltag|w3tpl}}{{xmltag|/w3tpl}} tags, there are a number of other tags which replicate much of the same functionality and may be suitable for simpler tasks.
[[W3TPL]] implements a set of XML-style tags for embedding within wikitext, and uses the MediaWiki parser (via a standard hook) to notice them and call the appropriate W#TPL code for processing.


In order to get around the parser, most of these tags have ways of using internal data for their values rather than depending on the parser to get things in the right order. ''to be documented''
The MW parser does not always do things in the expected order, so most of these tags have ways of using internal data for their values rather than depending on the literal sequencing of the tags.


One of the weaknesses of the MediaWiki parser is that it cannot deal with nested tags properly; the ending-tag of a tag-pair nested inside another tag-pair results in closure of the ''outer'' tag-pair as well, and any text past the internal closing-tag is displayed rather than being passed to the tag handler. W3TPL allows you to get around this limitation by defining ''functions'' which are parsed separately from the code-block in which they are executing.
Another issue with the MediaWiki parser is that it cannot deal with nested tags properly; the ending-tag of a tag-pair nested inside another tag-pair results in closure of the ''outer'' tag-pair as well, and any text past the internal closing-tag is displayed rather than being passed to the tag handler. W3TPL allows you to get around this limitation by defining ''functions'' which are parsed separately from the code-block in which they are executing.


My plan has been to create a {{xml/tag|w3tpl}} content-tag which supports directly-parsed scripting, based on the names and attributes of the existing W3 tags.
==Tags==
==Tags==
{|
{|
Line 12: Line 13:
|-
|-
| valign=top |
| valign=top |
* {{w3tpl/tag|arg}}
===Supported===
* {{w3tpl/tag|call}}
* {{l/w3tpl/tag|dump}}
* {{w3tpl/tag|class}}
* {{l/w3tpl/tag|echo}}
* {{w3tpl/tag|dump}}
* {{l/w3tpl/tag|get}}
* {{w3tpl/tag|echo}}
* {{l/w3tpl/tag|hide}}
* {{w3tpl/tag|else}}
* {{l/w3tpl/tag|let}}
* {{w3tpl/tag|for}}
===Unsupported===
* {{w3tpl/tag|func}}
These tags have been written but not checked with current versions of MediaWiki and PHP; they may not work.
* {{w3tpl/tag|get}}
* {{l/w3tpl/tag|arg}}
* {{w3tpl/tag|hide}}
* {{l/w3tpl/tag|call}}
* {{w3tpl/tag|if}}
* {{l/w3tpl/tag|else}}
* {{w3tpl/tag|let}}
* {{l/w3tpl/tag|for}}
* {{w3tpl/tag|load}}
* {{l/w3tpl/tag|func}}
* {{w3tpl/tag|save}}
* {{l/w3tpl/tag|if}}
* {{w3tpl/tag|trace}}
* {{l/w3tpl/tag|load}}
* {{w3tpl/tag|w3tpl}}
* {{l/w3tpl/tag|save}}
* {{w3tpl/tag|xploop}}
* {{l/w3tpl/tag|w3tpl}}
* {{l/w3tpl/tag|xploop}}
| valign=top |
| valign=top |
* '''Text block inclusion''':
* '''Text block inclusion''':
** '''{{w3tpl/tag|hide}}''': Runs the parser on everything in between the tags, but doesn't display the result. Useful for doing a lot of "programmish" stuff, so you can format it nicely and comment it without messing up your display
** '''{{l/w3tpl/tag|hide}}''': Runs the parser on everything in between the tags, but doesn't display the result. Useful for doing a lot of "programmish" stuff, so you can format it nicely and comment it without messing up your display
** '''{{w3tpl/tag|echo}}''': overrides the "hide" attribute (and eventually the {{xmltag|hide}} tag), i.e. displays contents
** '''{{l/w3tpl/tag|echo}}''': overrides the "hide" attribute (and eventually the {{xml/tag|hide}} tag), i.e. displays contents
** '''{{w3tpl/tag|load}}''': includes the contents of another page – like templates, but without creating a separate instance of the page object
** '''{{l/w3tpl/tag|load}}''': includes the contents of another page – like templates, but without creating a separate instance of the page object
* '''{{w3tpl/tag|let}}, {{w3tpl/tag|get}}''': much like PageVars extension, but using XML tags instead of <nowiki>{{#parser}}</nowiki> functions
* '''{{l/w3tpl/tag|let}}, {{l/w3tpl/tag|get}}''': much like PageVars extension, but using XML tags instead of <nowiki>{{#parser}}</nowiki> functions
* '''{{w3tpl/tag|func}}''': defines a function which can be called with arguments later
* '''{{l/w3tpl/tag|func}}''': defines a function which can be called with arguments later
** '''{{w3tpl/tag|arg}}''': optional method of passing arguments to a function
** '''{{l/w3tpl/tag|arg}}''': optional method of passing arguments to a function
** '''{{w3tpl/tag|call}}''': call a previously defined function
** '''{{l/w3tpl/tag|call}}''': call a previously defined function
* '''Control structures''':
* '''Control structures''':
** '''{{w3tpl/tag|if}}, {{w3tpl/tag|else}}'''
** '''{{l/w3tpl/tag|if}}, {{l/w3tpl/tag|else}}'''
** '''{{w3tpl/tag|for}}
** '''{{l/w3tpl/tag|for}}'''
** '''{{w3tpl/tag|xploop}}: Same as <nowiki>{{#xploop}}</nowiki>, but uses varname instead of $s$
** '''{{l/w3tpl/tag|xploop}}''': Same as <nowiki>{{#xploop}}</nowiki>, but uses varname instead of $s$
*** '''syntax''': xploop list="\demarcated\list" repl=string-to-replace sep=separator
*** '''syntax''': xploop list="\demarcated\list" repl=string-to-replace sep=separator
* '''Debugging''':
* '''Debugging''':
** '''{{w3tpl/tag|dump}}''': show list of all variables (with values) and functions (with code)
** '''{{l/w3tpl/tag|dump}}''': show diagnostic information
** '''{{w3tpl/tag|trace}}
* '''In development''':
* '''In development''':
** '''{{w3tpl/tag|class}}'''
** '''{{l/w3tpl/tag|class}}'''
** '''{{w3tpl/tag|w3tpl}}''': currently, is only used for disabling cache; will later enclose blocks of executable w3tpl code
** '''{{l/w3tpl/tag|w3tpl}}''': currently, is only used for disabling cache; will later enclose blocks of executable w3tpl code
* '''Content management''':
* '''Content management''':
** '''{{w3tpl/tag|load}}'''
** '''{{l/w3tpl/tag|load}}'''
** '''{{w3tpl/tag|save}}''' - experimental; may not be useful without a lot more support
** '''{{l/w3tpl/tag|save}}''' - experimental; may not be useful without a lot more support
|}
|}


==Common Attributes==
==Common Attributes==
* '''name'''=: name of variable being accessed (usage depends on tag)
* '''name'''=: name of variable being accessed (usage depends on tag)
* '''hide''': if present, the contents of the tag will not be displayed except for those enclosed by {{w3tpl/tag|echo}}{{w3tpl/tag|echo}} tags. If absent, the contents of the {{w3tpl/tag|echo}}{{w3tpl/tag|echo}} tags are ignored and only the remainder of the content is shown. (At present, contents of the {{w3tpl/tag|hide}} tag itself are never displayed; this will be changed to enable the {{xmltag|echo}} tag at some point.)
* '''hide''': if present, the contents of the tag will not be displayed except for those enclosed by {{l/w3tpl/tag|echo}} tags. If absent, the contents of the {{l/w3tpl/tag|echo}}{{l/w3tpl/tag|echo}} tags are ignored and only the remainder of the content is shown. (At present, contents of the {{l/w3tpl/tag|hide}} tag itself are never displayed; this will be changed to enable the {{xml/tag|echo}} tag at some point.)
** '''Used in''': {{w3tpl/tag|if}}/{{w3tpl/tag|else}}, {{w3tpl/tag|for}}
** '''Used in''': {{l/w3tpl/tag|if}}/{{l/w3tpl/tag|else}}, {{l/w3tpl/tag|for}}
* '''parse''': parse any wikitext when reading the value of a variable
* '''parse''': parse any wikitext when reading the value of a variable
==Technical Notes==
At startup, the hook for each tag is initialized:
* $mwoParser->setHook( {{arg|tag name}},{{arg|tag class}}::Call() )
The content-processing flow for tags goes like this:
* {{arg|tag object}}->Call()
* &rarr; {{arg|tag object}}->Setup((string) $sInput,$arArgs,$mwoParser,$mwoFrame);
* &rarr; return {{arg|tag object}}->FigureReturnValue()
** &rarr; $sOut = $this->Go(); // $sOut gets a bit of extra processing and is eventually returned
*** &rarr; $sIn = $this->GetTagInput();
*** &rarr; $sOut = $this->UseTagInput($sIn);
*** &rarr; return $sOut;
GetTagInput() and UseTagInput() are then specialized by the various tag classes.

Latest revision as of 21:09, 1 May 2022

About

W3TPL implements a set of XML-style tags for embedding within wikitext, and uses the MediaWiki parser (via a standard hook) to notice them and call the appropriate W#TPL code for processing.

The MW parser does not always do things in the expected order, so most of these tags have ways of using internal data for their values rather than depending on the literal sequencing of the tags.

Another issue with the MediaWiki parser is that it cannot deal with nested tags properly; the ending-tag of a tag-pair nested inside another tag-pair results in closure of the outer tag-pair as well, and any text past the internal closing-tag is displayed rather than being passed to the tag handler. W3TPL allows you to get around this limitation by defining functions which are parsed separately from the code-block in which they are executing.

My plan has been to create a <w3tpl> content-tag which supports directly-parsed scripting, based on the names and attributes of the existing W3 tags.

Tags

alphabetical by function

Supported

Unsupported

These tags have been written but not checked with current versions of MediaWiki and PHP; they may not work.

  • Text block inclusion:
    • <hide>: Runs the parser on everything in between the tags, but doesn't display the result. Useful for doing a lot of "programmish" stuff, so you can format it nicely and comment it without messing up your display
    • <echo>: overrides the "hide" attribute (and eventually the <hide> tag), i.e. displays contents
    • <load>: includes the contents of another page – like templates, but without creating a separate instance of the page object
  • <let>, <get>: much like PageVars extension, but using XML tags instead of {{#parser}} functions
  • <func>: defines a function which can be called with arguments later
    • <arg>: optional method of passing arguments to a function
    • <call>: call a previously defined function
  • Control structures:
    • <if>, <else>
    • <for>
    • <xploop>: Same as {{#xploop}}, but uses varname instead of $s$
      • syntax: xploop list="\demarcated\list" repl=string-to-replace sep=separator
  • Debugging:
    • <dump>: show diagnostic information
  • In development:
    • <class>
    • <w3tpl>: currently, is only used for disabling cache; will later enclose blocks of executable w3tpl code
  • Content management:
    • <load>
    • <save> - experimental; may not be useful without a lot more support

Common Attributes

  • name=: name of variable being accessed (usage depends on tag)
  • hide: if present, the contents of the tag will not be displayed except for those enclosed by <echo> tags. If absent, the contents of the <echo><echo> tags are ignored and only the remainder of the content is shown. (At present, contents of the <hide> tag itself are never displayed; this will be changed to enable the <echo> tag at some point.)
  • parse: parse any wikitext when reading the value of a variable

Technical Notes

At startup, the hook for each tag is initialized:

  • $mwoParser->setHook( <tag name>,<tag class>::Call() )

The content-processing flow for tags goes like this:

  • <tag object>->Call()
  • <tag object>->Setup((string) $sInput,$arArgs,$mwoParser,$mwoFrame);
  • → return <tag object>->FigureReturnValue()
    • → $sOut = $this->Go(); // $sOut gets a bit of extra processing and is eventually returned
      • → $sIn = $this->GetTagInput();
      • → $sOut = $this->UseTagInput($sIn);
      • → return $sOut;

GetTagInput() and UseTagInput() are then specialized by the various tag classes.