r61241 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61240‎ | r61241 | r61242 >
Date:05:59, 19 January 2010
Author:nad
Status:deferred
Tags:
Comment:
don't render cols that are used in groupby parameter
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -396,9 +396,11 @@
397397 $tmp = array();
398398 foreach ( $records as $r ) {
399399 $v0 = $r[$groupby[0]];
 400+ unset( $r[$groupby[0]] );
400401 if ( !isset( $tmp[$v0] ) || !is_array( $tmp[$v0] ) ) $tmp[$v0] = array();
401402 if ( isset( $groupby[1] ) ) {
402403 $v1 = $r[$groupby[1]];
 404+ unset( $r[$groupby[1]] );
403405 if ( !isset( $tmp[$v0][$v1] ) || !is_array( $tmp[$v0][$v1] ) ) $tmp[$v0][$v1] = array();
404406 $tmp[$v0][$v1][] = $r;
405407 } else $tmp[$v0][] = $r;
@@ -455,6 +457,7 @@
456458 function renderRecords( $records, $cols = false, $sortable = true, $template = false, $name = 'wpSelect', $export = true, $groupby = false ) {
457459 global $wgParser, $wgTitle, $wgRequest;
458460 if ( count( $records ) < 1 ) return wfMsg( 'recordadmin-nomatch' );
 461+ if ( $groupby ) $groupby = preg_split( '/\s*,\s*/', $groupby );
459462
460463 $special = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
461464 $type = $this->type;
@@ -474,17 +477,21 @@
475478 $class = 'col' . preg_replace( '|\W|', '-', $col );
476479 $th[$col] = "<th class='$class'>$col$br</th>";
477480 }
478 - $ncol = 0;
479 - foreach ( $cols ? $cols : array_keys( $th ) as $col ) {
480 - $html = isset( $th[$col] ) ? $th[$col] : "<th>$col</th>";
481 - $table .= "$html\n";
482 - $ncol++;
 481+ $tmp = array();
 482+ $cols = $cols ? $cols : array_keys( $th );
 483+ foreach ( $cols as $col ) {
 484+ if ( $groupby === false || !in_array( $col, $groupby ) ) {
 485+ $html = isset( $th[$col] ) ? $th[$col] : "<th>$col</th>";
 486+ $table .= "$html\n";
 487+ $tmp[] = $col;
 488+ }
483489 }
 490+ $cols = $tmp;
 491+ $ncol = count( $cols );
484492 $table .= "</tr>\n";
485493
486494 # If using grouping, reconstruct the record tree as a list including headings
487495 if ( $groupby ) {
488 - $groupby = preg_split( '/\s*,\s*/', $groupby );
489496 $td = "<td colspan=\"$ncol\">";
490497 $tmp = array();
491498 foreach( $records as $k1 => $v1 ) {
@@ -539,7 +546,7 @@
540547 'created' => "<td class='col2 col-created'>$tsc</td>\n",
541548 'modified' => "<td class='col3 col-modified'>$tsm</td>\n",
542549 );
543 - foreach ( $cols ? $cols : array_keys( $th ) as $col ) {
 550+ foreach ( $cols as $col ) {
544551 if ( !isset( $row[$col] ) ) {
545552 $v = isset( $r[$col] ) ? $wgParser->parse( $r[$col], $wgTitle, $wgParser->mOptions, true, false )->getText() : '&nbsp;';
546553 $class = 'col' . preg_replace( '|\W|', '-', $col );
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -11,7 +11,7 @@
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
1414
15 -define( 'RECORDADMIN_VERSION', '0.10.1, 2010-01-19' );
 15+define( 'RECORDADMIN_VERSION', '0.10.2, 2010-01-19' );
1616
1717 $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type
1818 $wgRecordAdminCategory = 'Records'; # Category containing record types

Status & tagging log