Talk:WikiDB/Repeat tag syntax/Archive

From TestWiki
< Talk:WikiDB‎ | Repeat tag syntax
Revision as of 01:53, 10 December 2008 by HappyDog (Talk | contribs) (Oops - last edit had wrong summary, and wasn't quite finished. Completed now with a few more moves from Talk:WikiDB.)

Jump to: navigation, search

Table Formatting

Moved from Talk:WikiDBdiff

Hi. I love this use for the Wiki, but I've had one frustration - getting formatted tables. To that end, I have made a modification for my own use, and am passing it on. Feel free to include, ignore, whatever. I just thought it might be useful. I have added two internal tags to the repeat command so that there can be footers and headers added to the output produced from the repeat tag.

The trouble was produced because something like:

{|
<repeat table="foo">
|{{{colA}}}
|{{{colB}}}
|-
</repeat>
|}

gives totally useless results, and after looking at the MediaWiki Parser.php file, it turns out that unless that is rewritten, it always will - the table parsing is all one-pass, and doesn't preserve state while in an extension.

So, I have turned that into:

{|
<repeat table="foo">
<header>
{|
</header>
|{{{colA}}}
|{{{colB}}}
|-
<footer>
|}
</footer>
</repeat>
|}

Which now gives the right results. Of course, this requires the following code I added (I know it is rudimentary, but it works...)

Change to WikiDB.php

                $Data = $Table->PerformQuery($Where, $Sort);
		if (trim($Input) == "")
			$Output = $Table->FormatTableData($Data);
		else 
		{
			$outputDef = new WikiDB_OutputFormatDef($Input);
			
			$Output = "";
			$Data = $Table->NormaliseData($Data);
//			print_r($Data);

			if($outputDef->hasHeader())
			{
				$Output .= $outputDef->getHeader() . "\n";
			}
			
			$RowFormat = $outputDef->getRow();
			foreach ($Data as $Row)
			{
				$Output .= pWikiDB_ExpandVariables($RowFormat, $Row);
			}
			
			if($outputDef->hasFooter())
			{
				$Output .= $outputDef->getFooter() . "\n";
			}
//			print($Output);
		}

Also, you must include the following file:

classWikiDB_OutputFormatDef.php

<?php

class WikiDB_OutputFormatDef 
{
	var $sHeader;
	var $sFooter;
	var $sRow;
	
	function WikiDB_OutputFormatDef($contents)
	{
		$this->sHeader = $this->stripTagItem($contents, 'header');
		$this->sFooter = $this->stripTagItem($contents, 'footer');
		$this->sRow		= $contents;
	}
	
	function hasHeader(){ return strlen($this->sHeader) > 0; }
	function hasFooter(){ return strlen($this->sFooter) > 0; }
	
	function getHeader(){ return $this->sHeader; }
	function getFooter(){ return $this->sFooter; }
	function getRow()   { return $this->sRow; }
	
	function stripTagItem(&$text, $tag)
	{
		$tagLen = strlen($tag);
		
		$start = stripos($text, '<' . $tag . '>');
		if($start == FALSE)
		{
			return '';
		}
		
		$end = stripos($text, '</' . $tag . '>');
		if($end == FALSE)
		{
			return '';
		}
		
		$tagTextStart  = $start+$tagLen+2;
		$tagTextLength = $end - $tagTextStart - 1;
		$tagTextEnd    = $end + $tagLen + 3;
		
		$tagContents = substr($text, $tagTextStart, $tagTextLength);
		//strip out the tag
		$text = substr($text, 0, $start) . substr($text, $tagTextEnd);
		
		return $tagContents;
	}
	
}  //END: Class WikiDB_OutputFormatDef

?>

Thanks!

-Jacob 15:50, 8 April 2007 (BST)

Slight Modifications

I integrated your code into my working wiki, because I too saw the uselessness of the table formatting with the repeat tag. However, I made a couple other changes:

  • the table begin and end before and after the repeat are not needed, correct? (the header and footer tags print them)
  • It seems like the table code was inserting an extra line break in the raw input, which was causing a "br" tag in the output, which was skewing the last column of each table row. To change this, I added the last line here:
if (trim($Input) == "")
  $Output = $Table->FormatTableData($Data);
else {
  $Input = trim($Input); // get rid of extra line breaks
  • However, the trim broke the tag processing in the OutputFormatDef file. On the lines "if $start == FALSE" and "if $end == false", I changed the "==" to "===" to be a more correct equality test, since after the trim those tags for me were in position 0 (== FALSE, but not ===FALSE).
  • Finally, "stripos" only works on PHP5, so I changed the 2 lines that use strpos as follows:
OLD: stripos($text, '<' . $tag . '>'));
NEW: strpos($text, strtolower('<' . $tag . '>'));

Thanks for your help and work on this. It's a cool extension.

-- Joe Clark (a guest, joeclark AT joeclarkia DOT net)

Using the <repeat> tag to display filtered/sorted Tables

Moved from Talk:WikiDBdiff

I have a suggestion to efficiently display tables using the <repeat> tag when a table has a very large number of fields that a user may want to only see a small portion of the fields.

Expand the parameters of the <repeat> tag such that somehow a user can specify which fields to display in the rendered wiki page. Perhaps this need be only one additional parameter that contains a comma separated list of field names to display whilst not displaying all other fields in the specified table.

Example:

Suppose a table called "Stock Investments" contains the following fields: "stock_symbol", "name", "ceo_name", "address", "main_phone", "annual_revenue", "website", "current_stock_price", "my_shares_count".

There are 9 fields in this table such that when the current <repeat> tag was used to display a sorted and/or filtered table of this table, the rendered table in the browser may proceed beyond the right edge of the screen, so perhaps the <repeat> tag could have a new parameter, filter_columns, that is used as such:

<repeat table="Stock Investments" sort="stock_symbol" filter_columns="stock_symbol,name,current_stock_price,my_shares_count,annual_revenue"></repeat>

And this usage of the <repeat> tag would yield a table such as the following with ONLY the columns specified in the filter_columns parameter AND in the order specified.

Stock Investments
stock_symbol name current_stock_price my_shares_count annual_revenue
AMD AMD, Inc 14.30 100 5.649B
KEI Keithley Instruments, Inc 20 12.55 0.155B
MSFT Microsoft, Inc 29.47 25 44.282B

This feature would be very useful and I recommend including support for this feature in WikiDB.

Thanks! -- Mdrayman 22:02, 30 June 2007 (BST)

There are a lot of syntax issues with the repeat tag at present, so I need to get those resolved first. It may be that after the fix-up this kind of thing will be sufficiently simple not to warrant a separate syntax, however if this is not the case then it is a good suggestion, and one I will revisit when the other issues are fixed. --HappyDog 13:35, 4 July 2007 (BST)

Adding table properties within repeat tag

Moved from Talk:WikiDBdiff

Could you please provide a patch which enables extensions to <repeat> tag for adding custom attributes for <table> generated by default? This can be the alternative to missing table formating within <repeat>. Especially, I need "style" and "class" attributes to be added to default table output so I can format this table as required and apply the sortable property.

Hi - The table formatting code is in a bit of a mess at the moment (as is quite a lot of the code...!) and I am in the process of tidying it all up at the moment. I'm quite a long way through this process, but haven't touched on the formatting yet. When I do I'll make it a bit more flexible. All of the major elements that the extension outputs will have a class defined for them, so you can style these as you need. If you need the ability to add your own custom classes as well then I don't see a problem with adding that feature. --HappyDog 12:05, 5 February 2008 (GMT)