Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/190788
Change subject: Configuration API to read configuration for language pairs
......................................................................
Configuration API to read configuration for language pairs
Introduce ApiContentTranslationConfiguration.php to load the
language pair specific configuration file.
Currently, it is used for whitelisting templates per language pair
Bug: T69457
Change-Id: Iecb948005e6a27c93e3de7e9947e840e37ee5609
---
M Autoload.php
M ContentTranslation.php
A api/ApiContentTranslationConfiguration.php
M i18n/en.json
M i18n/qqq.json
M modules/source/ext.cx.source.filter.js
6 files changed, 78 insertions(+), 2 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/88/190788/1
diff --git a/Autoload.php b/Autoload.php
index b92fa3b..2be5567 100644
--- a/Autoload.php
+++ b/Autoload.php
@@ -11,6 +11,7 @@
$dir = __DIR__;
$wgAutoloadClasses += array(
+ 'ApiContentTranslationConfiguration' =>
"$dir/api/ApiContentTranslationConfiguration.php",
'ApiContentTranslationPublish' =>
"$dir/api/ApiContentTranslationPublish.php",
'ApiContentTranslationDelete' =>
"$dir/api/ApiContentTranslationDelete.php",
'ApiQueryContentTranslation' =>
"$dir/api/ApiQueryContentTranslation.php",
diff --git a/ContentTranslation.php b/ContentTranslation.php
index e6935c0..895d3df 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -54,6 +54,7 @@
$GLOBALS['wgSpecialPages']['ContentTranslationStats'] =
'SpecialContentTranslationStats';
// API modules
+$GLOBALS['wgAPIModules']['cxconfiguration'] =
'ApiContentTranslationConfiguration';
$GLOBALS['wgAPIModules']['cxpublish'] = 'ApiContentTranslationPublish';
$GLOBALS['wgAPIModules']['cxdelete'] = 'ApiContentTranslationDelete';
$GLOBALS['wgAPIListModules']['contenttranslation'] =
'ApiQueryContentTranslation';
diff --git a/api/ApiContentTranslationConfiguration.php
b/api/ApiContentTranslationConfiguration.php
new file mode 100644
index 0000000..16ae7eb
--- /dev/null
+++ b/api/ApiContentTranslationConfiguration.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * API to get the Content Translation configuration for the given language
pair.
+ *
+ * @file
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+class ApiContentTranslationConfiguration extends ApiBase {
+
+ public function execute() {
+ $contents = "{}";
+ $this->getMain()->setCacheMode( 'public' );
+ $this->getMain()->setCacheMaxAge( 2419200 );
+
+ $params = $this->extractRequestParams();
+ $source = $params['from'];
+ $target = $params['to'];
+ if ( !Language::isValidCode( $source ) || !Language::isValidCode(
$target ) ) {
+ $this->dieUsage( 'Invalid language', 'invalidlanguage' );
+ }
+ $filename = __DIR__ . "/../modules/source/conf/$source-$target.json";
+ if ( file_exists( $filename ) ) {
+ $contents = file_get_contents( $filename );
+ }
+ // Output the file's contents raw
+ $this->getResult()->addValue( null, 'text', $contents );
+ $this->getResult()->addValue( null, 'mime', 'application/json' );
+ }
+
+ public function getCustomPrinter() {
+ return new ApiFormatRaw(
+ $this->getMain(),
+ $this->getMain()->createPrinterByName( 'json' )
+ );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'from' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_TYPE => 'string',
+ ),
+ 'to' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_TYPE => 'string',
+ ),
+ );
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ */
+ protected function getExamplesMessages() {
+ return array(
+ 'action=cxconfiguration&from=es&to=ca'
+ => 'apihelp-cxconfiguration-example-1',
+ );
+ }
+}
diff --git a/i18n/en.json b/i18n/en.json
index df91012..c4b0228 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -115,6 +115,10 @@
"apihelp-query+contenttranslation-example-2": "Get translations draft
by id.",
"apihelp-query+contenttranslation-example-3": "Find any translation for
the given title between given language pair",
"apihelp-query+contenttranslationstats-example-1": "Get content
translation statistics for all languages.",
+ "apihelp-cxconfiguration-description": "Fetch the Content Translation
configuration json for the given language pair",
+ "apihelp-cxconfiguration-param-from": "The source language code.",
+ "apihelp-cxconfiguration-param-to": "The target language code.",
+ "apihelp-cxconfiguration-example-1": "Fetch the Content Translation
configuration json for Spanish-Catalan language pair",
"cx-save-draft-save-success": "Saved {{PLURAL:$1|a minute ago|$1
minutes ago|0=just now}}",
"cx-save-draft-saving": "Saving...",
"cx-save-draft-tooltip": "Translation drafts are saved automatically",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 99e2e95..34fc79a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -120,6 +120,10 @@
"apihelp-query+contenttranslation-example-2":
"{{doc-apihelp-example|query+contenttranslation}}",
"apihelp-query+contenttranslation-example-3":
"{{doc-apihelp-example|query+contenttranslation}}",
"apihelp-query+contenttranslationstats-example-1":
"{{doc-apihelp-example|query+contenttranslationstats}}",
+ "apihelp-cxconfiguration-description":
"{{doc-apihelp-description|cxconfiguration}}",
+ "apihelp-cxconfiguration-param-from":
"{{doc-apihelp-param|cxconfiguration|from}}",
+ "apihelp-cxconfiguration-param-to":
"{{doc-apihelp-param|cxconfiguration|to}}",
+ "apihelp-cxconfiguration-example-1":
"{{doc-apihelp-example|cxconfiguration}}",
"cx-save-draft-save-success": "\"Saved\" refers to a draft of a
translated page that was saved recently.",
"cx-save-draft-saving": "Label of button to save the translation as
draft while saving is in progress\n{{Identical|Saving}}",
"cx-save-draft-tooltip": "Tooltip text shown for the save status
indicator text in the header of [[Special:ContentTranslation]].\n\nParameters:
\n* $1 - the number of minutes ago the translation was saved.",
diff --git a/modules/source/ext.cx.source.filter.js
b/modules/source/ext.cx.source.filter.js
index be0b8a1..dbe4e91 100644
--- a/modules/source/ext.cx.source.filter.js
+++ b/modules/source/ext.cx.source.filter.js
@@ -19,8 +19,13 @@
* @return {jQuery.Promise}
*/
function fetchFilterConfiguration( sourceLanguage, targetLanguage ) {
- return $.getJSON( mw.config.get( 'wgExtensionAssetsPath' ) +
- '/ContentTranslation/modules/source/conf/' +
sourceLanguage + '-' + targetLanguage + '.json' );
+ var api = new mw.Api();
+
+ return api.get( {
+ action: 'cxconfiguration',
+ from: sourceLanguage,
+ to: targetLanguage
+ } );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/190788
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecb948005e6a27c93e3de7e9947e840e37ee5609
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits