Difference between revisions of "Issue:Dates in sortable tables"

From FollowTheScore
Jump to: navigation, search
(Problem)
(Problem)
Line 54: Line 54:
 
</pre>
 
</pre>
  
How is the extra newline added? Is because DPL uses "single bar" table syntax rather then double bar? or is it mediawiki's implementation of tables?
+
The newline seems to come from mediawiki's mapping from pipe syntax to html. If you use "single bar" table syntax then the newline before the bar is included in the table data. If you use a double bar "||" instead of "\n|" for table columns then the a new line is not present in the table data tags. So that works for most columns. However, the last column will still be problematic.
I suggest that the solution is to modify DPL table generation to produce code like the following. Notice that the <nowiki></td></nowiki> is immediately after the content. There can be whitespce between <nowiki></td></nowiki> and the following <nowiki><td></nowiki>
+
 
 +
One solution could be to output HTML code instead of wiki syntax for tables.
 +
 
 +
Notice that the <nowiki></td></nowiki> is immediately after the content. There can be whitespce between <nowiki></td></nowiki> and the following <nowiki><td></nowiki>
 
<pre>
 
<pre>
 
<tr>
 
<tr>

Revision as of 11:41, 10 September 2008

Description: DPL does not allow sortable dates in tables
Extension / Version: DPL   /  
Type / Status: Bug   /   open

Problem

The dpl output for a table in dates in it does not allow mediawiki data-sorting to work correctly.

  • The mediawiki date sorting is very strict (wikibits.js) about what it recognises as a date. For example, for "01/02/2009" to be a date, it must have a length of exactly 10 characters and match a regular expression /^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/ (notice the start and end markers).
  • The output from a DPL table contains extra characters (newline) that mean that an apparent date is not treated as so.
<tr>
<td><a href="/mediawiki/index.php/Cust1" title="Cust1">Cust1</a>
</td><td>01/02/2009
</td></tr>

Test case: Page Template:datetest contains

{{{date}}}

A page contains:

{{datetest|date=01/02/2009}}
{{datetest|date=03/11/2009}}
{{datetest|date=03/10/2009}}
{{datetest|date=03/12/2009}}
{{datetest|date=03/02/2010}}

Then the DPL script:

<dpl>
 uses=Template:Datetest
 include={Datetest}:date
 table=class="wikitable sortable",page,date
</dpl>

Generates this output (after sorting)

C1 	01/02/2009 
C1 	03/11/2009 
C1 	03/10/2009 
C1 	03/12/2009 
C1 	03/02/2010

Note that there is a line in wikibits.js that needs to be carefully adjusted...but in this case, it does not make a difference because the js is failing to recognise it as a date earlier than this.

var ts_europeandate = wgContentLanguage != "en";  //The non-American-inclined can change to "true"

The newline seems to come from mediawiki's mapping from pipe syntax to html. If you use "single bar" table syntax then the newline before the bar is included in the table data. If you use a double bar "||" instead of "\n|" for table columns then the a new line is not present in the table data tags. So that works for most columns. However, the last column will still be problematic.

One solution could be to output HTML code instead of wiki syntax for tables.

Notice that the </td> is immediately after the content. There can be whitespce between </td> and the following <td>

<tr>
<td><a href="/mediawiki/index.php/Cust1" title="Cust1">Cust1</a></td>
<td>01/02/2009</td>
</tr>

Reply

Thanks for the analysis and the suggestion. I will have a look at it. But it may take some weeks. Gero 08:50, 10 September 2008 (UTC)