DPL:Manual - General Usage and Invocation Syntax

From FollowTheScore
Revision as of 13:40, 15 August 2007 by Eep² (talk | contribs) (Using DPL2 as a parser function: -you references, reword)
Jump to: navigation, search

Template:Type:Manual

DPL2 can be used as a parser extension or as a parser function. There is no general rule which one is better. The next two sections describe the differences.

If in doubt, you may want to use the parser function syntax as it is more powerful.

Using DPL2 as a parser extension

Parser extensions define a specific tag (in this case <DPL>) and a corresponding end tag (</DPL>). Case doesn´t matter, so it can also be written <dpl>. The text between these tags is handed over to the extension module just as it is. The extension module takes this text as a series of commands, executes them, and inserts the output right at the place where it found the two tags.

Other issues:

  • Every parameter assignment (=command) has to be on a separate line.
  • Lines starting with a # will be ignored (comment).
  • Generally the syntax looks fairly simple and intuitive as it doesn't contain special characters (except for the two embracing tags).
  • Wiki markup expansion does not take place before the commands are handed over to the extension module.
    • This may be useful if you want to pass wiki syntax elements to DPL2 as arguments (see the listseparators option, for example).
    • Magic words like {{PAGENAME}} or {{CURRENTDAY}} cannot be used.
    • Template calls as parameters, like {{{some template}}}, cannot be used.
    • Parser function calls like {{#if:...|...|...}} cannot be used within arguments.
    • To pass wiki syntax elements to DPL as parameters it is sometimes necessary to enforce a line break. The reason is that wiki syntax depends on line breaks. Instead, use \n or for that purpose.

In many cases there is no need to have macro expansion within the parameter list. For example:

 <DPL>
    category = cat1|cat2
    # only pages which contain a link to myPage
    linksto  = myPage
 </DPL>

The example will produce a list of all articles which belong to cat1 or cat2 and which contain a reference to myPage. Note that the pipe character (which is used to define a logical OR between the two categories) can be written as it is. The name of the page (myPage), however, must be a hardcoded constant. The output of this DPL call would be something like:

Using DPL2 as a parser function

Parser functions look like templates which start with a hash character (#). They are more closely integrated with the wiki system. They are more powerful but their syntax looks a bit more complicated. In this case, it can be written {{#dpl:...|...}} just the way {{#if:...|...}} is used. The text between the double curly braces is interpreted and expanded according to wiki syntax rules before it is handed over to the extension module. This means:

  • All kind of wiki markup expansions take place before the commands are handed over to the extension module.
    • Magic words like {{PAGENAME}} or {{CURRENTDAY}}</tt> can be used.
    • To use wiki characters as arguments, escape them.
      • It is possible to either define a special template like {{!}} which contains a single | symbol as its contents.
      • It is possible to use the symbol ¦ instead of |; this is very intuitive and maybe it could be adopted by MediaWiki in general...but be careful: it must be inserted by copy-and-paste from here (or from a HTML symbol or extended ASCII table like Windows' Character Map) as normally a keyboard will not have it available (even worse: on some keyboards the standard pipe character is printed in a way that it looks more like the "broken pipe").
  • The text can (but needs not) be written in one line of text, parameters are separated by pipe characters.
  • What was said before regarding explicit line breaks holds true also for the parser function syntax, i.e. the special symbols \n or must be used to insert an explicit linefeed character into the wiki output stream if wiki symbols are used, which must stand at the beginning of a line.

Example:

 {{#dpl: category = cat1{{!}}cat2 | linksto = {{{1}}} }}
 
                  or
 
 {{#dpl:
   |category = cat1¦cat2
   |linksto  = {{{1}}}
 }}

Both examples will produce an identical list of all articles which belong to cat1 or cat2 and which contain a reference to a certain page. It is assumed that the above invocation of #dpl is contained within a template. The desired page name will be passed as a parameter when calling the template. Within the template the page name can be referred to as {{{1}}}.

Note: the pipe character, which is used to define a logical OR for the two categories, must be represented as a call of a special template (which would typically be called "Template:!") which has a single pipe character as its contents. The same kind of trick is also found outside DPL in other templates. The second example shows that the ¦ character acts as an alternative to this somewhat awkward notation.

The second example is not literally equivalent to the first one as there is an additional pipe character before the first parameter. Technically, this creates an additional empty parameter, but as empty parameters are silently ignored by DPL it makes no difference.

Characters with special meaning

Sometimes it is necessary to use a character as "plain data" at a place where it normally has a syntactical meaning. Mediawiki is not very clean at character escaping in general. So we had to define our own way in the jungle of "character escaping":

  •  » is translated to >
  • « is translated to <

  • ²{ is translated to {{
  • }² is translated to }}
  • ¦ is translated to |

  • ¶ is translated to a newline
  • \n is translated to a newline

The first two translations make it possible to embed a call to another mediawiki extension into a parameter of a DPL call. The next three translations make it possible to call a template within the 'article loop' of DPL. This is especially useful for nesting DPL calls (DPL recursion). The last two translations are needed because sometimes you must be able to control when and where a line break is issued by DPL. Note that DPL produces wikitext which finally is interpreted by the normal wiki parser. And parts of the wiki text format depend on the fact whether a line starts with a special charcter (e.g. a '*', '#',':',';' etc.).

DPL's mechanism of replacing %xx% variables then can be used to modify the arguments of that call before it will be resolved. Most DPL users will not need this, but for some advanced uses of DPL it is a real help...

Syntax used in this manual

If we give complete examples we will typically use the tag based parser extension syntax in this manual. Except when we want to make use of variable expansion.

Most of the manual deals with the explanation of individual parameters. This is independent of the choice between the two variants described above. So, if you read something like

  • parameter = value

you should have in mind that you must either place DPL tags around (using a separate line for each parameter) or use the parser function syntax and separate parameters by pipe characters.

Interaction between your wiki text and DPL2 output

As mentioned before DPL2 will insert its output exactly at the position where you placed the DPL2 call. This means that you can put wiki syntax around your DPL call, like e.g.:

  {| class=wikitable
  |a table field
  |<DPL>
     linksto=myPage
   </DPL>
  |-
  |another table field
  |...
  |}

You could also use html syntax to surround DPL output as in the following example:

<ul>
  <li>Item1</li>
  <li>Item2
    <DPL>
      ...parameters...
    </DPL>
  </li>
</ul>

Special Note on Self References

In principle a DPL query could be written in a way that the page containing the query (or the page including a template which contains the query) would be part of the result set. Experience in the past has shown that in most cases this leads to unwanted effects. For instance the page containing the query from a mediawiki point of view contains links to all pages it lists. If your DPL statement contains a "uses" clause you will be astonished to find your own page in all results. The same happens with categories... In addition there were technical problems with self referencing result sets (parser loop references which seemed very hard to solve). So it was decided to always skip a self reference in the result set.

DPL never returns its own page in the result.


Symbol replacement in mode=userformat

When mode=userformat is selected, DPL will not output anything by default. Instead it will look for symbols in your input (listseparators, secseparators, multisecseparators) which it will replace by their corresponding values. For example, %TITLE% will be replaced by the title of an article, %PAGE% will be replaced by the pagename. So, if you write something like
[[%PAGE%|%TITLE%]], DPL will create a hyperlink to an article.

See DPL:Manual - DPL_parameters: Controlling output format#listseparators for a complete list of symbols.

The specification of listseparators, secseparators, and multisecseparators does only make sense in combination with mode=userformat. Therefore mode=userformat is automatically implied when listseparators is specified. To make the syntax even more comfortable the simple word format can be used as an alias for listseparators. So:

mode=userformat
listseparators=a,b,c,d

is exactly the same as:

format=a,b,c,d

Use of boolean parameters

A lot of DPL's parameters have type boolean. The manual always assumes that 'true' and 'false' are used to set such parameters. As an alternative, you can also use 'yes' and 'no' (but not just '1' and '0' to use as little bytes as possible, or even 'off' and 'on' as with the standard HTML form checkbox input type).