Page MenuHomePhabricator
Authored By
dom_walden
Jul 22 2019, 2:39 PM
Size
2 KB
Referenced Files
None
Subscribers
None

copyvio_repro.py

# Copyright (c) 2019 Dominic Walden
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Example use (on beta):
# $ python3 copyvio_repro.py -u Username -p Password --url "https://en.wikipedia.beta.wmflabs.org/w/api.php" -r 123
# where Username has the pagetriage-copyvio right and -r is the revision you want marked copyvio.
import argparse
import requests
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description='''Example use (on beta):
$ python3 copyvio_repro.py -u Username -p Password --url 'https://en.wikipedia.beta.wmflabs.org/w/api.php' -r 123
where Username has the pagetriage-copyvio right and -r is the revision you want marked copyvio.''')
parser.add_argument("-u", "--user", required=True, help="Username of a user who has 'pagetriage-copyvio' rights")
parser.add_argument("-p", "--password", required=True)
parser.add_argument("--url", required=True, help="API endpoint of the wiki you want to modify")
parser.add_argument("-r", "--revid", required=True, help="ID of the revision you want to mark as copyvio")
args = parser.parse_args()
session = requests.session()
params_1 = {
"action": "query",
"meta": "tokens",
"type": "login",
"format": "json"
}
r = session.get(url=args.url, params=params_1)
data = r.json()
login_token = data["query"]["tokens"]["logintoken"]
params_2 = {
"action": "login",
"lgname": args.user,
"lgpassword": args.password,
"lgtoken": login_token,
"format": "json"
}
r = session.post(url=args.url, data=params_2)
params_3 = {
"action": "query",
"meta": "tokens",
"format": "json"
}
r = session.get(url=args.url, params=params_3)
data = r.json()
csrf_token = data["query"]["tokens"]["csrftoken"]
params_4 = {
'action': "pagetriagetagcopyvio",
'revid': args.revid,
'token': csrf_token,
'format': "json"
}
r = session.post(url=args.url, data=params_4)
print(r.json())

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7765676
Default Alt Text
copyvio_repro.py (2 KB)

Event Timeline