jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/404468 )

Change subject: Fix "Adding translation overrides exisiting ones"
......................................................................


Fix "Adding translation overrides exisiting ones"

* Added API to fetch existing translations
* If not set by client-side config (that's the case when the dialog gets opened
on a page that has no translations yet) the API get's queried to see if there
are other translations available for the given source page

ERM7001

NEEDS CHERRY-PICK TO master!

Change-Id: Ia13881dbba5ff1c0de5020b4b663346b2875895a
---
M resources/ext.mlm.js
M src/Api/Tasks.php
2 files changed, 80 insertions(+), 2 deletions(-)

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



diff --git a/resources/ext.mlm.js b/resources/ext.mlm.js
index ef59c91..a4268bd 100644
--- a/resources/ext.mlm.js
+++ b/resources/ext.mlm.js
@@ -53,7 +53,8 @@
                mw.mlm.dialog.static.actions = [{
                        action: 'save',
                        label: mw.message( 'mlm-input-label-save' ).plain(),
-                       flags: [ 'primary', 'constructive' ]
+                       flags: [ 'primary', 'constructive' ],
+                       disabled: true
                }, {
                        action: 'cancel',
                        label: mw.message( 'mlm-input-label-cancel' ).plain(),
@@ -108,6 +109,7 @@
                                label: mw.message( 
'mlm-input-label-sourcetitle' ).plain(),
                                disabled: mw.mlm.srcTitle === '' ? false : true
                        });
+                       this.srcText.on( 'change', this.onSrcTextChange.bind( 
this ) );
 
                        this.srcSection = new OO.ui.HorizontalLayout( {
                                items: [
@@ -260,10 +262,44 @@
                        );
                };
 
+               mw.mlm.dialog.prototype.onSrcTextChange = function( value ){
+                       var me = this;
+
+                       var api = new mw.Api();
+                       api.postWithToken( 'csrf', {
+                               action: 'mlm-tasks',
+                               task: 'get',
+                               format: 'json',
+                               taskData: JSON.stringify( {
+                                       srcText: value
+                               } )
+                       })
+                       .done( function( response, jqXHR ) {
+                               if( !response.success ) {
+                                       return;
+                               }
+
+                               for( var i = 0; i < response.payload.length; 
i++ ) {
+                                       var translation = response.payload[i];
+                                       me.updateTranslations( {
+                                               'lang': translation.lang,
+                                               'text': translation.text
+                                       });
+                               }
+
+                               me.getActions().setAbilities( {
+                                       save: true
+                               });
+                       });
+               };
+
                mw.mlm.dialog.prototype.onTranslationAdd = function(){
                        this.updateTranslations( {
                                'lang': this.translationLang.value,
                                'text': this.translationText.value
+                       });
+                       this.getActions().setAbilities( {
+                               save: true
                        });
                };
 
@@ -272,6 +308,9 @@
                                'lang': lang,
                                'text': ''
                        }, true);
+                       this.getActions().setAbilities( {
+                               save: true
+                       });
                };
 
                mw.mlm.dialog.prototype.updateTranslations = function ( 
translation, removeOnly ) {
diff --git a/src/Api/Tasks.php b/src/Api/Tasks.php
index 767b923..7ba8666 100644
--- a/src/Api/Tasks.php
+++ b/src/Api/Tasks.php
@@ -22,6 +22,10 @@
                                'read',
                                Helper::getConfig()->get( Config::PERMISSION )
                        ],
+                       'get' => [
+                               'read',
+                               Helper::getConfig()->get( Config::PERMISSION )
+                       ],
                ];
        }
 
@@ -148,6 +152,37 @@
                return $result;
        }
 
+       protected function task_get( $taskData, $params ) {
+               $result = $this->makeStandardReturn();
+               $sysLang = Helper::getSystemLanguageCode();
+               $result->message = [];
+               if( empty( $taskData->srcText ) ) {
+                       $taskData->srcText = '';
+               }
+               $oSourceTitle = \Title::newFromText( $taskData->srcText );
+               $status = Helper::isValidTitle(
+                       $oSourceTitle
+               );
+               if( !$status->isOK() ) {
+                       $result->message[$sysLang] = $status->getHTML();
+                       return $result;
+               }
+
+               $mlmTranslation = MultiLanguageTranslation::newFromTitle(
+                       $oSourceTitle
+               );
+
+               $translations = $mlmTranslation->getTranslations();
+               foreach( $translations as &$translation ) {
+                       $title = \Title::newFromID( $translation->id );
+                       $translation->text = $title->getPrefixedText();
+               }
+
+               $result->success = 1;
+               $result->payload = $translations;
+               return $result;
+       }
+
        public function execute() {
                $params = $this->extractRequestParams();
 
@@ -226,7 +261,7 @@
                if( $paramName == 'taskData' ) {
                        $value = \FormatJson::decode($value);
                        if( empty($value) ) {
-                               return new stdClass();
+                               return new \stdClass();
                        }
                }
                return $value;
@@ -289,4 +324,8 @@
                        )
                ];
        }
+
+       public function needsToken() {
+               return 'csrf';
+       }
 }
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia13881dbba5ff1c0de5020b4b663346b2875895a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MultiLanguageManager
Gerrit-Branch: REL1_27
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to