r100738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100737‎ | r100738 | r100739 >
Date:20:22, 25 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added setting of CSS "column class" for every cell in the table
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php
@@ -35,13 +35,8 @@
3636
3737 $result = '';
3838
39 - $tableRows = array();
 39+ $columnClasses = array();
4040
41 - $rowNum = 1;
42 - while ( $subject = $res->getNext() ) {
43 - $tableRows[] = $this->getRowForSubject( $subject, $outputmode, $rowNum++ );
44 - }
45 -
4641 if ( $this->mShowHeaders != SMW_HEADERS_HIDE ) { // building headers
4742 $headers = array();
4843
@@ -49,6 +44,9 @@
5045 $attribs = array();
5146 $columnClass = str_replace( array( ' ', '_' ), '-', $pr->getText( SMW_OUTPUT_WIKI ) );
5247 $attribs['class'] = $columnClass;
 48+ // Also add this to the array of classes, for
 49+ // use in displaying each row.
 50+ $columnClasses[] = $columnClass;
5351 $text = $pr->getText( $outputmode, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null : $this->mLinker ) );
5452
5553 $headers[] = Html::rawElement(
@@ -63,9 +61,16 @@
6462 if ( $outputmode == SMW_OUTPUT_HTML ) {
6563 $headers = '<thead>' . $headers . '</thead>';
6664 }
67 -
 65+ $headers = "\n$headers\n";
 66+
6867 $result .= $headers;
6968 }
 69+
 70+ $tableRows = array();
 71+ $rowNum = 1;
 72+ while ( $subject = $res->getNext() ) {
 73+ $tableRows[] = $this->getRowForSubject( $subject, $outputmode, $columnClasses, $rowNum++ );
 74+ }
7075
7176 $tableRows = implode( "\n", $tableRows );
7277
@@ -108,11 +113,12 @@
109114 *
110115 * @return string
111116 */
112 - protected function getRowForSubject( array /* of SMWResultArray */ $subject, $outputmode, $rowNum ) {
 117+ protected function getRowForSubject( array /* of SMWResultArray */ $subject, $outputmode, $columnClasses, $rowNum ) {
113118 $cells = array();
114119
115 - foreach ( $subject as $field ) {
116 - $cells[] = $this->getCellForPropVals( $field, $outputmode );
 120+ foreach ( $subject as $i => $field ) {
 121+ $columnClass = $columnClasses[$i];
 122+ $cells[] = $this->getCellForPropVals( $field, $outputmode, $columnClass );
117123 }
118124
119125 $rowClass = ( $rowNum % 2 == 1 ) ? 'row-odd' : 'row-even';
@@ -129,7 +135,7 @@
130136 *
131137 * @return string
132138 */
133 - protected function getCellForPropVals( SMWResultArray $resultArray, $outputmode ) {
 139+ protected function getCellForPropVals( SMWResultArray $resultArray, $outputmode, $columnClass ) {
134140 $dataValues = array();
135141
136142 while ( ( $dv = $resultArray->getNextDataValue() ) !== false ) {
@@ -151,7 +157,8 @@
152158 if ( in_array( $alignment, array( 'right', 'left', 'center' ) ) ) {
153159 $attribs['style'] = "text-align:' . $alignment . ';";
154160 }
155 -
 161+ $attribs['class'] = $columnClass;
 162+
156163 $content = $this->getCellContent(
157164 $dataValues,
158165 $outputmode,

Follow-up revisions

RevisionCommit summaryAuthorDate
r101782Fix for r100738 - added handling if CSS classes for columns aren't setyaron02:53, 3 November 2011