API:Allrevisions/Sample code 1
Appearance
From mediawiki.org
Python
[edit ]#This file is auto-generated. See modules.json and autogenerator.py for details #!/usr/bin/python3 """ get_allrevisions.py MediaWiki API Demos Demo of `Allrevisions` module: get revision data of multiple pages and users MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "arvprop": "ids|flags|timestamp", "arvuser": "Place holder", "list": "allrevisions", "format": "json" } R = S.get(url=URL, params=PARAMS) DATA = R.json() ALLREVISIONS = DATA["query"]["allrevisions"] for rev in ALLREVISIONS: print(rev)
PHP
[edit ]<?php //This file is autogenerated. See modules.json and autogenerator.py for details /* get_allrevisions.php MediaWiki API Demos Demo of `Allrevisions` module: get revision data of multiple pages and users MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "list" => "allrevisions", "arvprop" => "ids|flags|timestamp", "arvuser" => "Place holder" ]; $url = $endPoint . "?" . http_build_query( $params ); $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $output = curl_exec( $ch ); curl_close( $ch ); $result = json_decode( $output, true ); foreach( $result["query"]["allrevisions"] as $k => $v ) { foreach( $v["revisions"] as $k => $v ) { var_dump( $v ); } }
JavaScript
[edit ]//This file is autogenerated. See modules.json and autogenerator.py for details /* get_allrevisions.js MediaWiki API Demos Demo of `Allrevisions` module: get revision data of multiple pages and users MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", format:"json", list:"allrevisions", arvprop:"ids|flags|timestamp", arvuser:"Place holder" }; url=url+"?origin=*"; Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];}); fetch(url) .then(function(response){returnresponse.json();}) .then(function(response){ varrevs=response.query.allrevisions; for(varrinrevs){ console.log(revs[r]); } }) .catch(function(error){console.log(error);});
MediaWiki JS
[edit ]// This file is autogenerated. See modules.json and autogenerator.py for details /* get_allrevisions.js MediaWiki API Demos Demo of `Allrevisions` module: get revision data of multiple pages and users MIT License */ varparams={ action:'query', format:'json', list:'allrevisions', arvprop:'ids|flags|timestamp', arvuser:'Place holder' }, api=newmw.Api(); api.get(params).done(function(data){ varrevs=data.query.allrevisions, r; for(rinrevs){ console.log(revs[r]); } });