Nikerabbit has submitted this change and it was merged.

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, 73 insertions(+), 4 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



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..084a0d6
--- /dev/null
+++ b/api/ApiContentTranslationConfiguration.php
@@ -0,0 +1,53 @@
+<?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::isValidBuiltInCode( $source ) || 
!Language::isValidBuiltInCode( $target )  ) {
+                       $this->dieUsage( 'Invalid language', 'invalidlanguage' 
);
+               }
+               $filename = __DIR__ . 
"/../modules/source/conf/$source-$target.json";
+               if ( is_readable( $filename ) ) {
+                       $contents = file_get_contents( $filename );
+               }
+               // Output the file's contents raw
+               $this->getResult()->addValue( null, 'configuration', 
json_decode( $contents, false ) );
+       }
+
+       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..08d2c94 100644
--- a/modules/source/ext.cx.source.filter.js
+++ b/modules/source/ext.cx.source.filter.js
@@ -19,8 +19,14 @@
         * @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,
+                       format: 'json'
+               } );
        }
 
        /**
@@ -174,8 +180,8 @@
 
                mw.hook( 'mw.cx.source.loaded' ).add( function () {
                        fetchFilterConfiguration( mw.cx.sourceLanguage, 
mw.cx.targetLanguage )
-                               .done( function ( configuration ) {
-                                       filter.filter( configuration );
+                               .done( function ( response ) {
+                                       filter.filter( response.configuration );
                                } )
                                .fail( function () {
                                        // If the configuration file is not 
present, or not able

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iecb948005e6a27c93e3de7e9947e840e37ee5609
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Jsahleen <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to