Difference between revisions of "Sandbox"

From FollowTheScore
Jump to: navigation, search
(+ {{sandbox}})
Line 1: Line 1:
feel free to play around
+
feel free to play around; see also [[Template:Sandbox]].
  
 
== Playground ==
 
== Playground ==

Revision as of 07:51, 28 March 2010

feel free to play around; see also Template:Sandbox.

Playground

You must create valid syntax for the gallery extension if you want to use it within DPL; add debug=5 at the beginning of your statement and check what the Template Template:Infobox Country or territory dpl produces. Gero 10:34, 4 April 2008 (CEST)

1

{{#arraydefine:x|

There was a basic version of this extension some time ago. Later it was enhanced by many new features and the name was changed to DynamicPageList2. The new version was no longer downward compatible. At the same time the name of the original extension was changed to 'Intersection' (but the documentation kept talking of DynamicPageList and the tag name still was <DynamicPageList>).

Some time later another bunch of features had been added. And the name was changed back to DynamicPageList (which was thought to be 'free').

Meanwhile some new features had also been added to 'Intersection' and recently 'Intersection' requested its original name back - which caused a real lot of confusion regarding the naming.

Currently (as of June 2009) the status is as follows:

  • Some wikimedia websites like wikinews use the old version. They call it 'Intersection' or 'DynamicPageList'. Its tag is <DynamicPageList> and the sources are in the mediawiki SVN under the path name 'DynamicPageList'.
  • Some other websites switched to DynamicPageList2 - a version which is commonly considered to be obsolete by now. They may want to change to DPL as it is 95% downward compatible with DPL2.
  • Quite a lot of websites use DPL now, i.e. the extension distributed on this website. They call it DPL or DynamicPageList. It uses the tag <dpl> and in addition offers the parser function {{#dpl: ....}}. The source is available here under Download.

There is an opinion which says that running DPL on a major public website would introduce the risk that people write queries which consume a lot of resources. And apart from there is the problem of incompatibilities between 'Intersection' and DPL.

It is time to put an end to this mess.
  • A large effort was recently put into DPL to make it functionally 100% downward compatible with 'Intersection'. Missing commands were added and the semantics of some existing commands were slightly altered. For details read the chapter on DPL:Manual - Compatibility.
  • A concept of functional restrictions was introduced which allows it to configure DPL with different levels of functionality. The lowest level corresponds exactly to 'Intersection' as of today.
  • An advanced caching concept was introduced which makes it possible to save the result of DPL queries independent from the rest of a page. This means that this DPL cache even survives edit actions of the page containing the DPL invocation - as long as the DPL statement itself is not changed.
So, in near future there will only be one extension named DynamicPageList(DPL) which unites all previous branches.

° In the standard configuration DPL registers the <DynamicPageList> tag. This is needed to be downward compatible with extension 'Intersection'.

In the transition phase you may want to install DPL in PARALLEL to 'Intersection' for testing. DPL offers a second entry point for that purpose. Instead of require_once("DynamicPageList.php") you have to use require_once("DPLMigration.php"). DPL will then ONLY register a tag called <Intersection>

In this constellation you can change some of your existing calls of 'Intersection' (which use the <DynamicPageList> tag) to the <Intersection> tag. Once you are convinced that this produces identical results and works with equal efficiency you can change to require_once("DynamicPageList.php"). Don't forget to change the statements back to the <DynamicPageList> tag!. Of course you must also remove the require_once() for the Intersection extension. ° The general approach to output formatting is two-fold:

  1. There are a couple of simple predefined output formats which generate lists of articles
    You will understand their meaning directly from reading
  2. There is a mode called "userformat" which puts complete control into your hands
    This is somewhat complicated.

While the standard output formats are meant to be used for fast generation of simple page lists, the userformat approach aims at transcluding contents from other pages and requires some effort to understand. There is a system of three tags which are used to enclose (a) the whole output, (b) each item, (c) each transcluded section of an item. A fourth tag is used to separate values between items of one section which occur more than once.

We assume that we have two documents which use templates x and y with varying arguments; while x is being used once within each document, y is used several times. In very short notation the structure might look as follows:

A: x(a) y(3) y(5)
B: x(b) y(4) y(1) y(2)

The following DPL parameters are used to define a set of tags which are used to construct the output:

The arguments of the above statements can contain references to %VARIABLES%. So sec-1-start might contain a reference like %PAGE% to output the page name. See format for more details on variable substitution.

Now think of the following page inclusion statement:

 includepage={x}.dpl,{y}.dpl

The output will then look like this:

 liststart
    itemstart
       sec-1-start
          x.dpl(a)
       sec-1-end
       sec-2-start
          y.dpl(3)
          multi-sep
          y.dpl(5)
       sec-2-end
    itemend
    itemstart
       sec-1-start
          x.dpl(b)
       sec-1-end
       sec-2-start
          y.dpl(4)
          multi-sep
          y.dpl(1)
          multi-sep
          y.dpl(2)
       sec-2-end
    itemend
 listend

Assuming that the tags (liststart, itemstart, etc.) contain wiki syntax for table definitions and multi-sep defines a horizontal line, the output might look like this:

 +------+---------------------+
 |      |          | y.dpl(3) |
 |  A   | x.dpl(a) |  ----    |
 |      |          | y.dpl(5) |
 +------+----------+----------+
 |      |          | y.dpl(4) |
 |      |          |  ----    |
 |  B   | x.dpl(b) | y.dpl(1) |
 |      |          |  ----    |
 |      |          | y.dpl(2) |
 +------+----------+----------+

In some situations, however, you may want to create an output table where each of the calls of template y is used to create a separate output row. Using a sortable table you could then easily rearrange the output.

 +------+---------------------+       +------+---------------------+
 |  A   | x.dpl(a) | y.dpl(1) |       |  B   | x.dpl(b) | y.dpl(1) |
 +------+---------------------+       +------+---------------------+
 |  A   | x.dpl(a) | y.dpl(2) |       |  B   | x.dpl(b) | y.dpl(2) |
 +------+---------------------+       +------+---------------------+
 |  B   | x.dpl(b) | y.dpl(3) |       |  A   | x.dpl(a) | y.dpl(3) |
 +------+---------------------+       +------+---------------------+
 |  B   | x.dpl(b) | y.dpl(4) |       |  A   | x.dpl(a) | y.dpl(4) |
 +------+---------------------+       +------+---------------------+
 |  B   | x.dpl(b) | y.dpl(5  |       |  B   | x.dpl(b) | y.dpl(5) |
 +------+---------------------+       +------+---------------------+

There is a special parameter called dominantsection which you can use to mark one section of your includepage statement as "dominant" (in our example: dominatsection=2 as {y}.dpl is the second argument of our includepage statement). You can only have one dominant section in a DPL statement. Marking a section as "dominant" only makes sense if you have multiple calls of the same template (or multiple chapters with the same heading) in your documents. Each piece of content in the dominant section will generate an individual output row with the values of all other columns being repeated.


As all of the above is not very easy to understand there are additional DPL commands (table, tablerow) which make it fairly easy to create tabular output. °°

updaterules define a set of rules which are executed to perform an update on selected articles (bulk update or template value editing)

Syntax:

updaterules=
    rule;
    ...
    rule;

Where rule is one of the following:

  • rules for batch update of articles
   replace   pattern;
      by        replacement;
   before    pattern;
      insert    text;
   after     pattern;
      insert    text;
  • rules for interactive update of articles
   template  template name;
   legend    legend article name;
   table     table format;
   editform  form parameters;
   action    form action;
   hidden    value;
   submit    submit button;
   commit    commit button;
   parameter parameter name;
      value      value;
      format     display format;
      tooltip    text;
      optional   value;
      afterparm  parameter name;
  • common rules
   summary   edit summary text;
   exec      value;

The first group of rules is intended for batch updates of articles. A DPL query can select a group of articles and perform updates like inserting a piece of text at a certain position or changing text portions based on regular expressions.

The second group of rules is intended for interactive form-based editing of template values.

The third group of rules is common to both other groups and controls the update process.

The updaterules feature is intended for wiki expert users only. It is recommended that articles usind this statement are 'protected':

°° The code of this extenstion uses some MySQL-specific functions which don't exist in PostgreSQL. In order to avoid patching each new version of DyanmicPageList, I suggest to run the following script on your postgres Database (from the postgres account). This simply emulates the MySQL functions.

create schema mysql;

grant usage on schema mysql to public;

alter user wikiuser set search_path to mediawiki, public, mysql;

create or replace function mysql.concat(text, text) returns text
as $function$
  begin
    return $1 || $2;
  end;
$function$ language plpgsql immutable strict;

create or replace function mysql.if(boolean, text, text) returns text
as $function$
  begin
    if $1 then
      return $2;
    else
      return $3;
    end if;
  end;
$function$ language plpgsql immutable strict;

create or replace function mysql.ifnull(text, text) returns text
as $function$
    select coalesce($1, $2) as result
$function$ language 'sql';

°

  {{#dplreplace:text|pattern|replacement}}

°

 (1) {{#dplvar:set    |name1|value1|name2|value2|..|..}}
 (2) {{#dplvar:default|name|value}}
 (3) {{#dplvar:        name}}

°

 {{#dplchapter: text | heading | limit | page | linktext }}

°|°}} {{#arraysort:x|random}} {{#arrayindex:x|0}}

3

2

Country Official Name Capital Dial Code
DPL Example 007 main page 1 (%COUNT%) Template:Country dpl.default
Nigunda (%COUNT%) Republic of Nigunda Bamitogoo 237
Nigunda Test (%COUNT%) Republic of Nigunda Test Bamitogoo Test 237
Somango (%COUNT%) Somango Island Aaaabququque 224

Number of data = 1

No Name Languages Government Area Population GDP Independence Day
1 Republic of Cameroon French,English Republic 183,568 sq mi 17,795,000 $43.196 billion 01/10/1961

%TOTALPAGES%

{{#dpl: category=African_Union_member_states¦Cities|resultsheader=%PAGES%|noresultsheader=none|mode=userformat

9

{{#dpl: category=African_Union_member_states¦Cities|resultsheader=%TOTALPAGES%|noresultsheader=none|mode=userformat

9

1 3.2.1

 good morning! 

{{PAGENAME}} DPL Invoking Example

LOL!!!
the {{PAGENAME}} is Sandbox