Netbrain has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/66379


Change subject: Added a new parameter to table format. tableheader={left/top} 
where top is default.
......................................................................

Added a new parameter to table format.
tableheader={left/top} where top is default.

By setting this parameter to left, all table headers (<th>) will be
moved to the left hand of the table. effectively making the table
read from left to right, instead of top to down.

Unfortunately this setting disables table sorting, as the current
javascript code expects to find all table headers on a single row
containing only 'th' tags

Example of table top view:
|----|----|----|
| H1 | H2 | H3 |
|----|----|----|
| AA | AA | AA |
|----|----|----|
| BB | BB | BB |
|----|----|----|

Example of table left view:
|----|----|----|
| H1 | AA | BB |
|----|----|----|
| H2 | AA | BB |
|----|----|----|
| H3 | AA | BB |
|----|----|----|

Change-Id: If673cdbf5da3a5a78eb8746fccb5c136848b23d3
---
M includes/queryprinters/SMW_QP_Table.php
M languages/SMW_Messages.php
2 files changed, 58 insertions(+), 35 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/79/66379/1

diff --git a/includes/queryprinters/SMW_QP_Table.php 
b/includes/queryprinters/SMW_QP_Table.php
index 714d649..11c4e82 100644
--- a/includes/queryprinters/SMW_QP_Table.php
+++ b/includes/queryprinters/SMW_QP_Table.php
@@ -32,21 +32,11 @@
                                $columnClasses[] = $columnClass;
                                $text = $pr->getText( $outputmode, ( 
$this->mShowHeaders == SMW_HEADERS_PLAIN ? null : $this->mLinker ) );
                                
-                               $headers[] = Html::rawElement(
-                                       'th',
-                                       $attribs,
-                                       $text === '' ? '&nbsp;' : $text
+                               $headers[] = array(
+                                       'attrib' => $attribs,
+                                       'content' => $text === '' ? '&nbsp;' : 
$text,
                                );
                        }
-                       
-                       $headers = '<tr>' . implode( "\n", $headers ) . '</tr>';
-                       
-                       if ( $outputmode == SMW_OUTPUT_HTML ) {
-                               $headers = '<thead>' . $headers . '</thead>'; 
-                       }
-                       $headers = "\n$headers\n";
-
-                       $result .= $headers;
                }
                
                $tableRows = array();
@@ -55,27 +45,49 @@
                        $tableRows[] = $this->getRowForSubject( $subject, 
$outputmode, $columnClasses, $rowNum++ );
                }
 
-               $tableRows = implode( "\n", $tableRows );
-               
-               if ( $outputmode == SMW_OUTPUT_HTML ) {
-                       $tableRows = '<tbody>' . $tableRows . '</tbody>'; 
-               }
-               
-               $result .= $tableRows;
-               
-               // print further results footer
-               if ( $this->linkFurtherResults( $res ) ) {
-                       $link = $this->getFurtherResultsLink( $res, $outputmode 
);
-                       $result .= "\t<tr class=\"smwfooter\"><td 
class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . 
$link->getText( $outputmode, $this->mLinker ) . "</td></tr>\n";
-               }
-               
-               // Put the <table> tag around the whole thing
                $tableAttrs = array( 'class' => $this->params['class'] );
                
                if ( $this->mFormat == 'broadtable' ) {
                        $tableAttrs['width'] = '100%';
                }
-               
+
+
+               if($this->params['tableheader'] === 'left'){
+                       foreach($headers as $i => $header){
+                               $headerHtml = 
Xml::tags('th',$header['attrib'],$header['content']);
+                               $cellHtml = '';
+                               foreach ( $tableRows as $j => $row ){
+                                       $cells = $row['content'];
+                                       $cellHtml .= 
Xml::tags('td',$cells[$i]['attrib'],$cells[$i]['content']);
+                               }
+                               $result .= 
Xml::tags('tr',$row['attrib'],$headerHtml.$cellHtml);
+                       }
+
+               }else if($this->params['tableheader'] === 'top'){
+                       $headerHtml = '';
+                       foreach($headers as $i => $cell){
+                               $headerHtml .= 
Xml::tags('th',$cell['attrib'],$cell['content']);
+                       }
+                       $result .= Xml::tags('tr',null,$headerHtml);
+
+                       foreach ( $tableRows as $i => $row ){
+                               $cells = $row['content'];
+                               $cellHtml = '';
+
+                               foreach($cells as $j => $cell){
+                                       $cellHtml .= 
Xml::tags('td',$cell['attrib'],$cell['content']);
+                               }
+                               $result .= 
Xml::tags('tr',$row['attrib'],$cellHtml);
+                       }
+               }
+
+               // print further results footer
+               if ( $this->linkFurtherResults( $res ) ) {
+                       $link = $this->getFurtherResultsLink( $res, $outputmode 
);
+                       $result .= "\t<tr class=\"smwfooter\"><td 
class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . 
$link->getText( $outputmode, $this->mLinker ) . "</td></tr>\n";
+               }
+
+               // Put the <table> tag around the whole thing
                $result = Xml::tags( 'table', $tableAttrs, $result );
 
                $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our 
code can be viewed as HTML if requested, no more parsing needed
@@ -108,7 +120,11 @@
                }
                
                $rowClass = ( $rowNum % 2 == 1 ) ? 'row-odd' : 'row-even';
-               return "<tr class=\"$rowClass\">\n\t" . implode( "\n\t", $cells 
) . "\n</tr>";
+               $row = array(
+                       'content' => $cells,
+                       'attrib' => array('class' => $rowClass),
+               );
+               return $row;
        }
        
        /**
@@ -151,12 +167,12 @@
                                $resultArray->getPrintRequest()->getMode() == 
SMWPrintRequest::PRINT_THIS
                        );
                }
-               
-               return Html::rawElement(
-                       'td',
-                       $attribs,
-                       $content
+
+               return array(
+                       'content' => $content,
+                       'attrib' => $attribs,
                );
+
        }
        
        /**
@@ -199,6 +215,12 @@
                        'default' => 'sortable wikitable smwtable',
                );
 
+               $params['tableheader'] = array(
+                       'name' => 'tableheader',
+                       'message' => 'smw-paramdesc-tableheader',
+                       'default' => 'top',
+               );
+
                return $params;
        }
        
diff --git a/languages/SMW_Messages.php b/languages/SMW_Messages.php
index d9964f8..66bab18 100644
--- a/languages/SMW_Messages.php
+++ b/languages/SMW_Messages.php
@@ -79,6 +79,7 @@
        'smw-paramdesc-embedformat'     => 'The HTML tag used to define 
headings',
        'smw-paramdesc-embedonly'       => 'Display no headings',
        'smw-paramdesc-table-class'     => 'An additional CSS class to set for 
the table',
+       'smw-paramdesc-tableheader' =>  'The position of the table headers 
(left/top)',
        'smw-paramdesc-rdfsyntax'       => 'The RDF syntax to be used',
        'smw-paramdesc-csv-sep'         => 'The separator to use',
        'smw-paramdesc-dsv-separator'   => 'The separator to use',

-- 
To view, visit https://gerrit.wikimedia.org/r/66379
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If673cdbf5da3a5a78eb8746fccb5c136848b23d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Netbrain <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to