r61197 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61196‎ | r61197 | r61198 >
Date:04:11, 18 January 2010
Author:nad
Status:deferred
Tags:
Comment:
a bit more on the 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
@@ -321,7 +321,7 @@
322322 /**
323323 * Return an array of records given type and other criteria
324324 */
325 - function getRecords( $type, $posted, $operator, $wpTitle = '', $invert = false, $orderby = 'created desc' ) {
 325+ function getRecords( $type, $posted, $operator, $wpTitle = '', $invert = false, $orderby = 'created desc', $groupby = false, $format = false ) {
326326 global $wgRequest;
327327
328328 # If the page is already rendered, don't run this query
@@ -357,14 +357,7 @@
358358 if ( $v && !( $i && $this->cmpCallback( $r[$k], $v, $operator[$k] ) ) ) $match = false;
359359 }
360360 if ( $invert ) $match = !$match;
361 - if ( $match ) {
362 - if ( $group ) {
363 - $records[] = $r;
364 - }
365 - else {
366 - $records[] = $r;
367 - }
368 - }
 361+ if ( $match ) $records[] = $r;
369362 }
370363 }
371364 $dbr->freeResult( $res );
@@ -396,6 +389,24 @@
397390 if ( $this->desc = eregi( ' +desc *$', $orderby ) ) $orderby = eregi_replace( ' +desc *$', '', $orderby );
398391 $this->orderBy = $orderby;
399392 usort( $records, array( $this, 'sortCallback' ) );
 393+
 394+ # Group the records according to the "groupby" parameter
 395+ if ( $groupby ) {
 396+ if ( !is_array( $groupby ) ) $groupby = split( '/\s*,\s*/', $groupby );
 397+ $tmp = array();
 398+ foreach ( $records as $r ) {
 399+ $v0 = $r[$groupby[0]];
 400+ if ( $groupby[1] ) {
 401+ $v1 = $r[$groupby[1]];
 402+ if ( !in_array( $tmp[$v0] ) ) $tmp[$v0] = array();
 403+ $tmp[$v0][$v1] = $r;
 404+ } else $tmp[$v0] = $r;
 405+ }
 406+ $records = $tmp;
 407+ }
 408+ $this->groupBy = $groupby;
 409+ $this->format = $format;
 410+
400411 return $records;
401412 }
402413
@@ -883,6 +894,8 @@
884895 elseif ( $k == 'name' ) $name = $v;
885896 elseif ( $k == 'invert' ) $invert = $v;
886897 elseif ( $k == 'orderby' ) $orderby = $v;
 898+ elseif ( $k == 'groupby' ) $groupby = $v;
 899+ elseif ( $k == 'format' ) $format = $v;
887900 elseif ( $k == 'cols' ) $cols = preg_split( '/\s*,\s*/', $v );
888901 elseif ( $k == 'sortable' ) $sortable = eregi( '1|yes|true|on', $v );
889902 elseif ( $k == 'template' ) $template = $v;
@@ -898,7 +911,7 @@
899912 $tmp = $this->type;
900913 $this->preProcessForm( $type );
901914 $this->examineForm();
902 - $records = $this->getRecords( $type, $filter, $op, $title, $invert, $orderby );
 915+ $records = $this->getRecords( $type, $filter, $op, $title, $invert, $orderby, $groupby, $format );
903916 if ( $count ) while ( count( $records ) > $count ) array_pop( $records );
904917 $table = $this->renderRecords( $records, $cols, $sortable, $template, $name, $export );
905918 $this->type = $tmp;
@@ -946,7 +959,7 @@
947960 "rev_id=page_latest AND old_id=rev_text_id AND tl_from=page_id AND tl_title='$type' $regexp",
948961 __METHOD__
949962 );
950 - if ($row) return Title::newFromId( $row->page_id )->getPrefixedText();
 963+ if ( $row ) return Title::newFromId( $row->page_id )->getPrefixedText();
951964 }
952965
953966 return '';
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.9.9, 2010-01-05' );
 15+define( 'RECORDADMIN_VERSION', '0.9.10, 2010-01-18' );
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