Page MenuHomePhabricator
Paste P18742

mwaddlink-query (helper script for Add Link API)
ActivePublic

Authored by Tgr on Sat, Jan 15, 3:29 AM.
#!/bin/bash
LANGUAGE="$1"
PROJECT="$2"
TITLE="$3"
REVID="$4"
TITLE_ENCODED=`printf %s "$TITLE" | jq --raw-input --raw-output @uri`
OAUTH_TOKEN="..."
if [[ -z $4 ]]; then
echo 'Usage: mwaddlink <language> <project> <title> <revision>'
echo 'E.g.: mwaddlink en wikipedia "Twin Peaks" 1059847939'
fi
curl --silent --get "https://$LANGUAGE.$PROJECT.org/w/index.php" \
--data-urlencode "title=$TITLE" \
--data-urlencode "oldid=$REVID" \
--data-urlencode "action=raw" \
| jq --raw-input --slurp '{ "pageid": 0, "revid": 0, "wikitext": . }' \
| curl --silent -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $OAUTH_TOKEN" \
"https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/$PROJECT/$LANGUAGE/$TITLE_ENCODED" \
--data-binary @- \
| jq .