Author: brian.mcneil
Description:
I'm writing a set of PHP classes to replace botclasses.php for automated use of the API. I've come across what I feel is a bug, but the API does not return an error for it.
If I request the sections (TOC) for "Does-not-exist", I get an 'empty' result. If I request the sections (TOC) for "Special:Does-not-exist", I get a real error thrown.
This means I've had to code my function such that when an empty list of sections is returned, it checks if the page exists, thus:
$q = '&prop=sections&page='.urlencode($page); if ( $revid !== null ) $q .= '&rvstartid='.$revid; $r = $this->query_content( $q ); if ( isset($r['error']) ) { // Error getting any page data return self::ERR_ret( self::ERR_error, "API error, info:" .$result['error']['info']." Result:".$result['error']['code'] ); } $toc_elem = $r['parse']['sections']; if ( empty($toc_elem) ) { // Empty, does that mean page doesn't exist? if ( $this->get_page( $page ) == false) { return self::ERR_ret( self::ERR_warn, "Requested TOC for nonexistent page" ); } }
Because the API is not returning an error straight away that indicates the page does not exist, a second API call is needed to pull the entire page or throw an error because a nonexistent page was requested.
This can be seen with
http://en.wikinews.org/w/api.php?action=parse&format=xml&prop=sections&page=doesnotexist
versus
http://en.wikinews.org/w/api.php?action=parse&format=xml&prop=sections&page=Special:doesnotexist
Only the latter throws an error.
Version: unspecified
Severity: normal