This might sound silly since I'm a newbie but what would be the best way to call the API from a php script ? This is what I did :-
<?php echo exec( "lynx -dump http://en.wikipedia.org/w/api.php?action=opensearch&search=Malaysia&format=xml" ); ?>
Any suggestions?
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
This might sound silly since I'm a newbie but what would be the best way to call the API from a php script ? This is what I did :-
<?php echo exec( "lynx -dump http://en.wikipedia.org/w/api.php?action=opensearch&search=Malaysia&format=xml" ); ?>
Any suggestions?
Use cURL, or a PHP client library [1].
Roan Kattouw (Catrope)
I prefer to use cURL, but how do you use that properly? Do you mean the "curl" from the command line, or the equivalent PHP function that acts like it?
Run the commad using "exec" function?
On Mon, May 11, 2009 at 3:29 AM, Roan Kattouw roan.kattouw@gmail.comwrote:
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
This might sound silly since I'm a newbie but what would be the best way
to
call the API from a php script ? This is what I did :-
<?php echo exec( "lynx -dump
http://en.wikipedia.org/w/api.php?action=opensearch&search=Malaysia&... "
); ?> Any suggestions?
Use cURL, or a PHP client library [1].
Roan Kattouw (Catrope)
[1] http://www.mediawiki.org/wiki/API:Client_Code#PHP
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
I prefer to use cURL, but how do you use that properly? Do you mean the "curl" from the command line, or the equivalent PHP function that acts like it?
I mean the PHP function. No idea how to use it, though, but you can probably find that somewhere.
Roan Kattouw (Catrope)
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
I prefer to use cURL, but how do you use that properly? Do you mean the "curl" from the command line, or the equivalent PHP function that acts like it?
Run the commad using "exec" function?
ehh... these are, like, basics of the API ;)
if ($api = @file_get_contents('http://en.wikipedia.org/w/api.php?action=query&format=php&titles=Abr...')) { $api_result = unserialize($api); print_r($api_result); }
Michał "Hołek" Połtyn,
The results shows pageids ..
How do I use the pageids to get the content? Is this pageids similar to primary key for a recordset ?
On Mon, May 11, 2009 at 4:52 AM, Michał holek.n@gmail.com wrote:
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
I prefer to use cURL, but how do you use that properly? Do you mean the "curl" from the command line, or the equivalent PHP
function
that acts like it?
Run the commad using "exec" function?
ehh... these are, like, basics of the API ;)
if ($api = @file_get_contents(' http://en.wikipedia.org/w/api.php?action=query&format=php&titles=Abr...' )) { $api_result = unserialize($api); print_r($api_result); }
-- Michał "Hołek" Połtyn
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
I would like to use action=opensearch rather than action=query action=opensearch seems to return me a short result of the query if I specify with limit=1, rather than action=query.
Why does action=opensearch returns nothing after being called by unserialize() function?
2009/5/11 Rezuan Asrah rezuan7@gmail.com
Michał "Hołek" Połtyn,
The results shows pageids ..
How do I use the pageids to get the content? Is this pageids similar to primary key for a recordset ?
On Mon, May 11, 2009 at 4:52 AM, Michał holek.n@gmail.com wrote:
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
I prefer to use cURL, but how do you use that properly? Do you mean the "curl" from the command line, or the equivalent PHP
function
that acts like it?
Run the commad using "exec" function?
ehh... these are, like, basics of the API ;)
if ($api = @file_get_contents(' http://en.wikipedia.org/w/api.php?action=query&format=php&titles=Abr...'http://en.wikipedia.org/w/api.php?action=query&format=php&titles=Abraham_Lincoln%7CFilm%7CLanguage' )) { $api_result = unserialize($api); print_r($api_result); }
-- Michał "Hołek" Połtyn
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
-- Rezuan Asrah question = ( to ) ? be : ! be; -- Wm. Shakespeare
2009/5/10 Rezuan Asrah rezuan7@gmail.com:
I would like to use action=opensearch rather than action=query action=opensearch seems to return me a short result of the query if I specify with limit=1, rather than action=query. Why does action=opensearch returns nothing after being called by unserialize() function?
Because action=opensearch does not obey the format directive. In order to comply with the OpenSearch specification, the information is returned in JSON format. Use json_decode() to get the data.
I'm not quite sure what you'll be using OpenSearch for, though...
In answer to to your first question, there are also several frameworks written in PHP that implement the MediaWiki API. All the ones I know of are listed at http://en.wikipedia.org/wiki/Wikipedia:Creating_a_bot#PHP
Sam
mediawiki-api@lists.wikimedia.org