jenkins-bot has submitted this change and it was merged.
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 analyzing the translation pairs
(can't say parallel corpora in strict sense) get minimal information
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 the information we wanted to expose,
but just starting work on it.
As we improve 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, 140 insertions(+), 1 deletion(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
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..14661e1
--- /dev/null
+++ b/api/ApiQueryPublishedTranslations.php
@@ -0,0 +1,80 @@
+<?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() {
+ $from = $to = null;
+ $params = $this->extractRequestParams();
+ $result = $this->getResult();
+ $user = $this->getUser();
+ if ( isset( $params['from'] ) ) {
+ $from = $params['from'];
+ }
+ if ( isset( $params['to'] ) ) {
+ $to = $params['to'];
+ }
+ $limit = $params['limit'];
+ $offset = $params['offset'];
+ if ( $from !== null && !Language::isValidBuiltInCode( $from ) )
{
+ $this->dieUsage( 'Invalid language', 'invalidlanguage'
);
+ }
+ if ( $to !== null && !Language::isValidBuiltInCode( $to ) ) {
+ $this->dieUsage( 'Invalid language', 'invalidlanguage'
);
+ }
+ $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+cxpublishedtranslations-example-2',
+
'action=query&list=cxpublishedtranslations&from=en&to=es' =>
+
'apihelp-query+cxpublishedtranslations-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..9cf1ca1 100644
--- a/includes/Translation.php
+++ b/includes/Translation.php
@@ -124,6 +124,52 @@
}
/**
+ * Get all published translation records.
+ *
+ * @param string $from Source language code
+ * @param string $to Target language code
+ * @param int $limit Number of records to fetch atmost
+ * @param in $offset Offset from which at most $limit records to fetch
+ * @return array[]
+ */
+ 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 AS sourceTitle',
+ 'translation_target_title AS targetTitle',
+ 'translation_source_language AS sourceLanguage',
+ 'translation_target_language AS targetLanguage',
+ 'translation_source_url AS sourceURL',
+ 'translation_target_url AS targetURL',
+ 'translation_progress AS stats',
+ ),
+ $conditions,
+ __METHOD__,
+ $options
+ );
+ $result = array();
+ foreach ( $rows as $row ) {
+ $translation = (array) $row;
+ $translation['stats'] = json_decode(
$translation['stats'] );
+ $result[] = $translation;
+ }
+ return $result;
+ }
+
+ /**
* @return Translation
*/
public static function newFromRow( $row ) {
--
To view, visit https://gerrit.wikimedia.org/r/191860
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0094102b7f04bd249e7f69502737f671755165c1
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[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