[MediaWiki-commits] [Gerrit] mediawiki...JsonConfig[master]: Remove bogus restrictions in JCDataApi and fix example query...

2016-11-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Remove bogus restrictions in JCDataApi and fix example query 
strings
..


Remove bogus restrictions in JCDataApi and fix example query strings

There's nothing in there that in any way requires JSON format. If we add
the proper call to ApiResult::addMetadataToResultVars, it's not even
ugly in XML format.

Change-Id: I476aad09655a2822381a2c61690b4b0ad423151e
---
M i18n/en.json
M includes/JCApi.php
M includes/JCDataApi.php
3 files changed, 9 insertions(+), 17 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  Gergő Tisza: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index e327c20..069ecf6 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -49,7 +49,7 @@
"apihelp-jsonconfig-example-1": "Show configuration",
"apihelp-jsonconfig-example-2": "Reset [[Zero:TEST]]",
"apihelp-jsonconfig-example-3": "Reload [[Zero:TEST]]",
-   "apihelp-jsondata-description": "Retrieve localized JSON data. This API 
only supports format=json and formatversion=2 or later.",
+   "apihelp-jsondata-description": "Retrieve localized JSON data.",
"apihelp-jsondata-param-title": "Title to get. By default assumes 
namespace to be \"Data:\"",
"apihelp-jsondata-example-1": "Get JSON content of the Sample.tab page, 
localized to user's language",
"apihelp-jsondata-example-2": "Get JSON content of the Sample.tab page 
localized to French"
diff --git a/includes/JCApi.php b/includes/JCApi.php
index 9806feb..bf369f5 100644
--- a/includes/JCApi.php
+++ b/includes/JCApi.php
@@ -146,9 +146,9 @@
return [
'action=jsonconfig=jsonfm'
=> 'apihelp-jsonconfig-example-1',
-   
'api.php?action=jsonconfig=reset=480=TEST=jsonfm'
+   
'action=jsonconfig=reset=480=TEST=jsonfm'
=> 'apihelp-jsonconfig-example-2',
-   
'api.php?action=jsonconfig=reload=480=TEST=jsonfm'
+   
'action=jsonconfig=reload=480=TEST=jsonfm'
=> 'apihelp-jsonconfig-example-3',
];
}
diff --git a/includes/JCDataApi.php b/includes/JCDataApi.php
index 5a1d79b..8eefe9d 100644
--- a/includes/JCDataApi.php
+++ b/includes/JCDataApi.php
@@ -2,6 +2,7 @@
 namespace JsonConfig;
 
 use ApiBase;
+use ApiResult;
 use ApiFormatJson;
 
 /**
@@ -10,18 +11,6 @@
 class JCDataApi extends ApiBase {
 
public function execute() {
-   $printerParams = 
$this->getMain()->getPrinter()->extractRequestParams();
-   if ( !( $this->getMain()->getPrinter() instanceof ApiFormatJson 
) ||
-!isset( $printerParams['formatversion'] )
-   ) {
-   $this->dieUsage( 'This module only supports format=json 
and format=jsonfm',
-   'invalidparammix' );
-   }
-   if ( $printerParams['formatversion'] == 1 ) {
-   $this->dieUsage( 'This module only supports 
formatversion=2 or later',
-   'invalidparammix' );
-   }
-
$params = $this->extractRequestParams();
$jct = JCSingleton::parseTitle( $params['title'], NS_DATA );
if ( !$jct ) {
@@ -37,6 +26,9 @@
/** @var JCDataContent $data */
$data = $data->getLocalizedData( $this->getLanguage() );
}
+
+   // Armor any API metadata in $data
+   $data = ApiResult::addMetadataToResultVars( (array)$data, 
is_object( $data ) );
 
$this->getResult()->addValue( null, $this->getModuleName(), 
$data );
 
@@ -55,9 +47,9 @@
 
protected function getExamplesMessages() {
return [
-   
'api.php?action=jsondata=2=jsonfm=Sample.tab'
+   
'action=jsondata=2=jsonfm=Sample.tab'
=> 'apihelp-jsondata-example-1',
-   
'api.php?action=jsondata=2=jsonfm=Sample.tab=fr'
+   
'action=jsondata=2=jsonfm=Sample.tab=fr'
=> 'apihelp-jsondata-example-2',
];
}

-- 
To view, visit https://gerrit.wikimedia.org/r/320523
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I476aad09655a2822381a2c61690b4b0ad423151e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Anomie 
Gerrit-Reviewer: Anomie 
Gerrit-Reviewer: Gergő Tisza 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: Siebrand 

[MediaWiki-commits] [Gerrit] mediawiki...JsonConfig[master]: Remove bogus restrictions in JCDataApi and fix example query...

2016-11-08 Thread Anomie (Code Review)
Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/320523

Change subject: Remove bogus restrictions in JCDataApi and fix example query 
strings
..

Remove bogus restrictions in JCDataApi and fix example query strings

There's nothing in there that in any way requires JSON format. If we add
the proper call to ApiResult::addMetadataToResultVars, it's not even
ugly in XML format.

Change-Id: I476aad09655a2822381a2c61690b4b0ad423151e
---
M i18n/en.json
M includes/JCApi.php
M includes/JCDataApi.php
3 files changed, 9 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/JsonConfig 
refs/changes/23/320523/1

diff --git a/i18n/en.json b/i18n/en.json
index e327c20..069ecf6 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -49,7 +49,7 @@
"apihelp-jsonconfig-example-1": "Show configuration",
"apihelp-jsonconfig-example-2": "Reset [[Zero:TEST]]",
"apihelp-jsonconfig-example-3": "Reload [[Zero:TEST]]",
-   "apihelp-jsondata-description": "Retrieve localized JSON data. This API 
only supports format=json and formatversion=2 or later.",
+   "apihelp-jsondata-description": "Retrieve localized JSON data.",
"apihelp-jsondata-param-title": "Title to get. By default assumes 
namespace to be \"Data:\"",
"apihelp-jsondata-example-1": "Get JSON content of the Sample.tab page, 
localized to user's language",
"apihelp-jsondata-example-2": "Get JSON content of the Sample.tab page 
localized to French"
diff --git a/includes/JCApi.php b/includes/JCApi.php
index 9806feb..bf369f5 100644
--- a/includes/JCApi.php
+++ b/includes/JCApi.php
@@ -146,9 +146,9 @@
return [
'action=jsonconfig=jsonfm'
=> 'apihelp-jsonconfig-example-1',
-   
'api.php?action=jsonconfig=reset=480=TEST=jsonfm'
+   
'action=jsonconfig=reset=480=TEST=jsonfm'
=> 'apihelp-jsonconfig-example-2',
-   
'api.php?action=jsonconfig=reload=480=TEST=jsonfm'
+   
'action=jsonconfig=reload=480=TEST=jsonfm'
=> 'apihelp-jsonconfig-example-3',
];
}
diff --git a/includes/JCDataApi.php b/includes/JCDataApi.php
index 5a1d79b..8eefe9d 100644
--- a/includes/JCDataApi.php
+++ b/includes/JCDataApi.php
@@ -2,6 +2,7 @@
 namespace JsonConfig;
 
 use ApiBase;
+use ApiResult;
 use ApiFormatJson;
 
 /**
@@ -10,18 +11,6 @@
 class JCDataApi extends ApiBase {
 
public function execute() {
-   $printerParams = 
$this->getMain()->getPrinter()->extractRequestParams();
-   if ( !( $this->getMain()->getPrinter() instanceof ApiFormatJson 
) ||
-!isset( $printerParams['formatversion'] )
-   ) {
-   $this->dieUsage( 'This module only supports format=json 
and format=jsonfm',
-   'invalidparammix' );
-   }
-   if ( $printerParams['formatversion'] == 1 ) {
-   $this->dieUsage( 'This module only supports 
formatversion=2 or later',
-   'invalidparammix' );
-   }
-
$params = $this->extractRequestParams();
$jct = JCSingleton::parseTitle( $params['title'], NS_DATA );
if ( !$jct ) {
@@ -37,6 +26,9 @@
/** @var JCDataContent $data */
$data = $data->getLocalizedData( $this->getLanguage() );
}
+
+   // Armor any API metadata in $data
+   $data = ApiResult::addMetadataToResultVars( (array)$data, 
is_object( $data ) );
 
$this->getResult()->addValue( null, $this->getModuleName(), 
$data );
 
@@ -55,9 +47,9 @@
 
protected function getExamplesMessages() {
return [
-   
'api.php?action=jsondata=2=jsonfm=Sample.tab'
+   
'action=jsondata=2=jsonfm=Sample.tab'
=> 'apihelp-jsondata-example-1',
-   
'api.php?action=jsondata=2=jsonfm=Sample.tab=fr'
+   
'action=jsondata=2=jsonfm=Sample.tab=fr'
=> 'apihelp-jsondata-example-2',
];
}

-- 
To view, visit https://gerrit.wikimedia.org/r/320523
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I476aad09655a2822381a2c61690b4b0ad423151e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Anomie 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits