Hi All: I have blown 8 hrs over 2 days trying to figure out what is wrong with my PHP program to try to do a query.
I am trying to build a simple PHP program to get the contents of recent changes on a wiki I admin.
Here is the code, with a couple of things "anonymized" (surrounded by << >>):
========= begin code ===========
<?php //login and get the correct security values to pass in on subsequent queries $wikiURL = "<<mydomain>>/mediawiki"; $logincmd = $wikiURL."/api.php?action=login&lgname=Sgg&lgpassword=<<mypwd>>&format=json";
$handle = fopen($logincmd,"rb"); $contents = stream_get_contents($handle); fclose($handle);
$loginVals = json_decode($contents, true);
if($loginVals["login"]["result"] != "Success"){ echo"Failed to login, result returned ", $loginVals["login"]["result"]; exit(-1); }
//set up the security parm values and create query $userid = $loginVals["login"]["lguserid"]; $username = $loginVals["login"]["lgusername"]; $token = $loginVals["login"]["lgtoken"];
$query = $wikiURL."/api.php?action=query&list=recentchanges&format=xml&lgtoken=$token&lgusername=$username&lguserid=$userid"; echo" Query",$query," ";
//execute the get and print the results $handle = fopen($query,"rb"); $contents = stream_get_contents($handle); fclose($handle);
print_r(" Query results"); print_r($contents); print_r(" end query results "); ?>
===============end code ================
The login works fine, returns reasonable looking tokens. The Query results, however are empty.
When I copy the query that was produced (note the echo statement), and paste that into a browser (that I have previously used to login to the wiki, I get some query results back. When I paste that query into a browser I rarely use (ie haven't logged into the wiki), I get empty result set.
So, am I misusing the login parms somehow on the query url? Are the login parms not working? Should I use cookie manipulation instead?
Please help
sgg