jenkins-bot has submitted this change and it was merged.
Change subject: Update ApiResult handling for mediawiki/core change I7b37295e
......................................................................
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
---
M includes/api/ApiParseExtender.php
M includes/specials/SpecialMobileLanguages.php
M tests/phpunit/api/ApiMobileViewTest.php
M tests/phpunit/api/ApiParseExtenderTest.php
4 files changed, 55 insertions(+), 14 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/api/ApiParseExtender.php
b/includes/api/ApiParseExtender.php
index 443213f..3350d6e 100644
--- a/includes/api/ApiParseExtender.php
+++ b/includes/api/ApiParseExtender.php
@@ -65,14 +65,30 @@
global $wgMFSpecialCaseMainPage;
if ( $module->getModuleName() == 'parse' ) {
- $data = $module->getResultData();
+ if ( defined( 'ApiResult::META_CONTENT' ) ) {
+ $data = $module->getResult()->getResultData();
+ } else {
+ $data = $module->getResultData();
+ }
$params = $module->extractRequestParams();
if ( isset( $data['parse']['text'] ) &&
$params['mobileformat'] ) {
$result = $module->getResult();
$result->reset();
$title = Title::newFromText(
$data['parse']['title'] );
- $html = MobileFormatter::wrapHTML(
$data['parse']['text']['*'] );
+ $text = $data['parse']['text'];
+ if ( is_array( $text ) ) {
+ if ( defined( 'ApiResult::META_CONTENT'
) &&
+ isset(
$text[ApiResult::META_CONTENT] )
+ ) {
+ $contentKey =
$text[ApiResult::META_CONTENT];
+ } else {
+ $contentKey = '*';
+ }
+ $html = MobileFormatter::wrapHTML(
$text[$contentKey] );
+ } else {
+ $html = MobileFormatter::wrapHTML(
$text );
+ }
$mf = new MobileFormatter( $html, $title );
$mf->setRemoveMedia( $params['noimages'] );
$mf->setIsMainPage( $params['mainpage'] &&
$wgMFSpecialCaseMainPage );
@@ -81,9 +97,12 @@
$mf->remove( array( '.toc', 'mw-editsection' )
);
$mf->filterContent();
- $arr = array();
- ApiResult::setContent( $arr, $mf->getText() );
- $data['parse']['text'] = $arr;
+ if ( is_array( $text ) ) {
+ $text[$contentKey] = $mf->getText();
+ } else {
+ $text = $mf->getText();
+ }
+ $data['parse']['text'] = $text;
$result->addValue( null,
$module->getModuleName(), $data['parse'] );
}
diff --git a/includes/specials/SpecialMobileLanguages.php
b/includes/specials/SpecialMobileLanguages.php
index 9985e79..b41cef9 100644
--- a/includes/specials/SpecialMobileLanguages.php
+++ b/includes/specials/SpecialMobileLanguages.php
@@ -36,15 +36,21 @@
);
$api->execute();
- $data = $api->getResult()->getData();
-
- // Paranoia
- if ( !isset( $data['query']['pages'] ) ) {
- return array();
+ if ( defined( 'ApiResult::META_CONTENT' ) ) {
+ $data = ApiResult::removeMetadata(
+ (array)$api->getResult()->getResultData( array(
'query', 'pages' ) )
+ );
+ } else {
+ $data = $api->getResult()->getData();
+ // Paranoia
+ if ( !isset( $data['query']['pages'] ) ) {
+ return array();
+ }
+ $data = $data['query']['pages'];
}
// Silly strict php
- $pages = array_values( $data['query']['pages'] );
+ $pages = array_values( $data );
$page = array_shift( $pages );
if ( isset( $page['langlinks'] ) ) {
diff --git a/tests/phpunit/api/ApiMobileViewTest.php
b/tests/phpunit/api/ApiMobileViewTest.php
index 96b1ce2..cec2219 100644
--- a/tests/phpunit/api/ApiMobileViewTest.php
+++ b/tests/phpunit/api/ApiMobileViewTest.php
@@ -130,7 +130,14 @@
private function executeMobileViewApi( $api, $expected ) {
$api->execute();
- $result = $api->getResultData();
+ if ( defined( 'ApiResult::META_CONTENT' ) ) {
+ $result = $api->getResult()->getResultData();
+ $result = ApiResult::transformForBC( $result );
+ $result = ApiResult::transformForTypes( $result, array(
'BC' => true ) );
+ $result = ApiResult::removeMetadata( $result );
+ } else {
+ $result = $api->getResultData();
+ }
$this->assertTrue(
isset( $result['mobileview'] ),
'API output should be encloded in mobileview element'
@@ -380,7 +387,11 @@
$api->execute();
- $result = $api->getResultData();
+ if ( defined( 'ApiResult::META_CONTENT' ) ) {
+ $result = $api->getResult()->getResultData();
+ } else {
+ $result = $api->getResultData();
+ }
foreach ( $props as $prop ) {
$this->assertFalse(
diff --git a/tests/phpunit/api/ApiParseExtenderTest.php
b/tests/phpunit/api/ApiParseExtenderTest.php
index f12005f..d07250b 100644
--- a/tests/phpunit/api/ApiParseExtenderTest.php
+++ b/tests/phpunit/api/ApiParseExtenderTest.php
@@ -30,7 +30,12 @@
$req = new FauxRequest( $params );
$api = new ApiMain( $req );
$api->execute();
- $data = $api->getResultData();
+ if ( defined( 'ApiResult::META_CONTENT' ) ) {
+ $data = $api->getResult()->getResultData();
+ $data = ApiResult::transformForBC( $data );
+ } else {
+ $data = $api->getResultData();
+ }
$this->assertFalse( isset( $data['errors'] ) );
$text = preg_replace( "/[\r\n]/", '', trim(
$data['parse']['text']['*'] ) );
$expected = preg_replace( "/[\r\n]/", '', trim( $expected ) );
--
To view, visit https://gerrit.wikimedia.org/r/183589
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits