From c3eb02a9a66caa9c9f27729805e646dbea6436dd Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 30 Dec 2014 17:20:55 -0500 Subject: [PATCH] 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 --- includes/ApiQueryExtracts.php | 15 +++++++++++++-- includes/Hooks.php | 26 ++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php index 71559b0..eba4b8a 100644 --- a/includes/ApiQueryExtracts.php +++ b/includes/ApiQueryExtracts.php @@ -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. diff --git a/includes/Hooks.php b/includes/Hooks.php index ed09a7a..2efb271 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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; } -} +}