1 const MWBot
= require( 'mwbot' );
3 // TODO: Once we require Node 7 or later, we can use async-await.
7 * Shortcut for `MWBot#edit( .. )`.
10 * @see <https://www.mediawiki.org/wiki/API:Edit>
11 * @param {string} title
12 * @param {string} content
13 * @return {Object} Promise for API action=edit response data.
15 edit( title
, content
) {
16 let bot
= new MWBot();
18 return bot
.loginGetEditToken( {
19 apiUrl
: `${browser.options.baseUrl}/api.php`,
20 username
: browser
.options
.username
,
21 password
: browser
.options
.password
22 } ).then( function () {
23 return bot
.edit( title
, content
, `Created page with "${content}"` );
28 * Shortcut for `MWBot#delete( .. )`.
31 * @see <https://www.mediawiki.org/wiki/API:Delete>
32 * @param {string} title
33 * @param {string} reason
34 * @return {Object} Promise for API action=delete response data.
36 delete( title
, reason
) {
37 let bot
= new MWBot();
39 return bot
.loginGetEditToken( {
40 apiUrl
: `${browser.options.baseUrl}/api.php`,
41 username
: browser
.options
.username
,
42 password
: browser
.options
.password
43 } ).then( function () {
44 return bot
.delete( title
, reason
);
49 * Shortcut for `MWBot#request( { acount: 'createaccount', .. } )`.
52 * @see <https://www.mediawiki.org/wiki/API:Account_creation>
53 * @param {string} username
54 * @param {string} password
55 * @return {Object} Promise for API action=createaccount response data.
57 createAccount( username
, password
) {
58 let bot
= new MWBot();
61 return bot
.loginGetCreateaccountToken( {
62 apiUrl
: `${browser.options.baseUrl}/api.php`,
63 username
: browser
.options
.username
,
64 password
: browser
.options
.password
65 } ).then( function () {
66 // Create the new account
68 action
: 'createaccount',
69 createreturnurl
: browser
.options
.baseUrl
,
70 createtoken
: bot
.createaccountToken
,
79 * Shortcut for `MWBot#request( { action: 'block', .. } )`.
82 * @see <https://www.mediawiki.org/wiki/API:Block>
83 * @param {string} [username] defaults to user making the request
84 * @param {string} [expiry] default is not set. For format see API docs
85 * @return {Object} Promise for API action=block response data.
87 blockUser( username
, expiry
) {
88 let bot
= new MWBot();
91 return bot
.loginGetEditToken( {
92 apiUrl
: `${browser.options.baseUrl}/api.php`,
93 username
: browser
.options
.username
,
94 password
: browser
.options
.password
96 // block user. default = admin
99 user
: username
|| browser
.options
.username
,
100 reason
: 'browser test',
101 token
: bot
.editToken
,
108 * Shortcut for `MWBot#request( { action: 'unblock', .. } )`.
111 * @see <https://www.mediawiki.org/wiki/API:Block>
112 * @param {string} [username] defaults to user making the request
113 * @return {Object} Promise for API action=unblock response data.
115 unblockUser( username
) {
116 let bot
= new MWBot();
119 return bot
.loginGetEditToken( {
120 apiUrl
: `${browser.options.baseUrl}/api.php`,
121 username
: browser
.options
.username
,
122 password
: browser
.options
.password
124 // unblock user. default = admin
125 return bot
.request( {
127 user
: username
|| browser
.options
.username
,
128 reason
: 'browser test done',