cgt / go-mwclient Goto Github PK
View Code? Open in Web Editor NEWA Go package for interacting with the MediaWiki API.
License: Creative Commons Zero v1.0 Universal
A Go package for interacting with the MediaWiki API.
License: Creative Commons Zero v1.0 Universal
jason is a new Go package for dealing with arbitrary JSON, like go-simplejson. However, I find its API more pleasant to use, wherefore I would like to replace go-simplejson with jason. It's easy to refactor code using go-simplejson to jason, and it is even possible to pretty much avoid changing existing code by simply marshalling the jason object to a []byte of JSON and unmarshalling it into go-simplejson.
I am currently working on refactoring go-mwclient to use jason in a local branch, and I'll probably go ahead and push it to the master branch when it's done. I promised in the readme that I would do breaking changes if I found a nicer way of doing something, but I still feel kind of guilty about it. After this, however, I do not expect any more major breaking changes.
If the API returns a warning in an otherwise successful response, the GetPage(s) functions return just the warning as an error and no content. The functions ought to return both the content and the warning.
Hey, thanks for the amazing library!
Currently, all edits involve using query string parameters:
https://github.com/cgt/go-mwclient/blob/8d3513b202f9de1f12d4828c6fcc3db52bbbc3c8/core.go#L184-189
MW documentation recommends that edits over 8000 characters in size should be sent using multipart/form-data
, to avoid having the overhead of percent-encoding the entire contents. It'd be great to see go-mwclient support this!
I have a wiki that is working with go-mwclient, mediawiki v1.39.3
I have an account that uses a bot password. Read & write page permission is granted to the bot password. The only extension installed is ConfirmAccounts.
When the wiki is put into "private" mode:
LocalSettings.php:
# Disable reading by anonymous users
$wgGroupPermissions['*']['read'] = false;
# Disable anonymous editing
$wgGroupPermissions['*']['edit'] = false;
Then after this change, go-mwclient Login call returns an immediate error:
readapidenied: You need read permission to use this module.
Reverting the LocalSettings.php change allows the bot to work again.
What is the correct way to use go-mwclient with a private wiki?
Calling GetToken() prior to the Login() call fails with the readapidenied
error.
A curl call to to the API in private mode works:
> curl "https://wiki.my.com/api.php?action=query&meta=tokens&type=login&format=json"
{"batchcomplete":"","query":{"tokens":{"logintoken":"bdc839c440a8b42038ffe7ca1bfb36696430ed2e+\\"}}}
Any help appreciated.
Big fan of this library. Is there any chance you might add a way to upload files?
I am working on a version of go-mwclient in branch next
which I intend to tag as v1.0.0 once it is merged into master
.
The following changes are currently planned for v1, some are already implemented:
Support for OAuth authentication with the "owner-only consumer" method as described here: https://www.mediawiki.org/wiki/OAuth/Owner-only_consumers
Default to formatversion=2 of the JSON API described here: https://www.mediawiki.org/wiki/API:JSON_version_2. One particularly nice improvement in version 2 of the JSON API is that lists of pages are represented as JSON arrays rather than an object where the keys are page IDs. This makes it much easier to decode into a struct. It shall be possible to override this by setting formatversion=1 manually in your params.Values parameter objects.
New()
does not return an error if the userAgent
parameter is empty.
Login
and Logout
will no longer set an API assertion level (used to assert that the client is logged in or has bot rights). This must now be done manually.
Logout
may be changed to actually handle errors rather than just firing off the logout request blindly. The method was only implemented for completeness, I don't recall ever actually using it.
Verify that CAPTCHA error handling actually works (or get rid of it).
HTTP timeouts in HTTP client.
Some of these are breaking changes. Once v1 is tagged, go-mwclient shall follow semantic versioning as described on semver.org, with the exception that breaking changes may be introduced without a major version bump if changes to the MediaWiki API itself require it. go-mwclient shall be kept up to date and compatible with MediaWiki.
I'm not sure if anyone else but me is still using package, but I figured I would give people a chance to object to breaking changes or suggest other changes before v1. I don't have a plan for when v1 will be released, but it will likely be in the near future, possibly before the end of 2016.
site, err := mwclient.New("https://wiki.piratenpartei.de/wiki/api.php", "SomeBotName")
if err != nil {
fmt.Printf("Fehler: %s\n", err)
return
}
Works.
err = site.Login("BOTNAME", "BOTPASSWORD")
if err != nil {
fmt.Printf("Fehler: %s\n", err)
return
}
Does not work:
Fehler: extractWarnings: key not found: {"*":"Unrecognized parameters: 'formatversion', 'type‘"}
Huh?
2 warnings: [main: Subscribe to the mediawiki-api-announce mailing list at https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/ for notice of API deprecations and breaking changes.] [login: Main-account login via "action=login" is deprecated and may stop working without warning. To continue login with "action=login", see [[Special:BotPasswords]]. To safely continue using main-account login, see "action=clientlogin".] %
Should implement action=clientlogin to the library soon
url.Values is a map[string][]string, for which it is annoying to write literals because I never need the same parameter with different values in a request, so all the values have to be wrapped in braces. Replace url.Values with map[string]string (like in the Edit method) in the public UI.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.