Thread:Project:Support desk/Using MediaWiki API with the Continue/Query-Continue Commands

Hi everyone,

I need some help Using  the Mediawiki API with the "Continue" or "query-continue" Command to pull information from my wiki articles. I have a large number of wiki articles (more than 800 currently) and I need to use the api to pull them in batches of 50 and then print ou sections.

My API call works properly:

http://localhost/w/api.php?action=query&list=allpages&apfrom=a&apto=z&apnamespace=0&format=xml&aplimit=50 I am querying all pages, therefore "apfrom" and "apto".

I just need help processing the code with PHP and CURL accessing the API and processing the batches of 50 and using the "continue" to access more records until I hit the end. So far my php code is:

//the CURL commands here work and outputs a data set but only for the first 50 records, so I need to //call "continue" to get to the end. // Mediawiki has a limit of 500 records so it's good practice to call continue anyways

$url = sprintf(http://localhost/w/api.php?                                                                                              action=query&list=allpages&apfrom=a&apto=z&apnamespace=0&format=xml&aplimit=50'); $ch=curl_init; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'My site'); $res = curl_exec($ch);

$continue = ''; while ( //something gets set to true here not sure what, maybe query-continue?) {		//Maybe I need something other than $res['query-continue]?? if (empty($res['query-continue'])) {			exit; }		else {			$continue = '&apcontinue='.urlencode($res['query-continue']);

//Again not sure if $res['query']['allpages'] is right, just a guess foreach ($res['query']['allpages'] as $v) {					echo $v['title']; }

}

}

Can someone correct my while loop code above so I can do a simple print out of the title from each wiki article in the loop? I've done a lot of searching online but I'm stuck!! I found a python loop example at http://www.mediawiki.org/wiki/API:Query but I have to do it in PHP. And the mediawiki documentation doesn't have examples for php and other langauges, only python. And I am not sure if I call continue or query-continue.

Thanks for your help!

Peter