blob: c1da80aa57d36fd3996f49671a7e2a7a27a05b86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
/**
* Lets the user import a spreadsheet file to turn into wiki pages
*
* @author Stephan Gambke
* @ingroup DataTransfer
*/
class DTImportSpreadsheet extends DTImportCSV {
public function __construct( $name='ImportSpreadsheet' ) {
parent::__construct( $name );
}
protected function printForm() {
if ( !class_exists( 'PHPExcel' ) ) {
return '<div class="error">You must have the PHPExcel library installed to run this page.</div>';
}
$formText = DTUtils::printFileSelector( $this->getFiletype() );
$formText .= DTUtils::printExistingPagesHandling();
$formText .= DTUtils::printImportSummaryInput( $this->getFiletype() );
$formText .= DTUtils::printSubmitButton();
$text = "\t" . Xml::tags( 'form',
array(
'enctype' => 'multipart/form-data',
'action' => '',
'method' => 'post'
), $formText ) . "\n";
return $text;
}
protected function importFromFile( $file, $encoding, &$pages ) {
if ( is_null( $file ) ) {
return wfMessage( 'emptyfile' )->text();
}
$metadata = stream_get_meta_data( $file );
$filename = $metadata['uri'];
@$objPHPExcel = PHPExcel_IOFactory::load( $filename );
$table = $objPHPExcel->getSheet(0)->toArray( '', true, true, false );
return $this->importFromArray( $table, $pages );
}
protected function getFiletype() {
return wfMessage( 'dt_filetype_spreadsheet' )->text();
}
}
|