Santhosh has uploaded a new change for review.

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

Change subject: Expose published translation with source-target URL pairs
......................................................................

Expose published translation with source-target URL pairs

Introducing an API to expose the published translations information
so that people interested in analysing the translation pairs
(can't say parallel corpora in strict sense) get minimal informaiton
to work with.

Sample output

"result": {
        "translations": [
            {
                "sourceTitle": "SourceTitle",
                "targetTitle": "TranslatedTitle",
                "sourceLanguage": "es",
                "targetLanguage": "pt",
                "sourceURL": "//es.wikipedia.org/wiki/SourceTitle",
                "targetURL": "//pt.wikiedia.org/wiki/TranslatedTitle",
                "stats": {
                    "any": 1,
                    "human": 0.45176110260337,
                    "mt": 0.54823889739663,
                    "mtSectionsCount": 2
                }
            },
                ....
        ]
        }

This is not a final version of information we wanted to expose, but just
starting work on it. As we improvise our infrastructure we may able to
provide more useful information

Bug: T87353
Change-Id: I0094102b7f04bd249e7f69502737f671755165c1
---
M Autoload.php
M ContentTranslation.php
A api/ApiQueryPublishedTranslations.php
M i18n/en.json
M i18n/qqq.json
M includes/Translation.php
6 files changed, 126 insertions(+), 1 deletion(-)


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

diff --git a/Autoload.php b/Autoload.php
index 2be5567..500f040 100644
--- a/Autoload.php
+++ b/Autoload.php
@@ -16,6 +16,7 @@
        'ApiContentTranslationDelete' => 
"$dir/api/ApiContentTranslationDelete.php",
        'ApiQueryContentTranslation' => 
"$dir/api/ApiQueryContentTranslation.php",
        'ApiQueryContentTranslationStats' => 
"$dir/api/ApiQueryContentTranslationStats.php",
+       'ApiQueryPublishedTranslations' => 
"$dir/api/ApiQueryPublishedTranslations.php",
        'ContentTranslationHooks' => "$dir/ContentTranslation.hooks.php",
        'ContentTranslation\Database' => "$dir/includes/Database.php",
        'ContentTranslation\Draft' => "$dir/includes/Draft.php",
diff --git a/ContentTranslation.php b/ContentTranslation.php
index 895d3df..65c914e 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -59,7 +59,7 @@
 $GLOBALS['wgAPIModules']['cxdelete'] = 'ApiContentTranslationDelete';
 $GLOBALS['wgAPIListModules']['contenttranslation'] = 
'ApiQueryContentTranslation';
 $GLOBALS['wgAPIListModules']['contenttranslationstats'] = 
'ApiQueryContentTranslationStats';
-
+$GLOBALS['wgAPIListModules']['cxpublishedtranslations']= 
'ApiQueryPublishedTranslations';
 // Hooks
 $GLOBALS['wgHooks']['BeforePageDisplay'][] = 
'ContentTranslationHooks::addModules';
 $GLOBALS['wgHooks']['GetBetaFeaturePreferences'][] = 
'ContentTranslationHooks::getPreferences';
diff --git a/api/ApiQueryPublishedTranslations.php 
b/api/ApiQueryPublishedTranslations.php
new file mode 100644
index 0000000..5b8cacf
--- /dev/null
+++ b/api/ApiQueryPublishedTranslations.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Api module for querying published translations.
+ *
+ * @file
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+/**
+ *
+ * @ingroup API ContentTranslationAPI
+ */
+class ApiQueryPublishedTranslations extends ApiQueryBase {
+
+    public function __construct( $query, $moduleName ) {
+        parent::__construct( $query, $moduleName );
+    }
+
+    public function execute() {
+        $params = $this->extractRequestParams();
+        $result = $this->getResult();
+        $user = $this->getUser();
+        $from = $params['from'];
+        $to = $params['to'];
+        $limit = $params['limit'];
+        $offset = $params['offset'];
+        $translations = 
ContentTranslation\Translation::getAllPublishedTranslations( $from, $to, 
$limit, $offset );
+        $resultSize = count( $translations );
+        $result->addValue( array( 'result' ), 'translations', $translations );
+    }
+
+    public function getAllowedParams() {
+        $allowedParams = array(
+            'from' => array(
+                ApiBase::PARAM_TYPE => 'string',
+            ),
+            'to' => array(
+                ApiBase::PARAM_TYPE => 'string',
+            ),
+            'limit' => array(
+                ApiBase::PARAM_DFLT => 500,
+                ApiBase::PARAM_TYPE => 'limit',
+                ApiBase::PARAM_MIN => 1,
+                ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+            ),
+            'offset' => array(
+                ApiBase::PARAM_DFLT => '',
+                ApiBase::PARAM_TYPE => 'string',
+                ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+            ),
+        );
+        return $allowedParams;
+    }
+
+    protected function getExamplesMessages() {
+        return array(
+            'action=query&list=cxpublishedtranslations' =>
+                'apihelp-query+cxpublishedtranslations-example-1',
+            'action=query&list=cxpublishedtranslations&from=en' =>
+                'apihelp-query+contenttranslation-example-2',
+            'action=query&list=cxpublishedtranslations&from=en&to=es' =>
+                'apihelp-query+contenttranslation-example-3',
+        );
+    }
+}
diff --git a/i18n/en.json b/i18n/en.json
index 5e48137..b8061a4 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -119,6 +119,12 @@
        "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",
+       "apihelp-query+cxpublishedtranslations-description": "Fetch all 
published translations information",
+       "apihelp-query+cxpublishedtranslations-param-from": "The source 
language code.",
+       "apihelp-query+cxpublishedtranslations-param-to": "The target language 
code.",
+       "apihelp-query+cxpublishedtranslations-example-1": "Fetch all published 
translations",
+       "apihelp-query+cxpublishedtranslations-example-2": "Fetch all published 
translations, translated from English",
+       "apihelp-query+cxpublishedtranslations-example-3": "Fetch all published 
translations, translated from English to Spanish",
        "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 7f3b87b..ab140c5 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -124,6 +124,12 @@
        "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}}",
+       "apihelp-query+cxpublishedtranslations-description": 
"{{doc-apihelp-description|query+cxpublishedtranslations}}",
+       "apihelp-query+cxpublishedtranslations-param-from": 
"{{doc-apihelp-param|query+cxpublishedtranslations|from}}",
+       "apihelp-query+cxpublishedtranslations-param-to": 
"{{doc-apihelp-param|query+cxpublishedtranslations|to}}",
+       "apihelp-query+cxpublishedtranslations-example-1": 
"{{doc-apihelp-example|query+contenttranslation}}",
+       "apihelp-query+cxpublishedtranslations-example-2": 
"{{doc-apihelp-example|query+contenttranslation}}",
+       "apihelp-query+cxpublishedtranslations-example-3": 
"{{doc-apihelp-example|query+contenttranslation}}",
        "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/includes/Translation.php b/includes/Translation.php
index 1552d33..5b6b158 100644
--- a/includes/Translation.php
+++ b/includes/Translation.php
@@ -123,6 +123,51 @@
                return $result;
        }
 
+       public static function getAllPublishedTranslations( $from, $to,  
$limit, $offset ) {
+               $dbr = Database::getConnection( DB_SLAVE );
+               $conditions= array( 'translation_status' => 'published' );
+               if ( $from ) {
+                       $conditions['translation_source_language'] = $from;
+               }
+               if ( $to ) {
+                       $conditions['translation_target_language'] = $to;
+               }
+               $options = array ( 'LIMIT' => $limit );
+               if ( $offset ) {
+                       $options['OFFSET'] = $offset;
+               }
+               $rows = $dbr->select(
+                       'cx_translations',
+                       array(
+                               'translation_source_title',
+                               'translation_target_title',
+                               'translation_source_language',
+                               'translation_target_language',
+                               'translation_source_url',
+                               'translation_target_url',
+                               'translation_status',
+                               'translation_progress',
+                       ),
+                       $conditions,
+                       '',
+                       $options,
+                       __METHOD__
+               );
+               $result = array();
+               foreach ( $rows as $row ) {
+                       $result[] =     array(
+                               'sourceTitle' => $row->translation_source_title,
+                               'targetTitle' => $row->translation_target_title,
+                               'sourceLanguage' => 
$row->translation_source_language,
+                               'targetLanguage' => 
$row->translation_target_language,
+                               'sourceURL' => $row->translation_source_url,
+                               'targetURL' => $row->translation_target_url,
+                               'stats' => 
json_decode($row->translation_progress),
+                       );
+               }
+               return $result;
+       }
+
        /**
         * @return Translation
         */

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

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