|
1
|
|
|
<?php |
|
2
|
|
|
class SDImportApi extends ApiBase { |
|
3
|
|
|
|
|
4
|
|
|
public function execute() { |
|
5
|
|
|
|
|
6
|
|
|
$params = $this->extractRequestParams(); |
|
7
|
|
|
|
|
8
|
|
|
$jsonmodel = false; |
|
9
|
|
|
|
|
10
|
|
|
if ( array_key_exists( "model", $params ) ) { |
|
11
|
|
|
|
|
12
|
|
|
if ( $params["model"] === "json" ) { |
|
13
|
|
|
$jsonmodel = true; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
//wfDebugLog( "sdimport", json_encode( $params ) ); |
|
19
|
|
|
|
|
20
|
|
|
if ( $jsonmodel ) { |
|
21
|
|
|
//wfDebugLog( "sdimport", "Batch: ".$params['model'] ); |
|
22
|
|
|
if ( $params["batch"] === true ) { |
|
23
|
|
|
$status = SDImportData::importJSONBatch( $params['text'], $params['title'], $params['overwrite'] ); |
|
24
|
|
|
} |
|
25
|
|
|
else { |
|
26
|
|
|
// wfDebugLog( "sdimport", "Hereeeee" ); |
|
27
|
|
|
$status = SDImportData::importJSON( $params['text'], $params['title'], $params['overwrite'] ); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
else { |
|
31
|
|
|
$status = SDImportData::importWikiText( $params['text'], $params['title'], $params['separator'], $params['delimiter'], $params['num'] ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), array ( 'status' => $status ) ); |
|
35
|
|
|
|
|
36
|
|
|
return true; |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
public function getAllowedParams() { |
|
40
|
|
|
return array( |
|
41
|
|
|
'text' => array( |
|
42
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
43
|
|
|
ApiBase::PARAM_REQUIRED => true |
|
44
|
|
|
), |
|
45
|
|
|
'title' => array( |
|
46
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
47
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
48
|
|
|
), |
|
49
|
|
|
'separator' => array( |
|
50
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
51
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
52
|
|
|
), |
|
53
|
|
|
'delimiter' => array( |
|
54
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
55
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
56
|
|
|
), |
|
57
|
|
|
'num' => array( |
|
58
|
|
|
ApiBase::PARAM_TYPE => 'integer', |
|
59
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
60
|
|
|
), |
|
61
|
|
|
'model' => array( |
|
62
|
|
|
ApiBase::PARAM_TYPE => 'string', |
|
63
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
64
|
|
|
), |
|
65
|
|
|
'overwrite' => array( |
|
66
|
|
|
ApiBase::PARAM_TYPE => 'boolean', |
|
67
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
68
|
|
|
), |
|
69
|
|
|
'batch' => array( |
|
70
|
|
|
ApiBase::PARAM_TYPE => 'boolean', |
|
71
|
|
|
ApiBase::PARAM_REQUIRED => false |
|
72
|
|
|
) |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getDescription() { |
|
77
|
|
|
return array( |
|
78
|
|
|
'API for importing data into smwdata page' |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
public function getParamDescription() { |
|
82
|
|
|
return array( |
|
83
|
|
|
'text' => 'Content to be processed' |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getVersion() { |
|
88
|
|
|
return __CLASS__ . ': 1.1'; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|