r57842 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57841‎ | r57842 | r57843 >
Date:01:58, 17 October 2009
Author:nad
Status:deferred
Tags:
Comment:
resolved export issues raised yesterday
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
@@ -320,7 +320,7 @@
321321 /**
322322 * Render a set of records returned by getRecords() as an HTML table
323323 */
324 - function renderRecords( $records, $cols = false, $sortable = true, $template = false, $name = 'wpSelect' ) {
 324+ function renderRecords( $records, $cols = false, $sortable = true, $template = false, $name = 'wpSelect', $export = true ) {
325325 global $wgParser, $wgTitle, $wgRequest;
326326 if ( count( $records ) < 1 ) return wfMsg( 'recordadmin-nomatch' );
327327
@@ -404,6 +404,7 @@
405405 global $wgOut;
406406 $wgOut->disable();
407407
 408+ # PDF export
408409 if ( $wgRequest->getText( 'format' ) == 'pdf' ) {
409410 global $wgUploadDirectory;
410411 $file = "$wgUploadDirectory/" . uniqid( 'recordadmin' );
@@ -417,6 +418,7 @@
418419 @unlink( $file );
419420 }
420421
 422+ # CSV export
421423 else {
422424 header("Content-Type: text/html");
423425 header("Content-Disposition: attachment; filename=\"$quid.csv\"");
@@ -428,8 +430,7 @@
429431 $csv .= "\n";
430432 $sep = "";
431433 } else $sep = "\t";
432 - $cell = preg_replace( "|<!--.+?-->|s", "", $cell );
433 - if ( preg_match( "|<p>\s*(.+?)\s*</p>|s", $cell, $m ) ) $cell = $m[1];
 434+ $cell = strip_tags( $cell );
434435 $cell = preg_replace( "/[\\r\\n]+/m", "\\n", $cell );
435436 $csv .= "$sep$cell";
436437 }
@@ -439,12 +440,17 @@
440441 }
441442
442443 # Otherwise add export links
443 - else {
 444+ elseif ( $export ) {
 445+ $export = $export === true ? array( 'pdf', 'csv' ) : preg_split( "/\s*,\s*/", strtolower( $export ) );
444446 $qs = "wpType=$type&wpFind=1&quid={$this->quid}";
445447 foreach ( $this->filter as $k => $v ) $qs .= "&ra_$k=" . urlencode( $v );
446448 $url = $wgTitle->getLocalURL( $qs );
447 - $table .= "\n<a class=\"recordadmin-export\" href=\"$url\">" . wfMsg( 'recrodadmin-export-csv' ) . "</a>";
448 - $table .= "\n<a class=\"recordadmin-export\" href=\"$url&format=pdf\">" . wfMsg( 'recrodadmin-export-pdf' ) . "</a>";
 449+ if ( in_array( 'csv', $export ) ) {
 450+ $table .= "\n<a class=\"recordadmin-export-csv\" href=\"$url\">" . wfMsg( 'recrodadmin-export-csv' ) . "</a>";
 451+ }
 452+ if ( in_array( 'pdf', $export ) ) {
 453+ $table .= "\n<a class=\"recordadmin-export-pdf\" href=\"$url&format=pdf\">" . wfMsg( 'recrodadmin-export-pdf' ) . "</a>";
 454+ }
449455 }
450456
451457 return $table;
@@ -733,6 +739,7 @@
734740 $sortable = true;
735741 $template = false;
736742 $count = false;
 743+ $export = false;
737744 foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
738745 if ( preg_match( "|^(.+?)\s*=\s*(.+)$|i", $arg, $match ) ) {
739746 list( , $k, $v ) = $match;
@@ -744,6 +751,7 @@
745752 elseif ( $k == 'sortable' ) $sortable = eregi( '1|yes|true|on', $v );
746753 elseif ( $k == 'template' ) $template = $v;
747754 elseif ( $k == 'count' ) $count = $v;
 755+ elseif ( $k == 'export' ) $export = $v;
748756 else $filter[$match[1]] = $match[2];
749757 }
750758 }
@@ -752,7 +760,7 @@
753761 $this->examineForm();
754762 $records = $this->getRecords( $type, $filter, $title, $invert, $orderby );
755763 if ( $count ) while ( count( $records ) > $count ) array_pop( $records );
756 - $table = $this->renderRecords( $records, $cols, $sortable, $template, $name );
 764+ $table = $this->renderRecords( $records, $cols, $sortable, $template, $name, $export );
757765
758766 return array( $table, 'noparse' => true, 'isHTML' => true );
759767 }
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.8.8, 2009-10-15' );
 15+define( 'RECORDADMIN_VERSION', '0.8.9, 2009-10-17' );
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