Santhosh has uploaded a new change for review.

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


Change subject: [WIP]Fetch user translations support for Translation Stash API
......................................................................

[WIP]Fetch user translations support for Translation Stash API

Change-Id: I8ce1266a17d8b84c142960b7b1685dc6f454336c
---
M api/ApiTranslationStash.php
M resources/js/ext.translate.special.translationstash.js
M stash/TranslationStashStorage.php
3 files changed, 36 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/20/88720/1

diff --git a/api/ApiTranslationStash.php b/api/ApiTranslationStash.php
index b5c73a9..28a2c2f 100644
--- a/api/ApiTranslationStash.php
+++ b/api/ApiTranslationStash.php
@@ -18,6 +18,12 @@
                $action = $params['subaction'];
 
                if ( $action === 'add' ) {
+                       if ( !isset( $params['title'] ) ) {
+                               $this->dieUsageMsg( array( 'missingparam', 
'title' ) );
+                       }
+                       if ( !isset( $params['value'] ) ) {
+                               $this->dieUsageMsg( array( 'missingparam', 
'value' ) );
+                       }
                        // Ugly, but API modules don't have proper dependency 
injection
                        $stash = new TranslationStashStorage( wfGetDB( 
DB_MASTER ) );
 
@@ -27,9 +33,22 @@
                                $params['value'],
                                FormatJson::decode( $params['metadata'], true )
                        );
-                       $stash->addTranslation( $translation );
+                       $stash->addTranslation( serialize( $translation ) );
                }
 
+               if ( $action === 'query' ) {
+                       $stash = new TranslationStashStorage( wfGetDB( 
DB_MASTER ) );
+                       $translations = $stash->getTranslations( 
$this->getUser() );
+                       for ( $i = 0; $i < count( $translations ); $i++ ) {
+                               $translation = array(
+                                       'title' => 
$translations[$i]->getTitle()->getPrefixedDBKey(),
+                                       'value' => 
$translations[$i]->getValue(),
+                                       'metadata' =>  
$translations[$i]->getMetadata(),
+                               );
+                               $output['translations'][] = $translation;
+                       }
+
+               }
                // If we got this far, nothing has failed
                $output['result'] = 'ok';
                $this->getResult()->addValue( null, $this->getModuleName(), 
$output );
@@ -56,16 +75,16 @@
        public function getAllowedParams() {
                return array(
                        'subaction' => array(
-                               ApiBase::PARAM_TYPE => array( 'add' ),
+                               ApiBase::PARAM_TYPE => array( 'add', 'query' ),
                                ApiBase::PARAM_REQUIRED => true,
                        ),
                        'title' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true,
+                               ApiBase::PARAM_REQUIRED => false,
                        ),
                        'value' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true,
+                               ApiBase::PARAM_REQUIRED => false,
                        ),
                        'metadata' => array(
                                ApiBase::PARAM_TYPE => 'string',
diff --git a/resources/js/ext.translate.special.translationstash.js 
b/resources/js/ext.translate.special.translationstash.js
index a597053..faf01d1 100644
--- a/resources/js/ext.translate.special.translationstash.js
+++ b/resources/js/ext.translate.special.translationstash.js
@@ -8,10 +8,20 @@
 ( function ( $, mw ) {
        'use strict';
 
-       function getMessages( messageGroup, language, offset, limit ) {
+       function getUserTranslations() {
                var api = new mw.Api();
 
                return api.get( {
+                       action: 'translationstash',
+                       subaction: 'query',
+                       token: $( '#token' ).val()
+               } );
+       }
+
+       function getMessages( messageGroup, language, offset, limit ) {
+               var api = new mw.Api();
+
+               return api.post( {
                        action: 'query',
                        list: 'messagecollection',
                        mcgroup: messageGroup,
@@ -21,8 +31,6 @@
                        mclimit: limit,
                        mcprop: 'definition|properties'
                } );
-
-               // @todo: We need to get translations from the stash api
        }
 
        function addMessage( message ) {
@@ -139,5 +147,6 @@
                        }
                } );
                loadMessages();
+               getUserTranslations();
        } );
 }( jQuery, mediaWiki ) );
diff --git a/stash/TranslationStashStorage.php 
b/stash/TranslationStashStorage.php
index 8f5865b..7ff254a 100644
--- a/stash/TranslationStashStorage.php
+++ b/stash/TranslationStashStorage.php
@@ -54,6 +54,7 @@
 
                $objects = array();
                foreach ( $res as $row ) {
+
                        $objects[] = new StashedTranslation(
                                $user,
                                Title::makeTitle( $row->ts_namespace, 
$row->ts_title ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8ce1266a17d8b84c142960b7b1685dc6f454336c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to