Index: trunk/extensions/GPoC/SpecialSelection.php |
— | — | @@ -13,20 +13,45 @@ |
14 | 14 | parent::__construct( 'Selection' ); |
15 | 15 | } |
16 | 16 | |
| 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 | + } |
17 | 33 | public function execute( $par ) { |
18 | 34 | global $wgOut, $wgRequest; |
19 | 35 | |
20 | 36 | $name = $par; |
| 37 | + $action = $wgRequest->getVal('action'); |
21 | 38 | |
22 | 39 | $entries = Selection::getSelection( $name ); |
23 | 40 | $this->setHeaders(); |
24 | 41 | |
25 | 42 | $wgOut->setPageTitle("Selection"); |
26 | 43 | |
| 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 | + } |
27 | 53 | $template = new SelectionTemplate(); |
28 | 54 | $template->set( 'articles', $entries ); |
29 | 55 | |
30 | 56 | $wgOut->addTemplate( $template ); |
31 | | - |
32 | 57 | } |
33 | 58 | } |