Santhosh has uploaded a new change for review.

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

Change subject: Support common configuration for all language pairs
......................................................................

Support common configuration for all language pairs

Content Translation can selectively adapt the content elements of
source article. Some parts like templates cannot be adapted easily.

There are configuration for language pairs to do this adaptation.
In addition to them, introduce a common.json. The configuration given in
that file is common for all language pairs.
Language pair specific configuration can optionally override them.

Change-Id: Iec7ae9f8bbb511dd87f163c2f65ff92601dfa1e4
---
M api/ApiContentTranslationConfiguration.php
A modules/source/conf/README
A modules/source/conf/common.json
3 files changed, 45 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/67/194467/1

diff --git a/api/ApiContentTranslationConfiguration.php 
b/api/ApiContentTranslationConfiguration.php
index 084a0d6..c631e0b 100644
--- a/api/ApiContentTranslationConfiguration.php
+++ b/api/ApiContentTranslationConfiguration.php
@@ -10,7 +10,8 @@
 class ApiContentTranslationConfiguration extends ApiBase {
 
        public function execute() {
-               $contents = "{}";
+               $commonContent = "{}";
+               $configuration =  null;
                $this->getMain()->setCacheMode( 'public' );
                $this->getMain()->setCacheMaxAge( 2419200 );
 
@@ -20,12 +21,34 @@
                if ( !Language::isValidBuiltInCode( $source ) || 
!Language::isValidBuiltInCode( $target )  ) {
                        $this->dieUsage( 'Invalid language', 'invalidlanguage' 
);
                }
+               // Read common configuraiton
+               $commonFileName =  __DIR__ . 
"/../modules/source/conf/common.json";
+               if ( is_readable( $commonFileName ) ) {
+                       $commonContent = file_get_contents( $commonFileName );
+               }
+               $commonConfiguration = json_decode( $commonContent, false );
+
+               // Read configuraiton for language pair
                $filename = __DIR__ . 
"/../modules/source/conf/$source-$target.json";
                if ( is_readable( $filename ) ) {
                        $contents = file_get_contents( $filename );
+                       $configuration = json_decode( $contents, false );
                }
-               // Output the file's contents raw
-               $this->getResult()->addValue( null, 'configuration', 
json_decode( $contents, false ) );
+
+               if ( !$configuration ) {
+                       // No language specific configuration.
+                       $configuration = $commonConfiguration;
+               } else {
+                       // For now, we use only templates in configuration.
+                       // If we have more keys in configuration, this must be
+                       // a separate method to merge configurations
+                       $configuration->templates  = (object) array_merge(
+                               ( array ) $commonConfiguration->templates,
+                               ( array ) $configuration->templates
+                       );
+               }
+
+               $this->getResult()->addValue( null, 'configuration', 
$configuration );
        }
 
        public function getAllowedParams() {
diff --git a/modules/source/conf/README b/modules/source/conf/README
new file mode 100644
index 0000000..8e38589
--- /dev/null
+++ b/modules/source/conf/README
@@ -0,0 +1,11 @@
+Content Translation can selectively adapt the content elements of source 
article.
+Some parts like templates cannot be adapted easily.
+
+This directory contains configuration for language pairs to do this adaptation.
+In addition to them, there is a common.json, and the configuration given in
+that file is common for all language pairs. Language pair specific 
configuration
+can optionally override them.
+
+Currently configuration support white listing certain templates
+
+See https://www.mediawiki.org/wiki/Content_translation/Templates for more 
details.
diff --git a/modules/source/conf/common.json b/modules/source/conf/common.json
new file mode 100644
index 0000000..a801331
--- /dev/null
+++ b/modules/source/conf/common.json
@@ -0,0 +1,8 @@
+{
+       "templates": {
+               "Reflist": {
+                       "targetname": "Reflist",
+                       "editable": false
+               }
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec7ae9f8bbb511dd87f163c2f65ff92601dfa1e4
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

Reply via email to