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

From FollowTheScore
Jump to: navigation, search
 
(2 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
  |Version    =  
 
  |Version    =  
 
  |Description = DPL does not allow sortable dates in tables
 
  |Description = DPL does not allow sortable dates in tables
  |Status      = open
+
  |Status      = resolved
 
}}
 
}}
  
Line 68: Line 68:
 
== Reply ==
 
== Reply ==
 
Thanks for the analysis and the suggestion. I will have a look at it. But it may take some weeks. [[User:Gero|Gero]] 08:50, 10 September 2008 (UTC)
 
Thanks for the analysis and the suggestion. I will have a look at it. But it may take some weeks. [[User:Gero|Gero]] 08:50, 10 September 2008 (UTC)
^
+
 
 
== Reply2 ==
 
== Reply2 ==
 
First, I think that wikibits should be more liberal. A trailing \n is perfectly acceptable. Try "debug=5" and you will see that DPL genberates perfect table output (using single pipes). So I see no reason to change anything in DPL.
 
First, I think that wikibits should be more liberal. A trailing \n is perfectly acceptable. Try "debug=5" and you will see that DPL genberates perfect table output (using single pipes). So I see no reason to change anything in DPL.
  
After some experimenting I found a work around (using a phantom template). You can urge DPL to use double pipes and you can add a trailing empty column if the last column makes trouble with sorting. (As an alternative you could swap the columns)
+
Second, after some experimenting I found a work around (using a phantom template). You can urge DPL to use double pipes and you can add a trailing empty column if the last column makes trouble with sorting. (As an alternative you could swap the columns)
  
So, now we have a template called [[Template:Datetest.dpl]]. Note the wiki comment at its end. This comment must be present to enforce a trailing newline. Due to the use of this phantom template the DPL "table" statement must be replaced by an explicit "format" specification and the include statement must refer to the phantom template. So we get:
+
So, now we have a template called [[Template:Datetest.dpl]]. Note the wiki comment in its last line (see the source!). This comment must be present to enforce a trailing newline. Due to the use of this phantom template the DPL "table" statement must now be replaced by an explicit "format" specification and the include statement must refer to the phantom template. So we get:
  
 
<pre>
 
<pre>
Line 84: Line 84:
 
</pre>
 
</pre>
  
And here is the result:
+
<u>And here is the result:</u>
 
<dpl>
 
<dpl>
 
  uses=Template:Datetest
 
  uses=Template:Datetest
Line 92: Line 92:
  
 
:[[User:Gero|Gero]] 15:31, 12 September 2008 (UTC)
 
:[[User:Gero|Gero]] 15:31, 12 September 2008 (UTC)
 +
 +
== Fix to wikibits.js ==
 +
The following fix to skins/common/wikibits.js makes it less picky about this, allowing normal table syntax to be used and dates in the last column.
 +
 +
<pre>
 +
diff wikibits.js wikibits.js.orig
 +
1020,1023d1018
 +
< function trim(stringToTrim) {
 +
<  return stringToTrim.replace(/^\s+|\s+$/g,"");
 +
< }
 +
<
 +
1069c1064
 +
<              var keyText = trim(ts_getInnerText(row.cells[column]));
 +
---
 +
>              var keyText = ts_getInnerText(row.cells[column]);
 +
</pre>
 +
 +
And not forgetting the folloing for European date formats..
 +
<pre>
 +
957,958c957
 +
< //var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"
 +
< var ts_europeandate = true;
 +
---
 +
> var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"
 +
</pre>

Latest revision as of 11:49, 16 October 2008

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

Problem

The dpl output for a table in dates in it does not allow mediawiki date-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)

Reply2

First, I think that wikibits should be more liberal. A trailing \n is perfectly acceptable. Try "debug=5" and you will see that DPL genberates perfect table output (using single pipes). So I see no reason to change anything in DPL.

Second, after some experimenting I found a work around (using a phantom template). You can urge DPL to use double pipes and you can add a trailing empty column if the last column makes trouble with sorting. (As an alternative you could swap the columns)

So, now we have a template called Template:Datetest.dpl. Note the wiki comment in its last line (see the source!). This comment must be present to enforce a trailing newline. Due to the use of this phantom template the DPL "table" statement must now be replaced by an explicit "format" specification and the include statement must refer to the phantom template. So we get:

<dpl>
 uses=Template:Datetest
 include={Datetest}.dpl
 format={¦class=sortable¶!page\n!date\n,,¦} 
</dpl>

And here is the result:

page date
Datetest 01/02/2009
Datetest 03/11/2009
Datetest 03/10/2009
Datetest 03/12/2009
Datetest 03/02/2010
Gero 15:31, 12 September 2008 (UTC)

Fix to wikibits.js

The following fix to skins/common/wikibits.js makes it less picky about this, allowing normal table syntax to be used and dates in the last column.

diff wikibits.js wikibits.js.orig 
1020,1023d1018
< function trim(stringToTrim) {
<   return stringToTrim.replace(/^\s+|\s+$/g,"");
< }
< 
1069c1064
<               var keyText = trim(ts_getInnerText(row.cells[column]));
---
>               var keyText = ts_getInnerText(row.cells[column]);

And not forgetting the folloing for European date formats..

957,958c957
< //var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"
< var ts_europeandate = true;
---
> var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"