|
1
|
|
|
<?php |
|
2
|
|
|
if (!defined('MEDIAWIKI')) { die(-1); } |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
# Our SpecialPage |
|
6
|
|
|
class SpecialSDImport extends SpecialPage { |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Constructor : initialise object |
|
11
|
|
|
* Get data POSTed through the form and assign them to the object |
|
12
|
|
|
* @param $request WebRequest : data posted. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
public function __construct($request = null) { |
|
16
|
|
|
parent::__construct('SDImport'); #The first argument must be the name of your special page |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
private static function getKeyOptionsWithBlank( $keys ) { |
|
22
|
|
|
|
|
23
|
|
|
global $wgContLang; |
|
24
|
|
|
|
|
25
|
|
|
$list_namespaces = array( "" => "" ); |
|
26
|
|
|
|
|
27
|
|
|
foreach ( $keys as $key ) { |
|
28
|
|
|
|
|
29
|
|
|
$keyName = $wgContLang->getNsText( $key ); |
|
30
|
|
|
|
|
31
|
|
|
$list_namespaces[ $keyName ] = $key; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $list_namespaces; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Special page entry point |
|
40
|
|
|
*/ |
|
41
|
|
|
public function execute($par) { |
|
42
|
|
|
global $wgOut; |
|
43
|
|
|
|
|
44
|
|
|
global $wgSDImportDataPage; // Configuration options |
|
45
|
|
|
|
|
46
|
|
|
$list_namespaces = self::getKeyOptionsWithBlank( array_keys( $wgSDImportDataPage ) ); |
|
47
|
|
|
|
|
48
|
|
|
$wgOut->addModules( 'ext.sdimport' ); |
|
49
|
|
|
$this->setHeaders(); |
|
50
|
|
|
|
|
51
|
|
|
// TODO: We should handle request in the form in a better way. $wgRequest Check examples here: involved http://www.mediawiki.org/wiki/Category:Special_page_extensions |
|
52
|
|
|
|
|
53
|
|
|
# A formDescriptor for uploading stuff |
|
54
|
|
|
$formDescriptor = array( |
|
55
|
|
|
|
|
56
|
|
|
'fileupload' => array( |
|
57
|
|
|
'section' => 'upload', |
|
58
|
|
|
'label' => 'Upload file', |
|
59
|
|
|
'class' => 'HTMLTextField', |
|
60
|
|
|
'type' => 'file' |
|
61
|
|
|
), |
|
62
|
|
|
'separator' => array( |
|
63
|
|
|
'section' => 'upload', |
|
64
|
|
|
'type' => 'select', |
|
65
|
|
|
'label' => 'Separator', |
|
66
|
|
|
'options' => array( "," => ",","{TAB}" => "{TAB}", ";" => ";" ) |
|
67
|
|
|
), |
|
68
|
|
|
'delimiter' => array( |
|
69
|
|
|
'section' => 'upload', |
|
70
|
|
|
'type' => 'select', |
|
71
|
|
|
'label' => 'Delimiter', |
|
72
|
|
|
'options' => array( "\"" => "\"" , "'" => "'" ) |
|
73
|
|
|
), |
|
74
|
|
|
'namespace' => array( |
|
75
|
|
|
'section' => 'upload', |
|
76
|
|
|
'type' => 'select', |
|
77
|
|
|
'label' => 'Namespace', |
|
78
|
|
|
'options' => $list_namespaces |
|
79
|
|
|
), |
|
80
|
|
|
'single' => [ |
|
81
|
|
|
'section' => 'upload', |
|
82
|
|
|
'class' => 'HTMLCheckField', |
|
83
|
|
|
'label' => 'Single row mode', |
|
84
|
|
|
'default' => false, |
|
85
|
|
|
] |
|
86
|
|
|
|
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$htmlForm = new HTMLForm( $formDescriptor, 'sdimport-form' ); |
|
91
|
|
|
|
|
92
|
|
|
$htmlForm->setSubmitText( wfMessage('sdimport-form-submit-button')->text() ); # What text does the submit button display |
|
93
|
|
|
$htmlForm->setTitle( $this->getTitle() ); # You must call setTitle() on an HTMLForm |
|
94
|
|
|
|
|
95
|
|
|
/* We set a callback function */ |
|
96
|
|
|
$htmlForm->setSubmitCallback( array( 'SpecialSDImport', 'processCSV' ) ); |
|
97
|
|
|
|
|
98
|
|
|
$htmlForm->suppressReset(false); # Get back reset button |
|
99
|
|
|
|
|
100
|
|
|
$wgOut->addHTML( "<div id='sdintro' class='sdimport_section'>" ); |
|
101
|
|
|
$wgOut->addHTML( wfMessage('sdimport-form-intro')->text() ); |
|
102
|
|
|
$wgOut->addHTML( "</div>" ); |
|
103
|
|
|
$wgOut->addHTML( "<div id='sdform' class='sdimport_section'>" ); |
|
104
|
|
|
$htmlForm->show(); # Displaying the form |
|
105
|
|
|
$wgOut->addHTML( "</div>" ); |
|
106
|
|
|
$wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders sdimport_section'></div>" ); |
|
107
|
|
|
//$wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders'></div>"); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
static function processCSV( $formData ) { |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
// Everything handled via Javascript. Nothing done here... |
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.