1 const MWBot
= require( 'mwbot' );
5 * Get a logged-in instance of `MWBot` with edit token already set up.
6 * Default username, password and base URL is used unless specified.
9 * @param {string} username - Optional
10 * @param {string} password - Optional
11 * @param {string} baseUrl - Optional
12 * @return {Promise<MWBot>}
15 username
= browser
.config
.mwUser
,
16 password
= browser
.config
.mwPwd
,
17 baseUrl
= browser
.config
.baseUrl
19 const bot
= new MWBot();
21 await bot
.loginGetEditToken( {
22 apiUrl
: `${baseUrl}/api.php`,
30 * Shortcut for `MWBot#edit( .. )`.
31 * Default username, password and base URL is used unless specified
34 * @see <https://www.mediawiki.org/wiki/API:Edit>
35 * @param {string} title
36 * @param {string} content
37 * @param {string} username - Optional
38 * @param {string} password - Optional
39 * @param {baseUrl} baseUrl - Optional
40 * @return {Object} Promise for API action=edit response data.
44 username
= browser
.config
.mwUser
,
45 password
= browser
.config
.mwPwd
,
46 baseUrl
= browser
.config
.baseUrl
48 const bot
= await
this.bot( username
, password
, baseUrl
);
49 return await bot
.edit( title
, content
, `Created or updated page with "${content}"` );
53 * Shortcut for `MWBot#delete( .. )`.
56 * @see <https://www.mediawiki.org/wiki/API:Delete>
57 * @param {string} title
58 * @param {string} reason
59 * @return {Object} Promise for API action=delete response data.
61 async
delete( title
, reason
) {
62 const bot
= await
this.bot();
63 return await bot
.delete( title
, reason
);
67 * Shortcut for `MWBot#request( { acount: 'createaccount', .. } )`.
70 * @see <https://www.mediawiki.org/wiki/API:Account_creation>
71 * @param {string} username
72 * @param {string} password
73 * @return {Object} Promise for API action=createaccount response data.
75 async
createAccount( username
, password
) {
76 const bot
= new MWBot();
79 await bot
.loginGetCreateaccountToken( {
80 apiUrl
: `${browser.config.baseUrl}/api.php`,
81 username
: browser
.config
.mwUser
,
82 password
: browser
.config
.mwPwd
84 // Create the new account
85 return await bot
.request( {
86 action
: 'createaccount',
87 createreturnurl
: browser
.config
.baseUrl
,
88 createtoken
: bot
.createaccountToken
,
96 * Shortcut for `MWBot#request( { action: 'block', .. } )`.
99 * @see <https://www.mediawiki.org/wiki/API:Block>
100 * @param {string} [username] defaults to user making the request
101 * @param {string} [expiry] default is not set. For format see API docs
102 * @return {Object} Promise for API action=block response data.
104 async
blockUser( username
, expiry
) {
105 const bot
= await
this.bot();
106 // block user. default = admin
107 return await bot
.request( {
109 user
: username
|| browser
.config
.mwUser
,
110 reason
: 'browser test',
111 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 async
unblockUser( username
) {
125 const bot
= await
this.bot();
126 // unblock user. default = admin
127 return await bot
.request( {
129 user
: username
|| browser
.config
.mwUser
,
130 reason
: 'browser test done',