Extension talk:DataTable

From MediaWiki.org

Jump to: navigation, search

Contents

[edit] Table headers as columns vs. rows

Is there a way to get the table to show each row as a column instead? I've been trying to find a table creation extension that can create this table but am not having much luck... I like the idea of storing/retrieving the data with templates, since that's how other extensions work, but they are limited in how they output the tables as column headers and row entries; I need it reversed. See http://tnlc.com/wiki/index.php?title=Comparison_table for my attempts with 2 extensions so far (4 if you include the semantic stuff). -Eep² 11:27, 29 July 2007 (UTC)

It shouldn't be particularly difficult to enhance the DataTable extension to do that, and it seems an interesting idea to me. When I have some time, I'll work on that (likely to take some week before that happens...) RV1971 13:56, 10 August 2007 (UTC)
Thanks; I look forward to it. I'll be glad to test it, too. :) -Eep² 15:59, 10 August 2007 (UTC)
I noticed you made some contributions recently; have you had time to work on DataTable lately? —Eep² 20:59, 4 September 2007 (UTC)

[edit] Table format

Hi. I hope this is the way to do things, as I'm no programmer, just a hobbyist. I'm trying this very interesting extension, I do think is fantastic. But I'm getting a problem on the first page, the one to take the data into de table.

I just copy & paste the code

<datatable table=demo>
#{|
#|-
{{PAGENAME}}|interesting page|extension description
[[Manual:Contents|Manual]]|very interesting page|manual page
#|}
</datatable>

But instead of a neat and clean table, this is what I get:

| #{| |- | # | - |- | Test incluir datos Datatable | interesting page | extension description |- | Manual | very interesting page | manual page |- | # | } |-

The first record into de table is something like #{|

The second record is #

The last is #

But the retrieving of the data and the rest is working fine, so far.

Can you help me? Thank you so much --Amglez 00:10, 27 January 2008 (UTC)


I got the same result as well and have been able to correct it. The fix takes a few steps:

[edit] step 1. Correct hook syntax

After struggling with the output code for a while I checked the database and found that the the hook doesn't work the way that the example suggests. Executing the example shown above results in five records: two with the correct data and three containing erroneous symbols. If the right symbols are removed, the data goes into the table correctly. Changing the wikitext to include only the data records between the hooks as follows:

<datatable table=demo>
{{PAGENAME}}|interesting page|extension description
[[Manual:Contents|Manual]]|very interesting page|manual page
</datatable>

should result in the following table:

| Test incluir datos Datatable | interesting page | extension description |- | Manual | very interesting page | manual page |- 

[edit] step 2a. Acceptable rendering of input using a template

Correcting the hook syntax puts the correct data into the database table, but the rendering of the input is still not correct. The easiest, but least flexible of two solutions I found for this problem is to use a template. Create a template that uses numbers as the parameters to represent each of the columns in the dataset. Something like:

 {{{1}}} {{{2}}} {{{3}}} {{{4}}} 

then call the template from the tag:

<datatable table=demo template=mytemplatename >
{{PAGENAME}}|interesting page|extension description
[[Manual:Contents|Manual]]|very interesting page|manual page
</datatable>

This is a quick fix, but it doesn't help if you want your output to be shown as table. The DataTable extension calls the template once for each record, so if you set up a table in the template, your output will be a separate table for each record.

[edit] step 2b. Correct rendering of input by fixing the code

It appears that the extension has code that will accurately display the input in table form "if a head tag is passed to the extension". However, it is not clear how to pass the head tag, so I altered the code to render the table without the head tag.

Replace:

      // parse head tag, if any
      if( preg_match( '+<head>(.*)</head>+s', $input, $matches ) )
        {
          $head = $matches[1];
          $input = str_replace( $matches[0], '', $input );
 
          if( $class )
            $class = "class='$class'";
 
          $output .= "{| $class\n|-\n$head\n|-\n";
        }

with:

      // parse head tag, if any
      if( preg_match( '+<head>(.*)</head>+s', $input, $matches ) )
        {
          $head = $matches[1];
          $input = str_replace( $matches[0], '', $input );
 
          if( $class )
            $class = "class='$class'";
 
          $output .= "{| $class\n|-\n$head\n|-\n";
        } else {
          if( $class )
            $class = "class='$class'";
 
          $output .= "{| $class \n|-\n";
        }	

and replace:

      if( $head )
        $output .= "|-\n|}\n";

with:

      $output .= "|-\n|}\n";

[edit] step 3. Passing a table class parameter

Although it is not documented on the extension page, the extension DOES support the use of a table class parameter. After fixing the code, the class parameter may be passed as:

<datatable table=demo class='wikitable' >
{{PAGENAME}}|interesting page|extension description
[[Manual:Contents|Manual]]|very interesting page|manual page
</datatable>

good luck, Furboy 19:33, 18 March 2008 (UTC)


[edit] Documentation of conditional statement usage

Could we see some documentation on how to use the conditional statements? I think it's cool that the extension accepts and can pass links and magic words, but I would like to know how to use them in a conditional statement.

Thanks, Furboy 20:03, 18 March 2008 (UTC)

I would also like to see some documentation on this. I am considering recommending the use of this extension on a wiki I author and am curious if it can be made to display select columns and only display rows in which the variable in one column meets a specified condition. Any help with this question would be much appreciated.
97.83.122.63 23:18, 22 June 2009 (UTC)

[edit] data stored twice

Hello,

I set up this nice extension and it works fine if i put this <datatable table=joueurs display=no> Jean-Pierre_Adams|05/2007|défenseur|france.png|Jean-Pierre_Adams.jpg|Membre de la garde noire, en compagnie de Marius Trésor, Jean-Pierre Adams fut un des piliers de la défense tricolore, avant de sombrer dans le coma à la suite d'une opération au genou.|Autre </datatable>

However, in the datatable_data, in mysql, the data are stored twice, with exactly the same

I don't undesrtand why ? Do have the same issue ? How can it be corrected ?

[edit] Hope to see new version

This is real a nice extension, hope to see new version soon. (the unsigned comment was made by User:Jimmyyami 10:09, 19 July 2008

Same here. It seems the original author is no longer active. Could someone with sufficient programming expertise pick this up, improve it based on the comments and fully document it? I think many MediaWiki users could use a database integration for various purposes. Many thanks! --Vigilius 08:19, 20 July 2008 (UTC)


[edit] SQL injection ???

The columns, condition and sort parameters in the #data parser-extension, seem not to be sanitized at all, and allow for arbitrary SQL statements be injected. Or am I missing something?

[edit] $parser->recursiveTagParse()

Consider to use $parser->replaceVariables() instead to avoid the parser-internal link filtering.

[edit] New version will come

I'm sorry much time has passed since I published the last version of my extension. I have done quite some development in the meatime which also addresses some of the questions raised in the discussion so far. I hope I'll have some time in the next months to write the necessary documentation so that I can publish my current version. RV1971 07:39, 23 June 2009 (UTC)

[edit] $wgDBprefix

I just tried extensions/DataTable/DataTable.php and found that <datatable table=demo>...</datatable> prefixes the tablename by LocalSettings.php's $wgDBprefix and {{#data: ...}} doesn't. so i modified

original:
$res = $dbr->query( "select distinct $columns from datatable_data where dtd_table = '$table' $condition $sort" , __METHOD__ );
to:
global $wgDBprefix;
$res = $dbr->query( "select distinct $columns from ".$wgDBprefix."datatable_data where dtd_table = '$table' $condition $sort" , __METHOD__ );

ro 18:50, 16 August 2009