Comments (2)
I created a quick draft of this for my own bot. See https://gist.github.com/Krinkle/8e1e0e41baaae63f9839d86d918d512c/c1788e5ececff3ddf373944d3dc41ced99be08af#file-wmf-tour-bot-js-L107-L139. Feel free to use it as in any way you like.
client.edit = function(pageData, content, summary, minor, callback) {
var params = {
text: content,
// Avoid accidentally editing as anonymous user if session expires
assert: 'user'
};
if (typeof minor === 'function') {
callback = minor;
minor = undefined;
}
if (minor) {
params.minor = '';
} else {
params.notminor = '';
}
var title;
if (typeof pageData === 'object') {
params.basetimestamp = pageData.revision.timestamp;
params.starttimestamp = new Date().toISOString();
// Avoid accidentally creating a new page (e.g. if title string got corrupted,
// or if page was deleted meanwhile).
params.nocreate = '';
title = pageData.title;
} else {
title = pageData;
}
this.doEdit('edit', title, summary, params, callback);
};
This protects bots against various problems. The same protections that the MediaWiki web interface uses when you edit via a web browser:
- Session loss or expiration (
assert=user
). Avoid making edits as anonymous user if server lost the session. - Edit conflict (
basetimestamp
). Avoid overriding other edits. - Re-create (
starttimestamp
). Avoid re-publishing text that was deleted. - Edit type (
nocreate
/createonly
). Avoid creating new pages or edits. Sometimes if the page title is corrupted (e.g. bad encoding) it can happen that the content is fetched from A but saved to B - causing a duplicate page to be created. (E.g. If spaces are cut off and you fetch from "Foo bar" and save to "Foo", or a character encoding problem).
See https://www.mediawiki.org/wiki/API:Edit
from nodemw.
@Krinkle, thanks for the code snippet. assert=user
can be added automatically when bot operates in logged-in mode.
from nodemw.
Related Issues (20)
- [0.11.0 Regression] Edits fail but claim success (err = null) HOT 3
- Support namespaces in getPagesByPrefix
- Allow to enumerate/include redirects HOT 3
- Replace jshint with eslint HOT 3
- Planning a release to NPM? HOT 1
- API Errors don't include the original response
- getArticle not working with special characters in title HOT 4
- TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string HOT 1
- SVG upload
- Typescript Types HOT 4
- Dont request new edit token each edit call AND prevent SCRF error
- Next parameter in client.api.call, how to use?
- How to pass parameters to the bot.parse call? HOT 1
- Replace the deprecated 'request' package HOT 2
- Add a command-line module
- CSRF token should be sent as last parameter in request payload
- Add a page edit integration test
- Update Fandom videos upload
- Introduce WikiData client
- `username`, `password`, and `domain` is missing on `BotOptions` type definition. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodemw.