Page MenuHomePhabricator

Build Wikidata description data client.
Closed, ResolvedPublic3 Estimated Story Points

Description

This task is to create the classes and tests for submitting edits to the Wikidata description of a certain article. At the highest level, we need a function like: submitDescription(String pageTitle, String description, Callback callback);

This should correctly handle success and failure modes from submitting edits, including AbuseFilter responses. Much of the API interactions should be similar to the actual "editing" API that’s already part of the app. Additionally, we should consult with Monte about the API calls he used in his prototype.

Event Timeline

Dbrant renamed this task from Build Retrofit API infrastructure for editing Wikidata descriptions. to Build Wikidata description data client..Sep 30 2016, 6:27 PM
MBinder_WMF set the point value for this task to 3.Sep 30 2016, 6:28 PM

@Mhurd Anything we should be aware of regarding the API calls necessary to edit Wikidata descriptions? Even better, would you be able to share them with us?

I set breakpoints on the networking post handler and saw the following activity.

Not logged in:

Looks like it directly calls "wbsetdescription" with "+\\" token...

https://www.wikidata.org/w/api.php
{
    action = wbsetdescription;
    format = json;
    language = en;
    site = enwiki;
    title = "Tamarack,_Minnesota";
    token = "+\\";
    value = "small town in Aitkin County, Minnesota, USA";
}

Logged in:

First fetch central auth token...

https://en.m.wikipedia.org/w/api.php
{
    action = centralauthtoken;
    format = json;
}

Then use that to fetch wikidata token...

https://www.wikidata.org/w/api.php
{
    action = query;
    centralauthtoken = 2ec0f649767a396fc7f6bbc3018e55a41d7a5c4;
    format = json;
    meta = tokens;
}

Then fetch central auth token (again? - not sure why - this may or may not actually be needed)

https://en.m.wikipedia.org/w/api.php
{
    action = centralauthtoken;
    format = json;
}

Then update wikidata with both central auth and wikidata tokens...

https://www.wikidata.org/w/api.php
{
    action = wbsetdescription;
    centralauthtoken = 32594988bc519fd6bbd43cc2378217111d7a5c4;
    format = json;
    language = en;
    site = enwiki;
    title = "Tamarack,_Minnesota";
    token = "0400e320d951a1f22b063eac5446b72658110659+\\";  
    value = "small town in Aitkin County, Minnesota, USA";
}

Note: the old code can no longer log the user in so I had to fake it, so I think this is why the tokens above don't actually match.

The WIP PR from the Lyon hackathon:
https://github.com/montehurd/apps-ios-wikipedia/commit/4c611c4dd16bd9e3f83a0321f67c8e41f9b7cf98

Screenshots and discussion (including description size limit issues) and video link:
https://phabricator.wikimedia.org/T90765

@Mhurd Sweet! Thanks for this breakdown of the calls!

I'm trying the first option with the same article as you did but get an Unknown error: "wikibase-no-direct-editing".

Here are the details:

POST https://www.wikidata.org/w/api.php?action=edit&format=json
Content-Type: application/x-www-form-urlencoded
Content-Length: 130
language=en&site=enwiki&title=Tamarack%2C_Minnesota&value=small%20town%20in%20Aitkin%20County%2C%20Minnesota%2C%20USA&token=%2B%5C

Response:

{"servedby":"mw1189","error":{"code":"unknownerror","info":"Unknown error: \"wikibase-no-direct-editing\"","*":"See https://www.wikidata.org/w/api.php for API usage"}}

The token is encoded +\ but it's not complaining about the token. If I change it to something else I get:

{"servedby":"mw1199","error":{"code":"badtoken","info":"Invalid token","*":"See https://www.wikidata.org/w/api.php for API usage"}}

Change 318492 had a related patch set uploaded (by BearND):
WIP: Add Wikidata description editing dataclient

https://gerrit.wikimedia.org/r/318492

Never mind. Was a copy&paste error, and used the wrong action. With action=wbsetdescription I get:

{"entity":{"descriptions":{"en":{"language":"en","value":"a small town in Aitkin County, Minnesota, USA"}},"id":"Q2045923","type":"item","lastrevid":397427385},"success":1}

For testing I have been using the Wikidata sandbox item https://www.wikidata.org/wiki/Q4115189,
which is linked on enwiki to https://en.wikipedia.org/wiki/Wikipedia:Wikidata/Wikidata_Sandbox.
The wikidata item has links to other wikis (towards the bottom of the page).

  1. In the Android app search for Wikipedia:Wikidata/Wikidata_Sandbox.
  2. Tap on the description.
  3. Make a change
  4. Go back (the success screen is not hooked up yet).
  5. Refresh the page
  6. Observe the new description.

Since this is a sandbox item with a fairly lengthy but helpful description it would be good to revert any changes after testing.

Change 318492 merged by jenkins-bot:
Add Wikidata description editing dataclient

https://gerrit.wikimedia.org/r/318492

Change 320965 had a related patch set uploaded (by BearND):
Handle abusefilters in Wikidata description editing

https://gerrit.wikimedia.org/r/320965

Change 321703 had a related patch set uploaded (by BearND):
Wikidata description editing flow for logged in users

https://gerrit.wikimedia.org/r/321703

Then fetch central auth token (again? - not sure why - this may or may not actually be needed)

@Mhurd It's needed because central auth tokens are valid for one-time use only. Thanks again for all the help! This made it much easier to get this working for Android. We're making the same requests as you did in your prototype.

Change 320965 merged by jenkins-bot:
Handle abusefilters in Wikidata description editing

https://gerrit.wikimedia.org/r/320965

Change 325324 had a related patch set uploaded (by BearND):
Always request edit token before Wikidata description edits

https://gerrit.wikimedia.org/r/325324

Change 321703 abandoned by BearND:
Wikidata description editing flow for logged in users

Reason:
in favor of my series of patches starting with I91599b410dfbc6136838e9301290866ee733aaa8

https://gerrit.wikimedia.org/r/321703

Change 325324 merged by jenkins-bot:
Always request edit token before Wikidata description edits

https://gerrit.wikimedia.org/r/325324