r87058 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87057‎ | r87058 | r87059 >
Date:23:42, 27 April 2011
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Extended table rendering function to support adding classes, text and HTML to a cell, rather than only being able to set HTML. Making use of data-sort-value attribute, rather than "hiding" a 0 or 1 in the cell.
Modified paths:
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.dashboard.css (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -33,8 +33,10 @@
3434 /**
3535 * Returns an HTML table containing data from a given two dimensional array.
3636 *
37 - * @param $headings Array: List of rows, each a list of columns (values will be escaped)
38 - * @param $rows Array: List of rows, each a list of columns (values will not be escaped)
 37+ * @param $headings Array: List of rows, each a list of column data (values will be escaped)
 38+ * @param $rows Array: List of rows, each a list of either calss/column data pairs (values will
 39+ * be escaped), or arrays containing attr, text and html fields, used to set attributes, text or
 40+ * HTML content of the cell
3941 * @param $attribs Array: List of HTML attributes to apply to the table
4042 * @return String: HTML table code
4143 */
@@ -61,7 +63,20 @@
6264 foreach ( $row as $class => $column ) {
6365 $attr = is_string( $class )
6466 ? array( 'class' => 'articleFeedback-table-column-' . $class ) : array();
65 - $table .= Html::rawElement( 'td', $attr, $column );
 67+ if ( is_array( $column ) ) {
 68+ if ( isset( $column['attr'] ) ) {
 69+ $attr = array_merge( $attr, $column['attr'] );
 70+ }
 71+ if ( isset( $column['text'] ) ) {
 72+ $table .= Html::element( 'td', $attr, $column['text'] );
 73+ } else if ( isset( $column['html'] ) ) {
 74+ $table .= Html::rawElement( 'td', $attr, $column['html'] );
 75+ } else {
 76+ $table .= Html::element( 'td', $attr );
 77+ }
 78+ } else {
 79+ $table .= Html::rawElement( 'td', $attr, $column );
 80+ }
6681 }
6782 $table .= Html::closeElement( 'tr' );
6883 }
@@ -141,13 +156,18 @@
142157 $row = array();
143158 $row['page'] = $page['page'];
144159 foreach ( $wgArticleFeedbackRatings as $category ) {
145 - $row[] = in_array( $category, $page['categories'] )
146 - ? Html::element(
147 - 'span', array( 'class' => 'articleFeedback-table-cell-bad' ), 0
148 - )
149 - : Html::element(
150 - 'span', array( 'class' => 'articleFeedback-table-cell-good' ), 1
151 - );
 160+ $row[] = array(
 161+ 'attr' => in_array( $category, $page['categories'] )
 162+ ? array(
 163+ 'class' => 'articleFeedback-table-cell-bad',
 164+ 'data-sort-value' => 0
 165+ )
 166+ : array(
 167+ 'class' => 'articleFeedback-table-cell-good',
 168+ 'data-sort-value' => 1
 169+ ),
 170+ 'html' => ' '
 171+ );
152172 }
153173 $rows[] = $row;
154174 }
@@ -228,8 +248,20 @@
229249 'categories' => array( 1, 4 ),
230250 ),
231251 array(
232 - 'page' => 'Test Article',
 252+ 'page' => 'Test Article 1',
233253 'categories' => array( 1, 3 ),
 254+ ),
 255+ array(
 256+ 'page' => 'Test Article 2',
 257+ 'categories' => array( 2, 3 ),
 258+ ),
 259+ array(
 260+ 'page' => 'Test Article 3',
 261+ 'categories' => array( 3, 4 ),
 262+ ),
 263+ array(
 264+ 'page' => 'Test Article 4',
 265+ 'categories' => array( 1, 2 ),
234266 )
235267 );
236268 }
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.dashboard.css
@@ -32,13 +32,9 @@
3333 }
3434
3535 .articleFeedback-table-cell-bad {
36 - display: block;
3736 background-color: #ffcc99;
38 - color: #ffcc99;
3937 }
4038
4139 .articleFeedback-table-cell-good {
42 - display: block;
4340 background-color: #99ff99;
44 - color: #99ff99;
4541 }

Sign-offs

UserFlagDate
Krinkleinspected17:39, 28 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86992Using orange instead of red for "bad".tparscal22:21, 26 April 2011

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   15:04, 28 April 2011

This is related to r86992 - the association tool doesn't seem to work today.

#Comment by Catrope (talk | contribs)   15:06, 28 April 2011

It works fine, you just have to associate in the other direction (i.e. visit r86992 and add this one as a followup), which I just did. I guess this could be a UX improvement.

Status & tagging log