Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php |
— | — | @@ -11,30 +11,50 @@ |
12 | 12 | */ |
13 | 13 | class SMWTableResultPrinter extends SMWResultPrinter { |
14 | 14 | |
| 15 | + protected $mHTMLClass = ''; |
| 16 | + |
| 17 | + public function __construct( $format, $inline, $useValidator = true ) { |
| 18 | + parent::__construct( $format, $inline ); |
| 19 | + $this->useValidator = $useValidator; |
| 20 | + } |
| 21 | + |
15 | 22 | public function getName() { |
16 | 23 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
17 | 24 | return wfMsg( 'smw_printername_' . $this->mFormat ); |
18 | 25 | } |
19 | 26 | |
| 27 | + /** |
| 28 | + * @see SMWResultPrinter::handleParameters |
| 29 | + * |
| 30 | + * @since 1.6 |
| 31 | + * |
| 32 | + * @param array $params |
| 33 | + * @param $outputmode |
| 34 | + */ |
| 35 | + protected function handleParameters( array $params, $outputmode ) { |
| 36 | + parent::handleParameters( $params, $outputmode ); |
| 37 | + if ( array_key_exists( 'class', $params ) ) { |
| 38 | + $this->mHTMLClass = $params['class']; |
| 39 | + } |
| 40 | + } |
| 41 | + |
20 | 42 | protected function getResultText( SMWQueryResult $res, $outputmode ) { |
21 | 43 | global $wgVersion; |
22 | 44 | |
23 | 45 | $tableRows = array(); |
24 | 46 | |
| 47 | + $rowNum = 1; |
25 | 48 | while ( $subject = $res->getNext() ) { |
26 | | - $tableRows[] = $this->getRowForSubject( $subject, $outputmode ); |
| 49 | + $tableRows[] = $this->getRowForSubject( $subject, $outputmode, $rowNum++ ); |
27 | 50 | } |
28 | 51 | |
29 | | - // print header |
30 | | - $result = '<table class="sortable wikitable"' . |
31 | | - ( $this->mFormat == 'broadtable' ? ' width="100%"' : '' ) . |
32 | | - ">\n"; |
33 | | - |
34 | 52 | if ( $this->mShowHeaders != SMW_HEADERS_HIDE ) { // building headers |
35 | 53 | $headers = array(); |
36 | 54 | |
37 | 55 | foreach ( $res->getPrintRequests() as $pr ) { |
38 | 56 | $attribs = array(); |
| 57 | + $columnClass = str_replace( array( ' ', '_' ), '-', $pr->getText( SMW_OUTPUT_WIKI ) ); |
| 58 | + $attribs['class'] = $columnClass; |
39 | 59 | |
40 | 60 | $headers[] = Html::rawElement( |
41 | 61 | 'th', |
— | — | @@ -71,7 +91,18 @@ |
72 | 92 | $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText( $outputmode, $this->mLinker ) . "</td></tr>\n"; |
73 | 93 | } |
74 | 94 | |
75 | | - $result .= "</table>\n"; // print footer |
| 95 | + // Put the <table> tag around the whole thing |
| 96 | + // print header |
| 97 | + $tableClass = "sortable wikitable"; |
| 98 | + if ( !empty( $this->mHTMLClass ) ) { |
| 99 | + $tableClass .= ' ' . $this->mHTMLClass; |
| 100 | + } |
| 101 | + $tableAttrs = array( 'class' => $tableClass ); |
| 102 | + if ( $this->mFormat == 'broadtable' ) { |
| 103 | + $tableAttrs['width'] = '100%'; |
| 104 | + } |
| 105 | + $result = Xml::tags( 'table', $tableAttrs, $result ); |
| 106 | + |
76 | 107 | $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed |
77 | 108 | |
78 | 109 | return $result; |
— | — | @@ -87,14 +118,15 @@ |
88 | 119 | * |
89 | 120 | * @return string |
90 | 121 | */ |
91 | | - protected function getRowForSubject( array /* of SMWResultArray */ $subject, $outputmode ) { |
| 122 | + protected function getRowForSubject( array /* of SMWResultArray */ $subject, $outputmode, $rowNum ) { |
92 | 123 | $cells = array(); |
93 | 124 | |
94 | 125 | foreach ( $subject as $field ) { |
95 | 126 | $cells[] = $this->getCellForPropVals( $field, $outputmode ); |
96 | 127 | } |
97 | 128 | |
98 | | - return "<tr>\n\t" . implode( "\n\t", $cells ) . "\n</tr>"; |
| 129 | + $rowClass = ( $rowNum % 2 == 1 ) ? 'row-odd' : 'row-even'; |
| 130 | + return "<tr class=\"$rowClass\">\n\t" . implode( "\n\t", $cells ) . "\n</tr>"; |
99 | 131 | } |
100 | 132 | |
101 | 133 | /** |
— | — | @@ -170,7 +202,10 @@ |
171 | 203 | } |
172 | 204 | |
173 | 205 | public function getParameters() { |
174 | | - return array_merge( parent::getParameters(), parent::textDisplayParameters() ); |
| 206 | + $params = array_merge( parent::getParameters(), parent::textDisplayParameters() ); |
| 207 | + $params['class'] = new Parameter( 'class', Parameter::TYPE_STRING ); |
| 208 | + $params['class']->setMessage( 'smw-paramdesc-table-class' ); |
| 209 | + return $params; |
175 | 210 | } |
176 | 211 | |
177 | 212 | } |