1 const MWBot
= require( 'mwbot' );
3 // TODO: Once we require Node 7 or later, we can use async-await.
7 * Shortcut for `MWBot#edit( .. )`.
8 * Default username, password and base URL is used unless specified
11 * @see <https://www.mediawiki.org/wiki/API:Edit>
12 * @param {string} title
13 * @param {string} content
14 * @param {string} username - Optional
15 * @param {string} password - Optional
16 * @param {baseUrl} baseUrl - Optional
17 * @return {Object} Promise for API action=edit response data.
21 username
= browser
.options
.username
,
22 password
= browser
.options
.password
,
23 baseUrl
= browser
.options
.baseUrl
25 let bot
= new MWBot();
27 return bot
.loginGetEditToken( {
28 apiUrl
: `${baseUrl}/api.php`,
31 } ).then( function () {
32 return bot
.edit( title
, content
, `Created or updated page with "${content}"` );
37 * Shortcut for `MWBot#delete( .. )`.
40 * @see <https://www.mediawiki.org/wiki/API:Delete>
41 * @param {string} title
42 * @param {string} reason
43 * @return {Object} Promise for API action=delete response data.
45 delete( title
, reason
) {
46 let bot
= new MWBot();
48 return bot
.loginGetEditToken( {
49 apiUrl
: `${browser.options.baseUrl}/api.php`,
50 username
: browser
.options
.username
,
51 password
: browser
.options
.password
52 } ).then( function () {
53 return bot
.delete( title
, reason
);
58 * Shortcut for `MWBot#request( { acount: 'createaccount', .. } )`.
61 * @see <https://www.mediawiki.org/wiki/API:Account_creation>
62 * @param {string} username
63 * @param {string} password
64 * @return {Object} Promise for API action=createaccount response data.
66 createAccount( username
, password
) {
67 let bot
= new MWBot();
70 return bot
.loginGetCreateaccountToken( {
71 apiUrl
: `${browser.options.baseUrl}/api.php`,
72 username
: browser
.options
.username
,
73 password
: browser
.options
.password
74 } ).then( function () {
75 // Create the new account
77 action
: 'createaccount',
78 createreturnurl
: browser
.options
.baseUrl
,
79 createtoken
: bot
.createaccountToken
,
88 * Shortcut for `MWBot#request( { action: 'block', .. } )`.
91 * @see <https://www.mediawiki.org/wiki/API:Block>
92 * @param {string} [username] defaults to user making the request
93 * @param {string} [expiry] default is not set. For format see API docs
94 * @return {Object} Promise for API action=block response data.
96 blockUser( username
, expiry
) {
97 let bot
= new MWBot();
100 return bot
.loginGetEditToken( {
101 apiUrl
: `${browser.options.baseUrl}/api.php`,
102 username
: browser
.options
.username
,
103 password
: browser
.options
.password
105 // block user. default = admin
106 return bot
.request( {
108 user
: username
|| browser
.options
.username
,
109 reason
: 'browser test',
110 token
: bot
.editToken
,
117 * Shortcut for `MWBot#request( { action: 'unblock', .. } )`.
120 * @see <https://www.mediawiki.org/wiki/API:Block>
121 * @param {string} [username] defaults to user making the request
122 * @return {Object} Promise for API action=unblock response data.
124 unblockUser( username
) {
125 let bot
= new MWBot();
128 return bot
.loginGetEditToken( {
129 apiUrl
: `${browser.options.baseUrl}/api.php`,
130 username
: browser
.options
.username
,
131 password
: browser
.options
.password
133 // unblock user. default = admin
134 return bot
.request( {
136 user
: username
|| browser
.options
.username
,
137 reason
: 'browser test done',