r93837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93836‎ | r93837 | r93838 >
Date:17:10, 3 August 2011
Author:yuvipanda
Status:deferred
Tags:
Comment:
Export Selections as CSV
Modified paths:
  • /trunk/extensions/GPoC/SpecialSelection.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GPoC/SpecialSelection.php
@@ -13,20 +13,45 @@
1414 parent::__construct( 'Selection' );
1515 }
1616
 17+ private function makeCSV( $articles, $name ) {
 18+ $outstream = fopen( "php://output", "w" );
 19+ $headers = array(
 20+ 'article',
 21+ 'added'
 22+ );
 23+ fputcsv( $outstream, $headers );
 24+ foreach( $articles as $article ) {
 25+ $row = array(
 26+ $article['title']->getFullText(),
 27+ wfTimeStamp( TS_ISO_8601, $article['s_timestamp'] )
 28+ );
 29+ fputcsv( $outstream, $row );
 30+ }
 31+ fclose( $outstream );
 32+ }
1733 public function execute( $par ) {
1834 global $wgOut, $wgRequest;
1935
2036 $name = $par;
 37+ $action = $wgRequest->getVal('action');
2138
2239 $entries = Selection::getSelection( $name );
2340 $this->setHeaders();
2441
2542 $wgOut->setPageTitle("Selection");
2643
 44+ if( $action == 'csv' ) {
 45+ $wgRequest->response()->header( 'Content-type: text/csv' );
 46+ // Is there a security issue in letting the name be arbitrary?
 47+ $wgRequest->response()->header(
 48+ "Content-Disposition: attachment; filename=$name.csv"
 49+ );
 50+ $wgOut->disable();
 51+ $this->makeCSV( $entries, $name );
 52+ }
2753 $template = new SelectionTemplate();
2854 $template->set( 'articles', $entries );
2955
3056 $wgOut->addTemplate( $template );
31 -
3257 }
3358 }

Status & tagging log