Im on 1.14
So say, I wanted to query the main page for a list of all of its categories, I would think I could do this.
$params = array ( 'action' => 'query', 'prop' => 'categories', 'cllimit' => 500, 'titles' => 'Main Page', 'format' => 'json' );
$api = new ApiMain($params); $api->execute(); $data = & $api->getResultData();
But I get Call to a member function getVal() on a non-object in includes/api/ ApiMain.php on line 146
So I figure this is not how it is done.
On Jun 20, 2009, at 2:27 AM, Michael Daly wrote:
When you said "through plain PHP," I interpreted that to mean outside the wiki - i.e. a stand alone PHP program. You could do that the way I showed, but what you are pointing to with that URL is for use within the wiki - e.g. from within an extension.
What version of MW are you using - the hook function you need may be in your version if you are not running 1.14 or 1.15.
Without seeing details of what you're doing, anything I say would be a wild guess.
Adam Meyer wrote:
It looks like this would be my answer. http://www.mediawiki.org/wiki/API:Calling_internally
But it dosnt work. I get some error about a hook function missing or something.
But I would love it if it could work this easily.
On Jun 19, 2009, at 9:28 PM, Michael Daly wrote:
Adam Meyer wrote:
Is this doable?
There may be a better way to do this, but...
In PHP, you can get the wiki page as if it was a file:
$myPageUrl ="http://example.com/api.php?action=parse&text=%7B%7B:Main Page}}__TOC__&prop=sections"; // set to 20 second timeout then restore. $currentTimeout = ini_set( 'default_socket_timeout', "20" ); $myPage = file($myPageUrl); ini_set( 'default_socket_timeout', $currentTimeout );
This will produce a list of section headers. Count them to see what the last one is.
I've found it useful to ensure that any timeouts due to the web page access are trapped here and don't run into the overall program timeout. Restore the old timeout once the page is read.
If you need to set up a session (e.g. to log in and stay logged in while you get data from pages) look up curl in the online PHP manual.
Mike
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l