Update ApiResult handling for mediawiki/core change I7b37295e

Change I7b37295e for mediawiki/core deprecates several methods, and more
importantly changes the format of the data returned from
ApiResult::getData(). This change should handle these differences in a
backwards-compatible manner.

Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678e
This commit is contained in:
Brad Jorsch 2014-12-30 17:20:55 -05:00
parent d9869ef8d0
commit c3eb02a9a6
2 changed files with 33 additions and 8 deletions

View file

@ -19,6 +19,7 @@
namespace TextExtracts;
use ApiBase;
use ApiResult;
use ApiMain;
use ApiQueryBase;
use Config;
@ -189,7 +190,12 @@ class ApiQueryExtracts extends ApiQueryBase {
$api = new ApiMain( new FauxRequest( $request ) );
try {
$api->execute();
$data = $api->getResultData();
if ( defined( 'ApiResult::META_CONTENT' ) ) {
$data = $api->getResult()->getResultData();
$data = ApiResult::transformForBC( $data );
} else {
$data = $api->getResultData();
}
} catch ( UsageException $e ) {
if ( $e->getCodeString() === 'nosuchsection' ) {
// Looks like we tried to get the intro to a page without
@ -197,7 +203,12 @@ class ApiQueryExtracts extends ApiQueryBase {
unset( $request['section'] );
$api = new ApiMain( new FauxRequest( $request ) );
$api->execute();
$data = $api->getResultData();
if ( defined( 'ApiResult::META_CONTENT' ) ) {
$data = $api->getResult()->getResultData();
$data = ApiResult::transformForBC( $data );
} else {
$data = $api->getResultData();
}
} else {
// Some other unexpected error - lets just report it to the user
// on the off chance that is the right thing.

View file

@ -4,6 +4,7 @@ namespace TextExtracts;
use ApiMain;
use ApiResult;
use ConfigFactory;
use FauxRequest;
@ -30,13 +31,26 @@ class Hooks {
) )
);
$api->execute();
$data = $api->getResultData();
foreach ( $pageIds as $id ) {
if ( isset( $data['query']['pages'][$id]['extract']['*'] ) ) {
$results[$id]['extract'] = $data['query']['pages'][$id]['extract']['*'];
$results[$id]['extract trimmed'] = false;
if ( defined( 'ApiResult::META_CONTENT' ) ) {
$data = $api->getResult()->getResultData( array( 'query', 'pages' ) );
foreach ( $pageIds as $id ) {
$contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] )
? $data[$id]['extract'][ApiResult::META_CONTENT]
: '*';
if ( isset( $data[$id]['extract'][$contentKey] ) ) {
$results[$id]['extract'] = $data[$id]['extract'][$contentKey];
$results[$id]['extract trimmed'] = false;
}
}
} else {
$data = $api->getResultData();
foreach ( $pageIds as $id ) {
if ( isset( $data['query']['pages'][$id]['extract']['*'] ) ) {
$results[$id]['extract'] = $data['query']['pages'][$id]['extract']['*'];
$results[$id]['extract trimmed'] = false;
}
}
}
return true;
}
}
}