forked from wikimedia/mediawiki-extensions-Drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiSaveDrafts.php
111 lines (97 loc) · 2.49 KB
/
ApiSaveDrafts.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* API module to save Drafts
*
* @file
* @ingroup API
* @author Kunal Mehta
*/
class ApiSaveDrafts extends ApiBase {
public function execute() {
if ( $this->getUser()->isAnon() ) {
$this->dieUsage( 'You must be logged in to save drafts.', 'notloggedin' );
}
$params = $this->extractRequestParams();
if (isset($params['isPageFormData']) && $params['isPageFormData']) {
$params['text'] = NsDrafts\PageFormConnectors::convertSerializeFormToSemanticTextContent($params['title'], $params['text']);
}
$draft = Draft::newFromID( $params['id'] );
$draft->setToken( $params['drafttoken'] );
$draft->setTitle( Title::newFromText( $params['title'] ) );
$draft->setSection( $params['section'] == '' ? null : $params['section'] );
$draft->setStartTime( $params['starttime'] );
$draft->setEditTime( $params['edittime'] );
$draft->setSaveTime( wfTimestampNow() );
$draft->setScrollTop( $params['scrolltop'] );
$draft->setText( $params['text'] );
$draft->setSummary( $params['summary'] );
$draft->setMinorEdit( $params['minoredit'] );
$draft->save();
$this->getResult()->addValue(
null,
$this->getModuleName(),
array( 'id' => $draft->getID() )
);
}
/**
* @deprecated since MediaWiki core 1.25
*/
public function getDescription() {
return 'Save a draft';
}
public function getAllowedParams() {
return array(
'id' => array(
ApiBase::PARAM_TYPE => 'integer',
),
'drafttoken' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'title' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'section' => array(
ApiBase::PARAM_TYPE => 'integer',
),
'starttime' => array(
ApiBase::PARAM_REQUIRED => true,
),
'edittime' => array(
ApiBase::PARAM_REQUIRED => true,
),
'scrolltop' => array(
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_REQUIRED => true,
),
'text' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'summary' => array(
ApiBase::PARAM_TYPE => 'string',
),
'minoredit' => array(
ApiBase::PARAM_TYPE => 'boolean',
ApiBase::PARAM_REQUIRED => true,
),
'token' => null,
'isPageFormData' => array(
ApiBase::PARAM_TYPE => 'boolean',
),
);
}
public function mustBePosted() {
return true;
}
public function needsToken() {
return 'csrf';
}
public function getTokenSalt() {
return '';
}
public function isWriteMode() {
return true;
}
}