Extension talk:SimpleTable/Archive

Allow Wiki Text in Dataset
I have modified the script to allow wiki text within the dataset and properly handle the parse reference so it does not conflict with other extensions.

--- (Smcnaught) 20:12, 28 July 2006 (UTC) - I am also available on irc.chekmate.org #MediaWiki

Thanks for your contribution -- that's a big improvement (wish I'd thought of it!). As you'll see, I've moved your version to the main page, and also uploaded an improved version, which also includes your change. Cheers, JohanTheGhost 15:31, 12 April 2007 (UTC)

Quoted strings containing separator literals
I haven't tested this extension yet - though I've wanted one like it for a long time. Does it deal well with quoted strings that contain delimiters? For example:  "field, 1", "field, 2" "field 3", "field 4" Along the same lines, if it does handle quoted strings containing separator literals, does it support quote escaping, or would the user just have to put in &amp;quot;. --Jimbojw 16:05, 12 April 2007 (UTC)


 * No, it doesn't handle quoted delimiters yet; with the most recent enhancement, the idea is that you can pick a non-clashing delimiter.

Having said that, being able to handle quoted delimiters in the style exported by Excel (eg.) would be useful -- I'll look into it. JohanTheGhost 16:45, 19 April 2007 (UTC)

column/row headings
Since most tables usually have column headings (sometimes also row headings), it's be nice if there was an option for this. A simple parameter in the TAB tag (heading=column and/or heading=row) could tell the parser to format the first row/column accordingly. I'll look into it myself when I get around to it, though that might take a few weeks. -- FND 18:44, 12 April 2007 (UTC)

Move to MediaWiki.org
Why is this at Meta - doesn't it belong at MediaWiki.org? -- FND 18:44, 12 April 2007 (UTC)
 * Dude, read the box on the article page! JohanTheGhost 16:41, 19 April 2007 (UTC)

name misleading
As mentioned on MediaWiki-l, the current name of this extension makes it a bit hard to immediately grasp its purpose. The term "tabbed" is reminiscent of things like "tabbed browsing", which might be misleading. "Tabular Data" has been suggested as an alternative, though something like "CSV-Data Tables" might be a more telling name. -- FND 09:52, 13 April 2007 (UTC)

modification: column headings
I've changed and added a few lines of code to allow column headings using the "HEAD" parameter. Unfortunately, I do not know how to make TortoiseSVN create a patch from two local files, so I'll have to post the full code. (Disclaimer: I'm not an experienced coder, and don't know very much about PHP - so the quality of my changes might be questionable... ) -- FND 12:53, 19 April 2007 (UTC)

<?php

/* * Tabbed Data extension. * * This extension implements a simple method to display tabbed data, with a * far simpler markup than the standard Wiki table markup. The goal is to * allow tabular data to be very easily pasted in from an external source, * such as a spreadsheet. The disadvantage is that it doesn't allow for any * fancy formatting; for example, there is no way (as yet) to set row and cell * parameters, including row and cell spanning. However, it makes a very * simple way to include tabular data in a Wiki. * * All you need to do is prepare your data in rows, with fields separated * by tab characters. Excel's "Save as" -> "Text (Tab delimited)" function * saves data in this format. Place the data inside ... tags, * and set any table parameters inside the opening tag; eg.: * *   *   field1\tfield2\t... *   field1\tfield2\t... *   */

$wgExtensionFunctions[] = 'wfTabbedData'; $wgExtensionCredits['parserhook'][] = array( 'name'=>'TabbedData',  'author'=>'Johan the Ghost',  'url'=>'http://meta.wikimedia.org/wiki/TabbedData_extension',  'description'=>'convert tabbed data into a Wiki table', );

/* * Setup TabbedData extension. * Sets a parser hook for. */ function wfTabbedData { new TabbedData; }

class TabbedData {

/*    * The permitted separators. An array of separator style name * and preg pattern to match it. */   private $separators = array(        'space' => "/ /",        'spaces' => "/\s+/",        'tab' => "/\t/",        'comma' => "/,/",    );

/*    * Construct the extension and install it as a parser hook. */   public function __construct { global $wgParser; $wgParser->setHook('tab', array(&$this, 'hookTab')); }

/*    * The hook function. Handles. * Receives the table content and parameters. */   public function hookTab($tableText, $argv, &$parser) { // The default field separator. $sep = 'tab'; // default value for using table headings $head = false;

// Build the table parameters string from the tag parameters. // The 'sep' and 'head' parameters are special, and are handled // here, not passed to the table. $params = ''; foreach (array_keys($argv) as $key) { switch ($key) { case "sep": $sep = $argv[$key]; break; case "head": $head = true; break; default: $params .= ' '. $key. '="' . $argv[$key] . '"'; break; }       }

if (!array_key_exists($sep, $this->separators)) return "Invalid separator: $sep";

// Parse and convert the table body. $wikiText = $this->convertTable($tableText, $this->separators[$sep], $head);

// Wrap the body in table tags, with the table parameters. $wikiTable = " ";

// Done. Parse the result, so that the table can contain Wiki // text. Thanks to Smcnaught. $ret = $parser->parse($wikiTable,                             $parser->mTitle,                              $parser->mOptions,                              false,                              false); return $ret->getText; }

/*    * Convert tabbed data into an HTML table body. */   private function convertTable($tabbed, $pattern, $head) { $wikitab = "";

// Remove initial and final newlines. $tabbed = trim($tabbed);

// Split the input into lines, and convert each line to table format. $lines = preg_split('/\n/', $tabbed); $i = 1; // DEBUG: do PHP loops have an integrated index counter? foreach ($lines as $line) { if ($head && $i == 1) { $cellTag = "th"; } else { $cellTag = "td"; }           $wikitab .= " \n"; $wikitab .= "<". $cellTag. ">"	       . preg_replace($pattern, "<" . $cellTag . ">", $line) . "\n"; $wikitab .= " \n"; $i++; }       return $wikitab; }

}

?>