module.exports = {
/**
* Shortcut for `MWBot#edit( .. )`.
+ * Default username, password and base URL is used unless specified
*
* @since 1.0.0
* @see <https://www.mediawiki.org/wiki/API:Edit>
* @param {string} title
* @param {string} content
+ * @param {string} username - Optional
+ * @param {string} password - Optional
+ * @param {baseUrl} baseUrl - Optional
* @return {Object} Promise for API action=edit response data.
*/
- edit( title, content ) {
- let bot = new MWBot();
+ edit( title,
+ content,
+ username = browser.options.username,
+ password = browser.options.password,
+ baseUrl = browser.options.baseUrl
+ ) {
+ const bot = new MWBot();
return bot.loginGetEditToken( {
- apiUrl: `${browser.options.baseUrl}/api.php`,
- username: browser.options.username,
- password: browser.options.password
+ apiUrl: `${baseUrl}/api.php`,
+ username: username,
+ password: password
} ).then( function () {
- return bot.edit( title, content, `Created page with "${content}"` );
+ return bot.edit( title, content, `Created or updated page with "${content}"` );
} );
},
* @return {Object} Promise for API action=delete response data.
*/
delete( title, reason ) {
- let bot = new MWBot();
+ const bot = new MWBot();
return bot.loginGetEditToken( {
apiUrl: `${browser.options.baseUrl}/api.php`,
* @return {Object} Promise for API action=createaccount response data.
*/
createAccount( username, password ) {
- let bot = new MWBot();
+ const bot = new MWBot();
// Log in as admin
return bot.loginGetCreateaccountToken( {
retype: password
} );
} );
+ },
+
+ /**
+ * Shortcut for `MWBot#request( { action: 'block', .. } )`.
+ *
+ * @since 0.3.0
+ * @see <https://www.mediawiki.org/wiki/API:Block>
+ * @param {string} [username] defaults to user making the request
+ * @param {string} [expiry] default is not set. For format see API docs
+ * @return {Object} Promise for API action=block response data.
+ */
+ blockUser( username, expiry ) {
+ const bot = new MWBot();
+
+ // Log in as admin
+ return bot.loginGetEditToken( {
+ apiUrl: `${browser.options.baseUrl}/api.php`,
+ username: browser.options.username,
+ password: browser.options.password
+ } ).then( () => {
+ // block user. default = admin
+ return bot.request( {
+ action: 'block',
+ user: username || browser.options.username,
+ reason: 'browser test',
+ token: bot.editToken,
+ expiry
+ } );
+ } );
+ },
+
+ /**
+ * Shortcut for `MWBot#request( { action: 'unblock', .. } )`.
+ *
+ * @since 0.3.0
+ * @see <https://www.mediawiki.org/wiki/API:Block>
+ * @param {string} [username] defaults to user making the request
+ * @return {Object} Promise for API action=unblock response data.
+ */
+ unblockUser( username ) {
+ const bot = new MWBot();
+
+ // Log in as admin
+ return bot.loginGetEditToken( {
+ apiUrl: `${browser.options.baseUrl}/api.php`,
+ username: browser.options.username,
+ password: browser.options.password
+ } ).then( () => {
+ // unblock user. default = admin
+ return bot.request( {
+ action: 'unblock',
+ user: username || browser.options.username,
+ reason: 'browser test done',
+ token: bot.editToken
+ } );
+ } );
}
};