Retry parse call if it fails to get section

Some pages don't support extracting sections.  If the parse FauxRequest
fails then try again without the request to get a section.

Bug T78721

Change-Id: I37320208af38ea39e80b292b009bbaa7ab6d1c96
This commit is contained in:
Nik Everett 2014-12-17 10:01:06 -05:00
parent 6b5cda9c11
commit 24308948ed

View file

@ -211,8 +211,23 @@ class ApiQueryExtracts extends ApiQueryBase {
}
// in case of cache miss, render just the needed section
$api = new ApiMain( new FauxRequest( $request ) );
$api->execute();
$data = $api->getResultData();
try {
$api->execute();
$data = $api->getResultData();
} catch ( UsageException $e ) {
if ( $e->getCodeString() === 'nosuchsection' ) {
// Looks like we tried to get the intro to a page without
// sections! Lets just grab what we can get.
unset( $request['section'] );
$api = new ApiMain( new FauxRequest( $request ) );
$api->execute();
$data = $api->getResultData();
} else {
// Some other unexpected error - lets just report it to the user
// on the off chance that is the right thing.
throw $e;
}
}
wfProfileOut( __METHOD__ );
return $data['parse']['text']['*'];
}