Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -353,7 +353,7 @@ |
354 | 354 | $ek = str_replace( '|', '\|', $k ); |
355 | 355 | if ( !preg_match( "|\s*\|\s*$ek\s*=|", $text ) ) $text .= "\n|$k=\n|"; # Treat non-existent fields as existing but empty |
356 | 356 | $i = preg_match( "|^\s*\|\s*$ek\s*= *(.*?) *(?=^\s*[\|\}])|sm", $text, $m ); |
357 | | - $r[$k] = isset( $m[1] ) ? $m[1] : ''; |
| 357 | + $r[$k] = trim( isset( $m[1] ) ? $m[1] : '' ); |
358 | 358 | if ( $v && !( $i && $this->cmpCallback( $r[$k], $v, $operator[$k] ) ) ) $match = false; |
359 | 359 | } |
360 | 360 | if ( $invert ) $match = !$match; |
— | — | @@ -392,19 +392,18 @@ |
393 | 393 | |
394 | 394 | # Group the records according to the "groupby" parameter |
395 | 395 | if ( $groupby ) { |
396 | | - if ( !is_array( $groupby ) ) $groupby = split( '/\s*,\s*/', $groupby ); |
| 396 | + $groupby = preg_split( '/\s*,\s*/', $groupby ); |
397 | 397 | $tmp = array(); |
398 | 398 | foreach ( $records as $r ) { |
399 | 399 | $v0 = $r[$groupby[0]]; |
400 | | - if ( $groupby[1] ) { |
| 400 | + if ( isset( $groupby[1] ) ) { |
401 | 401 | $v1 = $r[$groupby[1]]; |
402 | | - if ( !in_array( $tmp[$v0] ) ) $tmp[$v0] = array(); |
| 402 | + if ( !isset( $tmp[$v0] ) || !is_array( $tmp[$v0] ) ) $tmp[$v0] = array(); |
403 | 403 | $tmp[$v0][$v1] = $r; |
404 | 404 | } else $tmp[$v0] = $r; |
405 | 405 | } |
406 | 406 | $records = $tmp; |
407 | 407 | } |
408 | | - $this->groupBy = $groupby; |
409 | 408 | $this->format = $format; |
410 | 409 | |
411 | 410 | return $records; |
— | — | @@ -452,7 +451,7 @@ |
453 | 452 | /** |
454 | 453 | * Render a set of records returned by getRecords() as an HTML table |
455 | 454 | */ |
456 | | - function renderRecords( $records, $cols = false, $sortable = true, $template = false, $name = 'wpSelect', $export = true ) { |
| 455 | + function renderRecords( $records, $cols = false, $sortable = true, $template = false, $name = 'wpSelect', $export = true, $groupby = false ) { |
457 | 456 | global $wgParser, $wgTitle, $wgRequest; |
458 | 457 | if ( count( $records ) < 1 ) return wfMsg( 'recordadmin-nomatch' ); |
459 | 458 | |
— | — | @@ -474,59 +473,81 @@ |
475 | 474 | $class = 'col' . preg_replace( '|\W|', '-', $col ); |
476 | 475 | $th[$col] = "<th class='$class'>$col$br</th>"; |
477 | 476 | } |
| 477 | + $ncol = 0; |
478 | 478 | foreach ( $cols ? $cols : array_keys( $th ) as $col ) { |
479 | 479 | $html = isset( $th[$col] ) ? $th[$col] : "<th>$col</th>"; |
480 | 480 | $table .= "$html\n"; |
| 481 | + $ncol++; |
481 | 482 | } |
482 | 483 | $table .= "</tr>\n"; |
483 | 484 | |
| 485 | + # If using grouping, reconstruct the record tree as a list including headings |
| 486 | + if ( $groupby ) { |
| 487 | + $groupby = preg_split( '/\s*,\s*/', $groupby ); |
| 488 | + $td = "<td colspan=\"$ncol\">"; |
| 489 | + $tmp = array(); |
| 490 | + foreach( $records as $k1 => $v1 ) { |
| 491 | + if ( empty( $k1 ) ) $k1 = wfMsg( 'recordadmin-notset', $groupby[0] ); |
| 492 | + $tmp[] = "$td<h2>$k1</h2></td>\n"; |
| 493 | + foreach( $v1 as $k2 => $v2 ) { |
| 494 | + if ( isset( $groupby[1] ) ) { |
| 495 | + if ( empty( $k2 ) ) $k2 = wfMsg( 'recordadmin-notset', $groupby[1] ); |
| 496 | + $tmp[] = "$td<h3>$k2</h3></td>\n"; |
| 497 | + foreach( $v2 as $v3 ) $tmp[] = $v3; |
| 498 | + } else $tmp[] = $v2; |
| 499 | + } |
| 500 | + } |
| 501 | + $records = $tmp; |
| 502 | + } |
| 503 | + |
484 | 504 | # Table rows |
485 | 505 | $stripe = ''; |
486 | 506 | foreach ( $records as $r ) { |
487 | | - |
488 | | - # Create special values for this row |
489 | | - $tsc = $this->formatDate( $r['created'] ); |
490 | | - $tsm = $this->formatDate( $r['modified'] ); |
491 | | - $t = $r[0]; |
492 | | - $u = $t->getLocalURL(); |
493 | | - $col = $r['title']; |
494 | | - $ecol = urlencode( $col ); |
495 | | - $sel = "<input type='checkbox' name='{$name}[]' value='$col' checked />"; |
496 | 507 | $stripe = $stripe ? '' : ' class="stripe"'; |
497 | 508 | $table .= "<tr$stripe>"; |
| 509 | + if ( !is_array( $r ) ) $table .= $r; # Just add as HTML content if not a row |
| 510 | + else { |
498 | 511 | |
499 | | - # Render this row |
500 | | - if ( $template ) { |
501 | | - $text = '{'.'{'."$template|select=%SELECT%|title=$col|created=$tsc|modified=$tsm"; |
502 | | - foreach ( array_keys( $this->types ) as $col ) { |
503 | | - $v = isset( $r[$col] ) ? $r[$col] : ''; |
504 | | - $text .= "|$col=$v"; |
505 | | - } |
506 | | - $text .= '}}'; |
507 | | - $text = $wgParser->parse( $text, $wgTitle, $wgParser->mOptions, true, false )->getText(); |
508 | | - $text = preg_replace( "|<(/?td.*?)>|", "<$1>", $text ); |
509 | | - $text = str_replace( '%SELECT%', $sel, $text ); |
510 | | - $table .= "$text\n"; |
511 | | - } |
512 | | - else { |
513 | | - $row = array( |
514 | | - 'select' => "<td class='col-select'>$sel</td>\n", |
515 | | - 'title' => "<td class='col0 col-title'><a href='$u'>$col</a></td>", |
516 | | - 'actions' => "<td class='col1 col-actions'><a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$ecol" ) . "'>" |
517 | | - . wfMsg( 'recordadmin-editlink' ) . "</a></td>", |
518 | | - 'created' => "<td class='col2 col-created'>$tsc</td>\n", |
519 | | - 'modified' => "<td class='col3 col-modified'>$tsm</td>\n", |
520 | | - ); |
521 | | - foreach ( $cols ? $cols : array_keys( $th ) as $col ) { |
522 | | - if ( !isset( $row[$col] ) ) { |
523 | | - $v = isset( $r[$col] ) ? $wgParser->parse( $r[$col], $wgTitle, $wgParser->mOptions, true, false )->getText() : ' '; |
524 | | - $class = 'col' . preg_replace( '|\W|', '-', $col ); |
525 | | - $row[$col] = "<td class='$class'>$v</td>"; |
| 512 | + # Create special values for this row |
| 513 | + $tsc = $this->formatDate( $r['created'] ); |
| 514 | + $tsm = $this->formatDate( $r['modified'] ); |
| 515 | + $t = $r[0]; |
| 516 | + $u = $t->getLocalURL(); |
| 517 | + $col = $r['title']; |
| 518 | + $ecol = urlencode( $col ); |
| 519 | + $sel = "<input type='checkbox' name='{$name}[]' value='$col' checked />"; |
| 520 | + |
| 521 | + # Render this row |
| 522 | + if ( $template ) { |
| 523 | + $text = '{'.'{'."$template|select=%SELECT%|title=$col|created=$tsc|modified=$tsm"; |
| 524 | + foreach ( array_keys( $this->types ) as $col ) { |
| 525 | + $v = isset( $r[$col] ) ? $r[$col] : ''; |
| 526 | + $text .= "|$col=$v"; |
526 | 527 | } |
527 | | - $table .= "$row[$col]\n"; |
| 528 | + $text .= '}}'; |
| 529 | + $text = $wgParser->parse( $text, $wgTitle, $wgParser->mOptions, true, false )->getText(); |
| 530 | + $text = preg_replace( "|<(/?td.*?)>|", "<$1>", $text ); |
| 531 | + $text = str_replace( '%SELECT%', $sel, $text ); |
| 532 | + $table .= "$text\n"; |
| 533 | + } else { |
| 534 | + $row = array( |
| 535 | + 'select' => "<td class='col-select'>$sel</td>\n", |
| 536 | + 'title' => "<td class='col0 col-title'><a href='$u'>$col</a></td>", |
| 537 | + 'actions' => "<td class='col1 col-actions'><a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$ecol" ) . "'>" |
| 538 | + . wfMsg( 'recordadmin-editlink' ) . "</a></td>", |
| 539 | + 'created' => "<td class='col2 col-created'>$tsc</td>\n", |
| 540 | + 'modified' => "<td class='col3 col-modified'>$tsm</td>\n", |
| 541 | + ); |
| 542 | + foreach ( $cols ? $cols : array_keys( $th ) as $col ) { |
| 543 | + if ( !isset( $row[$col] ) ) { |
| 544 | + $v = isset( $r[$col] ) ? $wgParser->parse( $r[$col], $wgTitle, $wgParser->mOptions, true, false )->getText() : ' '; |
| 545 | + $class = 'col' . preg_replace( '|\W|', '-', $col ); |
| 546 | + $row[$col] = "<td class='$class'>$v</td>"; |
| 547 | + } |
| 548 | + $table .= "$row[$col]\n"; |
| 549 | + } |
528 | 550 | } |
529 | 551 | } |
530 | | - |
531 | 552 | $table .= "</tr>\n"; |
532 | 553 | } |
533 | 554 | $table .= "</table>\n"; |
— | — | @@ -578,10 +599,10 @@ |
579 | 600 | foreach ( $this->filter as $k => $v ) $qs .= "&ra_$k=" . urlencode( $v ); |
580 | 601 | $url = $wgTitle->getLocalURL( $qs ); |
581 | 602 | if ( in_array( 'csv', $export ) ) { |
582 | | - $table .= "\n<a class=\"recordadmin-export-csv\" href=\"$url\">" . wfMsg( 'recrodadmin-export-csv' ) . "</a>"; |
| 603 | + $table .= "\n<a class=\"recordadmin-export-csv\" href=\"$url\">" . wfMsg( 'recordadmin-export-csv' ) . "</a>"; |
583 | 604 | } |
584 | 605 | if ( in_array( 'pdf', $export ) ) { |
585 | | - $table .= "\n<a class=\"recordadmin-export-pdf\" href=\"$url&format=pdf\">" . wfMsg( 'recrodadmin-export-pdf' ) . "</a>"; |
| 606 | + $table .= "\n<a class=\"recordadmin-export-pdf\" href=\"$url&format=pdf\">" . wfMsg( 'recordadmin-export-pdf' ) . "</a>"; |
586 | 607 | } |
587 | 608 | } |
588 | 609 | |
— | — | @@ -913,7 +934,7 @@ |
914 | 935 | $this->examineForm(); |
915 | 936 | $records = $this->getRecords( $type, $filter, $op, $title, $invert, $orderby, $groupby, $format ); |
916 | 937 | if ( $count ) while ( count( $records ) > $count ) array_pop( $records ); |
917 | | - $table = $this->renderRecords( $records, $cols, $sortable, $template, $name, $export ); |
| 938 | + $table = $this->renderRecords( $records, $cols, $sortable, $template, $name, $export, $groupby, $format ); |
918 | 939 | $this->type = $tmp; |
919 | 940 | |
920 | 941 | return array( $table, 'noparse' => true, 'isHTML' => true ); |
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php |
— | — | @@ -55,8 +55,9 @@ |
56 | 56 | 'recordadmin-editwithform' => 'Edit with form', |
57 | 57 | 'recordadmin-typeinfo' => '$1 record', |
58 | 58 | 'right-recordadmin' => 'Find and edit record pages', |
59 | | - 'recrodadmin-export-csv' => 'CSV', |
60 | | - 'recrodadmin-export-pdf' => 'PDF', |
| 59 | + 'recordadmin-export-csv' => 'CSV', |
| 60 | + 'recordadmin-export-pdf' => 'PDF', |
| 61 | + 'recordadmin-notset' => 'No $1', |
61 | 62 | ); |
62 | 63 | |
63 | 64 | /** Message documentation (Message documentation) |
— | — | @@ -84,8 +85,8 @@ |
85 | 86 | 'recordadmin-actions' => '{{Identical|Action}}', |
86 | 87 | 'recordadmin-typeinfo' => '$1 is a record type. Could be read as "A record of type $1"', |
87 | 88 | 'right-recordadmin' => '{{doc-right|recordadmin}}', |
88 | | - 'recrodadmin-export-csv' => '{{Optional}}', |
89 | | - 'recrodadmin-export-pdf' => '{{Optional}}', |
| 89 | + 'recordadmin-export-csv' => '{{Optional}}', |
| 90 | + 'recordadmin-export-pdf' => '{{Optional}}', |
90 | 91 | ); |
91 | 92 | |
92 | 93 | /** Afrikaans (Afrikaans) |
— | — | @@ -153,8 +154,8 @@ |
154 | 155 | 'recordadmin-editwithform' => 'عدل مع الاستمارة', |
155 | 156 | 'recordadmin-typeinfo' => '$1 تسجيل', |
156 | 157 | 'right-recordadmin' => 'أبحث و عدل صفحات السجل', |
157 | | - 'recrodadmin-export-csv' => 'سي في إس', |
158 | | - 'recrodadmin-export-pdf' => 'بي دي إف', |
| 158 | + 'recordadmin-export-csv' => 'سي في إس', |
| 159 | + 'recordadmin-export-pdf' => 'بي دي إف', |
159 | 160 | ); |
160 | 161 | |
161 | 162 | /** Aramaic (ܐܪܡܝܐ) |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'RECORDADMIN_VERSION', '0.9.10, 2010-01-18' ); |
| 15 | +define( 'RECORDADMIN_VERSION', '0.10.0, 2010-01-18' ); |
16 | 16 | |
17 | 17 | $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type |
18 | 18 | $wgRecordAdminCategory = 'Records'; # Category containing record types |