[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Update jquery.uls to fd41bbe
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/404234 ) Change subject: Update jquery.uls to fd41bbe .. Update jquery.uls to fd41bbe * Replace ULS trigger icon with monochromatic one * Custom no-results message support * Upgrade jquery in the example to 3.2.1 * Use .siblings to locate the suggestions, clear elements for efficiency * Removing assigned ids to elements that are not guaranteed to be unique * Use eslint and stylelint, fix all errors Bug: T182539 Change-Id: I7341064cd0de367d933048c4800f951568747d11 --- M lib/jquery.uls/css/jquery.uls.css M lib/jquery.uls/css/jquery.uls.grid.css M lib/jquery.uls/css/jquery.uls.lcd.css M lib/jquery.uls/css/jquery.uls.mobile.css M lib/jquery.uls/i18n/cop.json M lib/jquery.uls/i18n/mwl.json D lib/jquery.uls/images/icon-language.png D lib/jquery.uls/images/icon-language.svg A lib/jquery.uls/images/language-ltr.png A lib/jquery.uls/images/language-ltr.svg A lib/jquery.uls/images/language-rtl.png A lib/jquery.uls/images/language-rtl.svg M lib/jquery.uls/src/jquery.uls.core.js M lib/jquery.uls/src/jquery.uls.data.utils.js M lib/jquery.uls/src/jquery.uls.languagefilter.js M lib/jquery.uls/src/jquery.uls.lcd.js 16 files changed, 285 insertions(+), 275 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/34/404234/1 diff --git a/lib/jquery.uls/css/jquery.uls.css b/lib/jquery.uls/css/jquery.uls.css index 6af44a5..af531f2 100644 --- a/lib/jquery.uls/css/jquery.uls.css +++ b/lib/jquery.uls/css/jquery.uls.css @@ -1,8 +1,8 @@ .uls-trigger { - background: url('../images/icon-language.png') no-repeat left center; + background: url( ../images/language-ltr.png ) no-repeat left center; /* @embed */ - background-image: linear-gradient(transparent, transparent), url('../images/icon-language.svg'); - padding-left: 30px; + background-image: linear-gradient( transparent, transparent ), url( ../images/language-ltr.svg ); + padding-left: 25px; } .uls-menu { @@ -12,10 +12,10 @@ margin-top: 1px; background-color: #fff; border: 1px solid #ccc; - border-color: rgba(0, 0, 0, 0.2); - -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); - -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); - box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); + border-color: rgba( 0, 0, 0, 0.2 ); + -webkit-box-shadow: 0 5px 10px rgba( 0, 0, 0, 0.2 ); + -moz-box-shadow: 0 5px 10px rgba( 0, 0, 0, 0.2 ); + box-shadow: 0 5px 10px rgba( 0, 0, 0, 0.2 ); -webkit-background-clip: padding-box; -moz-background-clip: padding; background-clip: padding-box; @@ -65,9 +65,9 @@ } .uls-search-label { - background: url('../images/search.png') no-repeat center center; + background: url( ../images/search.png ) no-repeat center center; /* @embed */ - background-image: linear-gradient(transparent, transparent), url('../images/search.svg'); + background-image: linear-gradient( transparent, transparent ), url( ../images/search.svg ); background-size: 20px; height: 32px; width: 44px; @@ -88,7 +88,7 @@ width: 100%; /* For the custom clear (X) icon */ padding: 6px 25px 6px 0; - outline: none; + outline: 0; border: 0; display: block; position: absolute; @@ -110,9 +110,9 @@ } .uls-languagefilter-clear { - background: url('../images/clear.png') no-repeat left center; + background: url( ../images/clear.png ) no-repeat left center; /* @embed */ - background-image: linear-gradient(transparent, transparent), url('../images/clear.svg'); + background-image: linear-gradient( transparent, transparent ), url( ../images/clear.svg ); background-size: 15px; cursor: pointer; height: 15px; diff --git a/lib/jquery.uls/css/jquery.uls.grid.css b/lib/jquery.uls/css/jquery.uls.grid.css index 9caf088..f068a86 100644 --- a/lib/jquery.uls/css/jquery.uls.grid.css +++ b/lib/jquery.uls/css/jquery.uls.grid.css @@ -32,15 +32,18 @@ } .grid .highlight { - background: #99; + background: #ff9; } /* The Grid -- */ + .grid .row { width: 100%; max-width: none; min-width: 600px; margin: 0 auto; + /* Nicolas Gallagher's micro clearfix */ + *zoom: 1; } .grid .row .row { @@ -48,6 +51,14 @@ max-width: none; min-width: 0; margin: 0 -5px; +} + +.grid .column, +.grid .columns { + float: left; + min-height: 1px; + padding: 0 5px; + position: relative; } .grid .row.collapse .column, @@ -55,25 +66,12 @@ padding: 0; } -.grid .row .row { - width: auto; - max-width: none; - min-width: 0; - margin: 0 -5px; -} - .grid .row
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Prevent page scroll to top while clicking on language settin...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401891 ) Change subject: Prevent page scroll to top while clicking on language settings icon .. Prevent page scroll to top while clicking on language settings icon If the language settings window is not visible, all calculations will go wrong and page will scroll to 0 position. So call scrollIntoView only when the element is visible. The $.fn.scrollIntoView defined in jquery.uls core may be unnecessary now since it is available natively on DOM elements. Bug: T178188 Change-Id: I461fa9eb7c51cd277bebd3a04cfcc0eed9793c4e --- M resources/js/ext.uls.languagesettings.js 1 file changed, 3 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/91/401891/1 diff --git a/resources/js/ext.uls.languagesettings.js b/resources/js/ext.uls.languagesettings.js index e39f3a6..b806d19 100644 --- a/resources/js/ext.uls.languagesettings.js +++ b/resources/js/ext.uls.languagesettings.js @@ -149,7 +149,9 @@ var $this = $( this ); $this.data( 'module' ).render(); - languageSettings.$window.scrollIntoView(); + if ( languageSettings.$window.is( ':visible' ) ) { + languageSettings.$window.scrollIntoView(); + } $settingsMenuItems.find( '.menu-section' ).removeClass( 'active' ); $this.addClass( 'active' ); } ); -- To view, visit https://gerrit.wikimedia.org/r/401891 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I461fa9eb7c51cd277bebd3a04cfcc0eed9793c4e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Support references wrapped in instead of
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401371 ) Change subject: Support references wrapped in instead of .. Support references wrapped in instead of Support both span and sup so that there is nothing to worry about transition. Bug: T45094 Change-Id: I54a02c7084a68ab8b7ea1ab0eda9359ee38b222a --- M lib/translationunits/MWReference.js M test/translationunits/MWReference.test.json 2 files changed, 33 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/71/401371/1 diff --git a/lib/translationunits/MWReference.js b/lib/translationunits/MWReference.js index 337f24e..96a4d9f 100644 --- a/lib/translationunits/MWReference.js +++ b/lib/translationunits/MWReference.js @@ -60,7 +60,7 @@ return this.node; } ); -MWReference.matchTagNames = [ 'span' ]; +MWReference.matchTagNames = [ 'span', 'sup' ]; MWReference.matchRdfaTypes = [ 'dc:references', 'mw:Extension/ref' ]; module.exports = MWReference; diff --git a/test/translationunits/MWReference.test.json b/test/translationunits/MWReference.test.json index d058d7a..8e80510 100644 --- a/test/translationunits/MWReference.test.json +++ b/test/translationunits/MWReference.test.json @@ -32,6 +32,38 @@ } }, { + "desc": "Adapting a reference with plain text content, sup tag", + "from": "en", + "to": "es", + "source": { + "name": "sup", + "attributes": { + "id": "trncttm-1", + "rel": "dc:references", + "typeof": "mw:Extension/ref", + "class": "mw-ref", + "data-mw": "{\"name\":\"ref\",\"body\":{\"html\":\"Hello reference\"}}" + } + }, + "result": { + "attributes": { + "id": "trncttm-1", + "rel": "dc:references", + "typeof": "mw:Extension/ref", + "class": "mw-ref", + "data-mw": { + "name": "ref", + "body": { + "html": "[en→es]Hello reference" + } + }, + "data-cx": { + "adapted": true + } + } + } + }, + { "desc": "Not adapting a reference with no data-mw.body", "from": "en", "to": "es", -- To view, visit https://gerrit.wikimedia.org/r/401371 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I54a02c7084a68ab8b7ea1ab0eda9359ee38b222a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Update rangy lib to 1.3.0
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/399135 ) Change subject: Update rangy lib to 1.3.0 .. Update rangy lib to 1.3.0 Change-Id: I9ad4758e9f4ecde84bdb2afc2ba9bf5492141495 --- M lib/rangy/rangy-core.js 1 file changed, 3,493 insertions(+), 2,872 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/35/399135/1 -- To view, visit https://gerrit.wikimedia.org/r/399135 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9ad4758e9f4ecde84bdb2afc2ba9bf5492141495 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Logged out user can't use CX from Special:CX campaign page
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/398029 ) Change subject: Logged out user can't use CX from Special:CX campaign page .. Logged out user can't use CX from Special:CX campaign page The 'try now' link should take the user to the login page. Bug: T182752 Change-Id: I0066b69a32205b48f67297591e1d8d4bca676595 --- M specials/SpecialContentTranslation.php 1 file changed, 4 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/29/398029/1 diff --git a/specials/SpecialContentTranslation.php b/specials/SpecialContentTranslation.php index 68e9f3c..567334c 100644 --- a/specials/SpecialContentTranslation.php +++ b/specials/SpecialContentTranslation.php @@ -128,6 +128,10 @@ // Enable cx for the user in this wiki. $this->enableCXBetaFeature(); } else { + if ( $campaign ) { + // Show login page if the URL has campaign parameter + $this->requireLogin(); + } // Invalid or missing campaign param $out->showErrorPage( 'cx', -- To view, visit https://gerrit.wikimedia.org/r/398029 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0066b69a32205b48f67297591e1d8d4bca676595 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Guard against js errors for invalid/corrupted(?) templates
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/397408 ) Change subject: Guard against js errors for invalid/corrupted(?) templates .. Guard against js errors for invalid/corrupted(?) templates This just prevents a potential js error when a templates data-mw has no parts attribute, which I had assumed impossible. I tried to reproduce the issue, but failed. Bug: T182528 Change-Id: I68f42397aec336af84f568b51c71ef62e85d7957 --- M modules/tools/ext.cx.tools.template.js 1 file changed, 5 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/08/397408/1 diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index 13e4d0d..e36d248 100644 --- a/modules/tools/ext.cx.tools.template.js +++ b/modules/tools/ext.cx.tools.template.js @@ -68,6 +68,11 @@ } } + if ( !mwData.parts ) { + mw.log( '[CX] data-mw for Template#' + this.$template.attr( 'id' ) + ' has no parts.' ); + return $.Deferred().reject().promise(); + } + if ( mwData.parts.length > 1 ) { mw.log( '[CX] Skipping multipart template for now for Template#' + this.$template.attr( 'id' ) ); return $.Deferred().reject().promise(); -- To view, visit https://gerrit.wikimedia.org/r/397408 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I68f42397aec336af84f568b51c71ef62e85d7957 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Fix: When cxserver is down, Dashboard is empty page
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395720 ) Change subject: Fix: When cxserver is down, Dashboard is empty page .. Fix: When cxserver is down, Dashboard is empty page We should show error message that the cxserver is not reachable. Due to a regression from accessing language pairs from cxserver early, the error message from the hook has no effect since there no header rendered in the screen. This commit is fixing this by rendering main components before the language pairs are requested. Also making sure the message is added to RL module definition. To test, shutdown cxserver and then access CX dashboard. Change-Id: Ib60c4568117fc79c09bf864ab8466bd36015177c --- M extension.json M modules/base/ext.cx.sitemapper.js M modules/dashboard/ext.cx.dashboard.js 3 files changed, 12 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/20/395720/1 diff --git a/extension.json b/extension.json index 204c8dc..83ca79a 100644 --- a/extension.json +++ b/extension.json @@ -251,14 +251,15 @@ ], "messages": [ "cx-create-new-translation", - "cx-dashboard-sidebar-title", + "cx-create-new-translation", + "cx-dashboard-sidebar-feedback", "cx-dashboard-sidebar-information", "cx-dashboard-sidebar-stats", - "cx-dashboard-sidebar-feedback", - "cx-create-new-translation", - "cx-translation-filter-suggested-translations", + "cx-dashboard-sidebar-title", + "cx-error-server-connection", + "cx-translation-filter-draft-translations", "cx-translation-filter-published-translations", - "cx-translation-filter-draft-translations" + "cx-translation-filter-suggested-translations" ] }, "ext.cx.util": { diff --git a/modules/base/ext.cx.sitemapper.js b/modules/base/ext.cx.sitemapper.js index aa11fa7..1ca5b39 100644 --- a/modules/base/ext.cx.sitemapper.js +++ b/modules/base/ext.cx.sitemapper.js @@ -179,7 +179,6 @@ response.statusText + ' (' + response.status + '). ' + response.responseText ); - mw.hook( 'mw.cx.error' ).fire( mw.msg( 'cx-error-server-connection' ) ); self.languagePairsPromise = null; return $.Deferred().reject().promise(); } ); diff --git a/modules/dashboard/ext.cx.dashboard.js b/modules/dashboard/ext.cx.dashboard.js index 0337c19..da455b3 100644 --- a/modules/dashboard/ext.cx.dashboard.js +++ b/modules/dashboard/ext.cx.dashboard.js @@ -76,6 +76,9 @@ autonym: mw.msg( 'cx-translation-filter-uls-all-languages' ) } ); + // Render the main components + this.render(); + // Get acceptable source/target language pairs this.siteMapper.getLanguagePairs().then( function ( data ) { // We store valid source and target languages as "static" variables of LanguageFilter @@ -83,11 +86,13 @@ mw.cx.ui.LanguageFilter.targetLanguages = data.targetLanguages; self.setDefaultLanguages(); - self.render(); + self.initLists(); self.listen(); mw.hook( 'mw.cx.dashboard.ready' ).fire(); + } ).fail( function () { + mw.hook( 'mw.cx.error' ).fire( mw.msg( 'cx-error-server-connection' ) ); } ); }; -- To view, visit https://gerrit.wikimedia.org/r/395720 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib60c4568117fc79c09bf864ab8466bd36015177c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Throw error if content to translate is not provided or empty
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/394975 ) Change subject: Throw error if content to translate is not provided or empty .. Throw error if content to translate is not provided or empty This was hiding the error for the issue T173801 Bug: T173801 Change-Id: I2a75d4f04469d4c32e2b2dbdc5e5c9cbb41aace2 --- M lib/routes/v1.js 1 file changed, 4 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/75/394975/1 diff --git a/lib/routes/v1.js b/lib/routes/v1.js index 2652f4a..df4d5ef 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -181,6 +181,10 @@ // We support setting html as body or as body.html. But body.html is the recommended way. // The other way will be removed soon. sourceHtml = req.body.html || req.rawBody; + if ( !sourceHtml || sourceHtml.length === 0 ) { + res.status( 500 ).end( 'Content to translate is not given or empty' ); + return; + } return mtClient.translate( from, to, sourceHtml ).then( ( data ) => { res.json( { -- To view, visit https://gerrit.wikimedia.org/r/394975 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2a75d4f04469d4c32e2b2dbdc5e5c9cbb41aace2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Remove deprecated dieUsage methods
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/394917 ) Change subject: Remove deprecated dieUsage methods .. Remove deprecated dieUsage methods dieWithError is used unconditionally now. dieUsage is deprecated in 1.29 Change-Id: Ib57384ee76c9f8a4ef88a9e395027efbb179fb65 --- M api/ApiContentTranslationPublish.php M api/ApiContentTranslationSuggestionList.php M api/ApiQueryContentTranslation.php M api/ApiQueryContentTranslationSuggestions.php M api/ApiQueryPublishedTranslations.php M api/ApiQueryTranslatorStats.php 6 files changed, 18 insertions(+), 77 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/17/394917/1 diff --git a/api/ApiContentTranslationPublish.php b/api/ApiContentTranslationPublish.php index 2839954..cbe3cfd 100644 --- a/api/ApiContentTranslationPublish.php +++ b/api/ApiContentTranslationPublish.php @@ -110,27 +110,15 @@ } if ( !Language::isKnownLanguageTag( $params['from'] ) ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( 'apierror-cx-invalidsourcelanguage', 'invalidsourcelanguage' ); - } else { - $this->dieUsage( 'Invalid source language', 'invalidsourcelanguage' ); - } + $this->dieWithError( 'apierror-cx-invalidsourcelanguage', 'invalidsourcelanguage' ); } if ( !Language::isKnownLanguageTag( $params['to'] ) ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( 'apierror-cx-invalidtargetlanguage', 'invalidtargetlanguage' ); - } else { - $this->dieUsage( 'Invalid target language', 'invalidtargetlanguage' ); - } + $this->dieWithError( 'apierror-cx-invalidtargetlanguage', 'invalidtargetlanguage' ); } if ( trim( $params['html'] ) === '' ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( [ 'apierror-paramempty', 'html' ], 'invalidhtml' ); - } else { - $this->dieUsage( 'html cannot be empty', 'invalidhtml' ); - } + $this->dieWithError( [ 'apierror-paramempty', 'html' ], 'invalidhtml' ); } $this->publish(); @@ -144,11 +132,7 @@ $targetTitle = Title::newFromText( $params['title'] ); if ( !$targetTitle ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); - } else { - $this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] ); - } + $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); } $translator = new Translator( $user ); @@ -176,13 +160,9 @@ ApiVisualEditorEdit::tryDeflate( $params['html'] ) ); } catch ( MWException $e ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( - [ 'apierror-cx-docserverexception', wfEscapeWikiText( $e->getMessage() ) ], 'docserver' - ); - } else { - $this->dieUsage( $e->getMessage(), 'docserver' ); - } + $this->dieWithError( + [ 'apierror-cx-docserverexception', wfEscapeWikiText( $e->getMessage() ) ], 'docserver' + ); } $saveresult = $this->saveWikitext( $targetTitle, $wikitext, $params ); diff --git a/api/ApiContentTranslationSuggestionList.php b/api/ApiContentTranslationSuggestionList.php index f5732e1..b4aabe1 100644 --- a/api/ApiContentTranslationSuggestionList.php +++ b/api/ApiContentTranslationSuggestionList.php @@ -17,11 +17,7 @@ $user = $this->getUser(); if ( !$this->getUser()->isLoggedIn() ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( 'apierror-cx-mustbeloggedin-suggestions', 'notloggedin' ); - } else { - $this->dieUsage( 'You must be logged-in to manage your suggestions', 'notloggedin' ); - } +
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: ApiULSLocalization: Correct the language code validation
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/394915 ) Change subject: ApiULSLocalization: Correct the language code validation .. ApiULSLocalization: Correct the language code validation Use Language::isKnownLanguageTag instead of Language::isValidCode isValidCode will accept strings that are not language code like abcd. Also removed the check for dieWithError method Change-Id: I511dfab03208b3fd70079cb97ad70549935cc6cb --- M api/ApiULSLocalization.php 1 file changed, 2 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/15/394915/1 diff --git a/api/ApiULSLocalization.php b/api/ApiULSLocalization.php index c86b5db..6176c3b 100644 --- a/api/ApiULSLocalization.php +++ b/api/ApiULSLocalization.php @@ -29,12 +29,8 @@ $params = $this->extractRequestParams(); $language = $params['language']; - if ( !Language::isValidCode( $language ) ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( [ 'apierror-invalidlang', 'language' ], 'invalidlanguage' ); - } else { - $this->dieUsage( 'Invalid language', 'invalidlanguage' ); - } + if ( !Language::isKnownLanguageTag( $language ) ) { + $this->dieWithError( [ 'apierror-invalidlang', 'language' ], 'invalidlanguage' ); } $contents = ULSJsonMessageLoader::getMessages( $language ); // Output the file's contents raw -- To view, visit https://gerrit.wikimedia.org/r/394915 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I511dfab03208b3fd70079cb97ad70549935cc6cb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: LanguageNameSearch: Optimize levenshteinDistance
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/394275 ) Change subject: LanguageNameSearch: Optimize levenshteinDistance .. LanguageNameSearch: Optimize levenshteinDistance 1. Do string comparison for equality early in the method so that we can do early return if it passes. 2. Move the zero length check for string up for early return. This may not have any significant change in performance though. Change-Id: I86bdd612a4a31c5ebfac6bcd7687b829acc69cda --- M data/LanguageNameSearch.php 1 file changed, 5 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/75/394275/1 diff --git a/data/LanguageNameSearch.php b/data/LanguageNameSearch.php index d12fb5f..06840f1 100644 --- a/data/LanguageNameSearch.php +++ b/data/LanguageNameSearch.php @@ -105,16 +105,16 @@ * @return int */ public static function levenshteinDistance( $str1, $str2 ) { + if ( $str1 === $str2 ) { + return 0; + } $length1 = mb_strlen( $str1, 'UTF-8' ); $length2 = mb_strlen( $str2, 'UTF-8' ); - if ( $length1 < $length2 ) { - return self::levenshteinDistance( $str2, $str1 ); - } if ( $length1 === 0 ) { return $length2; } - if ( $str1 === $str2 ) { - return 0; + if ( $length1 < $length2 ) { + return self::levenshteinDistance( $str2, $str1 ); } $prevRow = range( 0, $length2 ); for ( $i = 0; $i < $length1; $i++ ) { -- To view, visit https://gerrit.wikimedia.org/r/394275 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I86bdd612a4a31c5ebfac6bcd7687b829acc69cda Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Prevent js error in template adaptation
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393556 ) Change subject: Prevent js error in template adaptation .. Prevent js error in template adaptation The root cause for not having a visible fragment for template in target langauge is unknow and issue was not able to reproducable for me. This patch just prevents further damages. Not really nice though. Bug: T176237 Change-Id: I9b23f893944e46e21f4fa531aae5894830911669 --- M modules/tools/ext.cx.tools.template.js 1 file changed, 9 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/56/393556/1 diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index 403bd87..50d77c4 100644 --- a/modules/tools/ext.cx.tools.template.js +++ b/modules/tools/ext.cx.tools.template.js @@ -962,7 +962,6 @@ var self = this; this.targetTemplate.$template.first().cxoverlay( { - fullscreen: false, showLoading: true } ); return this.targetTemplate.getUpdatedTemplate().then( function ( $newTemplate ) { @@ -978,9 +977,16 @@ * @param {string} state The new state of the template. */ TemplateTool.prototype.replaceTargetTemplate = function ( $newTemplate, state ) { - var sourceId, $new; + var sourceId, $new, $visibleFragment; - sourceId = this.sourceTemplate.getFirstVisibleFragment().prop( 'id' ); + $visibleFragment = this.sourceTemplate.getFirstVisibleFragment(); + if ( !$visibleFragment ) { + // This should not happen. But prevent js error if it happens. See T176237 + mw.error( '[CX] Error: No visible fragment for template for ' + this.sourceTemplate.title ); + // Stopping here means no template editor for this particular template. + return; + } + sourceId = $visibleFragment.prop( 'id' ); $new = $newTemplate .clone() .attr( { @@ -1147,7 +1153,6 @@ // Not a processed template. Proceed with attempt to adapt. $targetTemplate.first().cxoverlay( { - fullscreen: false, showLoading: true } ); -- To view, visit https://gerrit.wikimedia.org/r/393556 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b23f893944e46e21f4fa531aae5894830911669 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Youdao: Fix the error code reading
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393519 ) Change subject: Youdao: Fix the error code reading .. Youdao: Fix the error code reading First check if response.body.errorCode is present. If not go for response.body. This was reverse in I9738d71971753f4 Change-Id: Id8ff3ff26f92a30c1eb7baa8ea471067f415e223 --- M lib/mt/Youdao.js 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/19/393519/1 diff --git a/lib/mt/Youdao.js b/lib/mt/Youdao.js index 8f16a82..5ec5cc1 100644 --- a/lib/mt/Youdao.js +++ b/lib/mt/Youdao.js @@ -103,7 +103,7 @@ return response.body.translation[ 0 ]; } else { throw new Error( 'Translation with Youdao failed. Error: ' + - this.getErrorName( response.body || response.body.errorCode ) + + this.getErrorName( response.body.errorCode || response.body ) + ` for ${sourceLang} > ${targetLang}` ); } } ); -- To view, visit https://gerrit.wikimedia.org/r/393519 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id8ff3ff26f92a30c1eb7baa8ea471067f415e223 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add test for Youdao client
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393171 ) Change subject: Add test for Youdao client .. Add test for Youdao client We cannot test the MT output since it require a valid key. This test helps to spot any other kind of errors in client code, such as js errors. Change-Id: I9738d71971753f470933cb42a1efffa86f18e54b --- M lib/mt/Youdao.js A test/mt/Youdao.test.js 2 files changed, 25 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/71/393171/1 diff --git a/lib/mt/Youdao.js b/lib/mt/Youdao.js index 03120d4..8f16a82 100644 --- a/lib/mt/Youdao.js +++ b/lib/mt/Youdao.js @@ -98,14 +98,13 @@ transtype: 'translate' } }; - return preq.post( postData ).then( ( response ) => { if ( response.body.errorCode === 0 ) { return response.body.translation[ 0 ]; } else { throw new Error( 'Translation with Youdao failed. Error: ' + - this.getErrorName( response.body.errorCode ) + - ' ' + sourceLang + '>' + targetLang ); + this.getErrorName( response.body || response.body.errorCode ) + + ` for ${sourceLang} > ${targetLang}` ); } } ); } @@ -133,7 +132,7 @@ return errormap[ code ]; } - return 'Unknown error'; + return `Unknown error: ${code}`; } requiresAuthorization() { diff --git a/test/mt/Youdao.test.js b/test/mt/Youdao.test.js new file mode 100644 index 000..caa6eff --- /dev/null +++ b/test/mt/Youdao.test.js @@ -0,0 +1,22 @@ +'use strict'; + +const assert = require( '../utils/assert.js' ); +const server = require( '../utils/server.js' ); +const Youdao = require( '../../lib/mt' ).Youdao; + +describe( 'Youdao machine translation', function () { + it( 'Should fail because of wrong key ', () => { + const cxConfig = server.config.service; + cxConfig.conf.mt.Youdao.key = 'wrongkey'; + const youdao = new Youdao( cxConfig ); + const testSourceContent = 'This is a test'; + assert.fails( + youdao.translate( 'en', 'zh', testSourceContent ), + function ( err ) { + if ( ( err instanceof Error ) && /value/.test( err ) ) { + return true; + } + } + ); + } ); +} ); -- To view, visit https://gerrit.wikimedia.org/r/393171 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9738d71971753f470933cb42a1efffa86f18e54b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Remove the left out data-seqid usage
Santhosh has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392794 ) Change subject: Remove the left out data-seqid usage .. Remove the left out data-seqid usage In I9272a9bda265de5e(June 26) we removed the usage of data-seqid. But somehow missed to remove it from the id calculation part with hash. Removing it. Heading tags were getting ids like undefinede5e3bbf3b3d03ac50ee32298 This fixes that issue. Change-Id: I23c49dee746f5734dae3c226a72ad5ec2aa7e5ad --- M lib/lineardoc/Doc.js 1 file changed, 2 insertions(+), 6 deletions(-) Approvals: jenkins-bot: Verified Nikerabbit: Looks good to me, approved diff --git a/lib/lineardoc/Doc.js b/lib/lineardoc/Doc.js index 30d2909..29b86fa 100644 --- a/lib/lineardoc/Doc.js +++ b/lib/lineardoc/Doc.js @@ -109,14 +109,10 @@ hash.update( this.items[ i + 1 ].item.getPlainText() ); // 30 is the max length of ids we allow. We also prepend the sequence id // just to make sure the ids don't collide if the same text repeats. - tag.attributes.id = ( - tag.attributes[ 'data-seqid' ] + hash.digest( 'hex' ) - ).substr( 0, 30 ); + tag.attributes.id = hash.digest( 'hex' ).substr( 0, 30 ); } else if ( tag.attributes.id.length > 30 ) { // At any case, make sure that the section id never exceeds 30 bytes - tag.attributes.id = ( - tag.attributes[ 'data-seqid' ] + tag.attributes.id - ).substr( 0, 30 ); + tag.attributes.id = tag.attributes.id.substr( 0, 30 ); } } else { tag.attributes.id = getNextId( 'block', tag.name ); -- To view, visit https://gerrit.wikimedia.org/r/392794 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I23c49dee746f5734dae3c226a72ad5ec2aa7e5ad Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: SanthoshGerrit-Reviewer: Nikerabbit Gerrit-Reviewer: Santhosh Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Youdao: Fix js error: self not defined
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393042 ) Change subject: Youdao: Fix js error: self not defined .. Youdao: Fix js error: self not defined Regression from 58b026a9ebff3e20e4188cf9621769152194cf1a Bug: T181209 Change-Id: Id361159297977a9ede31c52a6b592ac20366ec9f --- M lib/mt/Youdao.js 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/42/393042/1 diff --git a/lib/mt/Youdao.js b/lib/mt/Youdao.js index 8f6abaf..03120d4 100644 --- a/lib/mt/Youdao.js +++ b/lib/mt/Youdao.js @@ -29,7 +29,7 @@ return Promise.resolve( item ); } - return self.translateText( + return this.translateText( sourceLang, targetLang, item.item.getPlainText() -- To view, visit https://gerrit.wikimedia.org/r/393042 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id361159297977a9ede31c52a6b592ac20366ec9f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Upgrade service-runner to 2.4.3
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393008 ) Change subject: Upgrade service-runner to 2.4.3 .. Upgrade service-runner to 2.4.3 Change-Id: I70046a426ee690c5d23ef29252915cc03fe06fa1 --- M package.json 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/08/393008/1 diff --git a/package.json b/package.json index d1c2e11..db96257 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "mediawiki-title": "^0.6.5", "preq": "^0.5.3", "sax": "1.2.1", -"service-runner": "^2.4.2", +"service-runner": "^2.4.3", "swagger-router": "^0.7.1", "swagger-ui": "git+https://github.com/wikimedia/swagger-ui#master; }, -- To view, visit https://gerrit.wikimedia.org/r/393008 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I70046a426ee690c5d23ef29252915cc03fe06fa1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Segmentation: ES6 syntax clean up
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393005 ) Change subject: Segmentation: ES6 syntax clean up .. Segmentation: ES6 syntax clean up Change-Id: Ife554b709dbfdb019802041d7631714bf0556588 --- M lib/segmentation/CXSegmenter.js M lib/segmentation/languages/SegmenterAm.js M lib/segmentation/languages/SegmenterDefault.js M lib/segmentation/languages/SegmenterHi.js M lib/segmentation/languages/SegmenterHy.js M lib/segmentation/languages/SegmenterJa.js M lib/segmentation/languages/SegmenterZh.js M lib/segmentation/languages/index.js 8 files changed, 29 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/05/393005/1 diff --git a/lib/segmentation/CXSegmenter.js b/lib/segmentation/CXSegmenter.js index 0df6630..ce6e960 100644 --- a/lib/segmentation/CXSegmenter.js +++ b/lib/segmentation/CXSegmenter.js @@ -1,6 +1,6 @@ 'use strict'; -var segmenters = require( __dirname + '/languages' ).Segmenters; +const segmenters = require( __dirname + '/languages' ).Segmenters; class CXSegmenter { diff --git a/lib/segmentation/languages/SegmenterAm.js b/lib/segmentation/languages/SegmenterAm.js index efdc0f3..5b1458f 100644 --- a/lib/segmentation/languages/SegmenterAm.js +++ b/lib/segmentation/languages/SegmenterAm.js @@ -1,6 +1,6 @@ 'use strict'; -var findAll = require( '../../lineardoc' ).Utils.findAll; +const findAll = require( '../../lineardoc' ).Utils.findAll; /** * Test a possible Ethiopic sentence boundary match @@ -11,7 +11,7 @@ */ function findBoundary( text, match ) { - var tail = text.slice( match.index + 1, text.length ); + const tail = text.slice( match.index + 1, text.length ); // Trailing non-final punctuation: not a sentence boundary if ( tail.match( /^[,;:]/ ) ) { diff --git a/lib/segmentation/languages/SegmenterDefault.js b/lib/segmentation/languages/SegmenterDefault.js index 7b80980..d1dc337 100644 --- a/lib/segmentation/languages/SegmenterDefault.js +++ b/lib/segmentation/languages/SegmenterDefault.js @@ -1,6 +1,6 @@ 'use strict'; -var findAll = require( '../../lineardoc' ).Utils.findAll; +const findAll = require( '../../lineardoc' ).Utils.findAll; /** * Test a possible English sentence boundary match @@ -10,10 +10,8 @@ * @return {number|null} The boundary offset, or null if not a sentence boundary */ function findBoundary( text, match ) { - var tail, head, lastWord; - - tail = text.slice( match.index + 1, text.length ); - head = text.slice( 0, match.index ); + const tail = text.slice( match.index + 1, text.length ); + const head = text.slice( 0, match.index ); // Trailing non-final punctuation: not a sentence boundary if ( tail.match( /^[,;:]/ ) ) { @@ -25,7 +23,7 @@ } // Do not break in abbreviations. Example D. John, St. Peter - lastWord = head.match( /(\w*)$/ )[ 0 ]; + const lastWord = head.match( /(\w*)$/ )[ 0 ]; // Exclude at most 2 letter abbreviations. Examples: T. Dr. St. Jr. Sr. Ms. Mr. // But not all caps like "UK." as in "UK. Not US", if ( lastWord.length <= 2 && lastWord.match( /^\W*[A-Z][a-z]?$/ ) && tail.match( /^\W*[A-Z]/ ) ) { @@ -49,5 +47,5 @@ } module.exports = { - getBoundaries: getBoundaries + getBoundaries }; diff --git a/lib/segmentation/languages/SegmenterHi.js b/lib/segmentation/languages/SegmenterHi.js index fb1b7bd..26a9d41 100644 --- a/lib/segmentation/languages/SegmenterHi.js +++ b/lib/segmentation/languages/SegmenterHi.js @@ -1,6 +1,6 @@ 'use strict'; -var findAll = require( '../../lineardoc' ).Utils.findAll; +const findAll = require( '../../lineardoc' ).Utils.findAll; /** * Test a possible Hindi sentence boundary match @@ -10,7 +10,7 @@ * @return {number|null} The boundary offset, or null if not a sentence boundary */ function findBoundary( text, match ) { - var tail = text.slice( match.index + 1, text.length ); + const tail = text.slice( match.index + 1, text.length ); // Include any trailing space return match.index + 1 + tail.match( /^\s*/ )[ 0 ].length; } @@ -28,5 +28,5 @@ } module.exports = { - getBoundaries: getBoundaries + getBoundaries }; diff --git a/lib/segmentation/languages/SegmenterHy.js b/lib/segmentation/languages/SegmenterHy.js index 3bd3d2c..98c6d4a 100644 --- a/lib/segmentation/languages/SegmenterHy.js +++ b/lib/segmentation/languages/SegmenterHy.js @@ -1,6 +1,6 @@ 'use strict'; -var findAll = require( '../../lineardoc' ).Utils.findAll; +const findAll = require( '../../lineardoc' ).Utils.findAll; /** * Test a possible Armenian sentence boundary match @@ -10,7 +10,7 @@ * @return {number|null} The boundary offset, or null if not a sentence boundary */ function findBoundary( text, match ) { - var tail = text.slice(
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: lineardoc: Use ES6 syntax
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393002 ) Change subject: lineardoc: Use ES6 syntax .. lineardoc: Use ES6 syntax Change-Id: I67a6e937ad37d0240d04f2ef0a9d6e291d6f1bd2 --- M lib/lineardoc/Builder.js M lib/lineardoc/Contextualizer.js M lib/lineardoc/Doc.js M lib/lineardoc/Normalizer.js M lib/lineardoc/Parser.js M lib/lineardoc/TextChunk.js M lib/lineardoc/Utils.js M lib/lineardoc/index.js 8 files changed, 562 insertions(+), 575 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/02/393002/1 diff --git a/lib/lineardoc/Builder.js b/lib/lineardoc/Builder.js index 33cacf0..454167f 100644 --- a/lib/lineardoc/Builder.js +++ b/lib/lineardoc/Builder.js @@ -1,173 +1,175 @@ 'use strict'; -var Doc = require( './Doc.js' ), - TextBlock = require( './TextBlock.js' ), - TextChunk = require( './TextChunk.js' ); +const Doc = require( './Doc' ); +const TextBlock = require( './TextBlock' ); +const TextChunk = require( './TextChunk' ); /** * A document builder * * @class - * - * @constructor - * @param {Builder} [parent] Parent document builder - * @param {Object} [wrapperTag] tag that wraps document (if there is a parent) */ -function Builder( parent, wrapperTag ) { - this.blockTags = []; - // Stack of annotation tags - this.inlineAnnotationTags = []; - // The height of the annotation tags that have been used, minus one - this.inlineAnnotationTagsUsed = 0; - this.doc = new Doc( wrapperTag || null ); - this.textChunks = []; - this.isBlockSegmentable = true; - this.parent = parent || null; -} - -Builder.prototype.createChildBuilder = function ( wrapperTag ) { - return new Builder( this, wrapperTag ); -}; - -Builder.prototype.pushBlockTag = function ( tag ) { - this.finishTextBlock(); - this.blockTags.push( tag ); - if ( this.isIgnoredTag( tag ) ) { - return; - } - this.doc.addItem( 'open', tag ); -}; - -Builder.prototype.isIgnoredTag = function ( tag ) { - return tag.name === 'section' && tag.attributes[ 'data-section-number' ]; -}; - -Builder.prototype.popBlockTag = function ( tagName ) { - var tag = this.blockTags.pop(); - if ( !tag || tag.name !== tagName ) { - throw new Error( - 'Mismatched block tags: open=' + ( tag && tag.name ) + ', close=' + tagName - ); - } - this.finishTextBlock(); - - if ( !this.isIgnoredTag( tag ) ) { - this.doc.addItem( 'close', tag ); +class Builder { + /** +* @param {Builder} [parent] Parent document builder +* @param {Object} [wrapperTag] tag that wraps document (if there is a parent) +*/ + constructor( parent, wrapperTag ) { + this.blockTags = []; + // Stack of annotation tags + this.inlineAnnotationTags = []; + // The height of the annotation tags that have been used, minus one + this.inlineAnnotationTagsUsed = 0; + this.doc = new Doc( wrapperTag || null ); + this.textChunks = []; + this.isBlockSegmentable = true; + this.parent = parent || null; } - return tag; -}; - -Builder.prototype.pushInlineAnnotationTag = function ( tag ) { - this.inlineAnnotationTags.push( tag ); -}; - -Builder.prototype.popInlineAnnotationTag = function ( tagName ) { - var tag, textChunk, chunkTag, i, replace, whitespace; - tag = this.inlineAnnotationTags.pop(); - if ( this.inlineAnnotationTagsUsed === this.inlineAnnotationTags.length ) { - this.inlineAnnotationTagsUsed--; - } - if ( !tag || tag.name !== tagName ) { - throw new Error( - 'Mismatched inline tags: open=' + ( tag && tag.name ) + ', close=' + tagName - ); + createChildBuilder( wrapperTag ) { + return new Builder( this, wrapperTag ); } - if ( !Object.keys( tag.attributes ).length ) { + pushBlockTag( tag ) { + this.finishTextBlock(); + this.blockTags.push( tag ); + if ( this.isIgnoredTag( tag ) ) { + return; + } + this.doc.addItem( 'open', tag ); + } + + isIgnoredTag( tag ) { + return tag.name === 'section' && tag.attributes[ 'data-section-number' ]; + } + + popBlockTag( tagName ) { + const tag = this.blockTags.pop(); + if ( !tag || tag.name !== tagName ) { + throw new Error( + 'Mismatched block tags: open=' + ( tag && tag.name ) + ', close=' + tagName + ); + } + this.finishTextBlock(); + +
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Remove the left out data-seqid usage
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392794 ) Change subject: Remove the left out data-seqid usage .. Remove the left out data-seqid usage In I9272a9bda265de5e(June 26) we removed the usage of data-seqid. But somehow missed to remove it from the id calculation part with hash. Removing it. Heading tags were getting ids like undefinede5e3bbf3b3d03ac50ee32298 This fixes that issue. Change-Id: I23c49dee746f5734dae3c226a72ad5ec2aa7e5ad --- M lib/lineardoc/Doc.js 1 file changed, 2 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/94/392794/1 diff --git a/lib/lineardoc/Doc.js b/lib/lineardoc/Doc.js index 30d2909..5d23021 100644 --- a/lib/lineardoc/Doc.js +++ b/lib/lineardoc/Doc.js @@ -109,14 +109,10 @@ hash.update( this.items[ i + 1 ].item.getPlainText() ); // 30 is the max length of ids we allow. We also prepend the sequence id // just to make sure the ids don't collide if the same text repeats. - tag.attributes.id = ( - tag.attributes[ 'data-seqid' ] + hash.digest( 'hex' ) - ).substr( 0, 30 ); + tag.attributes.id = hash.digest( 'hex' ).substr( 0, 30 ); } else if ( tag.attributes.id.length > 30 ) { // At any case, make sure that the section id never exceeds 30 bytes - tag.attributes.id = ( - tag.attributes[ 'data-seqid' ] + tag.attributes.id - ).substr( 0, 30 ); + tag.attributes.id = ( tag.attributes.id ).substr( 0, 30 ); } } else { tag.attributes.id = getNextId( 'block', tag.name ); -- To view, visit https://gerrit.wikimedia.org/r/392794 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I23c49dee746f5734dae3c226a72ad5ec2aa7e5ad Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Section wrapping at cxserver for v2 page fetch api
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392790 ) Change subject: Section wrapping at cxserver for v2 page fetch api .. Section wrapping at cxserver for v2 page fetch api v2 page fetch api will wrap the translatable sections with tag. Immediate childrens under will be considered as translatable sections. Bug: T177752 Change-Id: Ibb5937061c6980579d35cd24a0ba8205b109f8c7 --- M bin/segment M lib/lineardoc/Doc.js M lib/lineardoc/MwContextualizer.js M lib/lineardoc/Parser.js M lib/mw/MWPageLoader.js M lib/routes/v2.js A test/mw/SectionWrap.test.js M test/segmentation/data/result-18.html M test/segmentation/data/result-4.html M test/segmentation/data/test-18.html 10 files changed, 108 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/90/392790/1 diff --git a/bin/segment b/bin/segment index 2a18675..c23f7b0 100755 --- a/bin/segment +++ b/bin/segment @@ -11,7 +11,9 @@ } function getParsedDoc( content ) { - const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); + const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer(), { + wrapSections: true + } ); parser.init(); parser.write( content ); return parser.builder.doc; diff --git a/lib/lineardoc/Doc.js b/lib/lineardoc/Doc.js index 6c4047d..30d2909 100644 --- a/lib/lineardoc/Doc.js +++ b/lib/lineardoc/Doc.js @@ -77,10 +77,14 @@ Doc.prototype.segment = function ( getBoundaries ) { var i, len, item, tag, textBlock, hash, newDoc = new Doc(), + nextSectionId = 0, nextId = 0; // TODO: return different counters depending on type - function getNextId( type ) { + function getNextId( type, tagName ) { + if ( tagName === 'section' ) { + return String( 'cxSourceSection' + nextSectionId++ ); + } if ( type === 'segment' || type === 'link' || type === 'block' ) { return String( nextId++ ); } else { @@ -115,7 +119,7 @@ ).substr( 0, 30 ); } } else { - tag.attributes.id = getNextId( 'block' ); + tag.attributes.id = getNextId( 'block', tag.name ); } newDoc.addItem( item.type, tag ); } else if ( this.items[ i ].type !== 'textblock' ) { diff --git a/lib/lineardoc/MwContextualizer.js b/lib/lineardoc/MwContextualizer.js index c5d3742..d964443 100644 --- a/lib/lineardoc/MwContextualizer.js +++ b/lib/lineardoc/MwContextualizer.js @@ -1,7 +1,7 @@ 'use strict'; const Contextualizer = require( './Contextualizer' ); -const contentBranchNodeNames = [ 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre' ]; +const contentBranchNodeNames = [ 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre', 'div', 'table', 'ol', 'li' ]; /** * Contextualizer for MediaWiki DOM HTML @@ -31,13 +31,18 @@ return 'media'; } + // Otherwise, figure is media + if ( context === undefined && tag.name === 'body' ) { + return 'section'; + } + // And figure//figcaption is contentBranch if ( context === 'media' && tag.name === 'figcaption' ) { return 'contentBranch'; } // And ContentBranchNodes are contentBranch - if ( context === undefined && contentBranchNodeNames.indexOf( tag.name ) > -1 ) { + if ( ( context === 'section' || context === undefined ) && contentBranchNodeNames.indexOf( tag.name ) > -1 ) { return 'contentBranch'; } diff --git a/lib/lineardoc/Parser.js b/lib/lineardoc/Parser.js index d2410da..5291228 100644 --- a/lib/lineardoc/Parser.js +++ b/lib/lineardoc/Parser.js @@ -57,7 +57,7 @@ this.builder = this.rootBuilder; // Stack of tags currently open this.allTags = []; - // context for each tag currently open; undefined|'verbatim'|'media'|'contentBranch' + // context for each tag currently open; undefined|'verbatim'|'media'|'contentBranch'|'section' this.contexts = []; }; @@ -78,6 +78,14 @@ } else if ( this.isInlineAnnotationTag( tag.name ) ) { this.builder.pushInlineAnnotationTag( tag ); } else { + if ( this.options.wrapSections && this.contextualizer.getContext() === 'section' ) { + this.builder.pushBlockTag( { + name: 'section', + attributes: { +
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Build the lineardoc in Pageloader and pass to segmenter
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392614 ) Change subject: Build the lineardoc in Pageloader and pass to segmenter .. Build the lineardoc in Pageloader and pass to segmenter This will allow us to segmentation, section wrapping, category adaptation etc in pageloader without requiring to build the doc more than once. Change-Id: I49204f07a11e149e2867b35d250d46023eecbcc5 Ref: I94d5250847a6287becf411eacfc1bdd64bfe7ad3 --- M lib/mw/MWPageLoader.js M lib/segmentation/CXSegmenter.js M test/segmentation/CXSegmenter.test.js 3 files changed, 30 insertions(+), 35 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/14/392614/1 diff --git a/lib/mw/MWPageLoader.js b/lib/mw/MWPageLoader.js index 57147fd..e9c5941 100644 --- a/lib/mw/MWPageLoader.js +++ b/lib/mw/MWPageLoader.js @@ -1,18 +1,27 @@ 'use strict'; const ApiRequest = require( '../mw/ApiRequest' ), + LinearDoc = require( '../lineardoc' ), CXSegmenter = require( '../segmentation/CXSegmenter' ); class MWPageLoader extends ApiRequest { getPage( page, revision ) { return this.fetch( page, revision ).then( ( response ) => { - let segmentedDoc = this.segment( response.body ); + const parsedDoc = this.getParsedDoc( response.body ); + const segmentedDoc = new CXSegmenter().segment( parsedDoc, this.sourceLanguage ); // TODO: segmentedDoc.wrapSections(); return { content: segmentedDoc.getHtml(), revision: response.revision }; } ); + } + + getParsedDoc( content ) { + const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); + parser.init(); + parser.write( content ); + return parser.builder.doc; } /** @@ -46,13 +55,6 @@ }; } ); } - - segment( pageContent ) { - const segmenter = new CXSegmenter( pageContent, this.sourceLanguage ); - segmenter.segment(); - return segmenter.getSegmentedDoc(); - } - } module.exports = MWPageLoader; diff --git a/lib/segmentation/CXSegmenter.js b/lib/segmentation/CXSegmenter.js index a1f793c..0df6630 100644 --- a/lib/segmentation/CXSegmenter.js +++ b/lib/segmentation/CXSegmenter.js @@ -1,22 +1,17 @@ 'use strict'; -var LinearDoc = require( '../lineardoc' ), - segmenters = require( __dirname + '/languages' ).Segmenters; +var segmenters = require( __dirname + '/languages' ).Segmenters; class CXSegmenter { - constructor( content, language ) { - this.parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); - this.parser.init(); - this.getBoundaries = this.getSegmenter( language ); - this.content = content; - this.originalDoc = null; - this.segmentedDoc = null; - } - segment() { - this.parser.write( this.content ); - this.originalDoc = this.parser.builder.doc; - this.segmentedDoc = this.originalDoc.segment( this.getBoundaries ); + /** +* Segment the given parsed linear document object +* @param {Object} parsedDoc +* @param {string} language +* @return {Object} +*/ + segment( parsedDoc, language ) { + return parsedDoc.segment( this.getSegmenter( language ) ); } /** @@ -36,15 +31,6 @@ return segmenter.getBoundaries; } - - getSegmentedContent() { - return this.segmentedDoc.getHtml(); - } - - getSegmentedDoc() { - return this.segmentedDoc; - } - } module.exports = CXSegmenter; diff --git a/test/segmentation/CXSegmenter.test.js b/test/segmentation/CXSegmenter.test.js index 8cc612c..3c1dce2 100644 --- a/test/segmentation/CXSegmenter.test.js +++ b/test/segmentation/CXSegmenter.test.js @@ -13,12 +13,19 @@ return normalizer.getHtml(); } +function getParsedDoc( content ) { + const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); + parser.init(); + parser.write( content ); + return parser.builder.doc; +} + function runTest( test, lang ) { let testData = fs.readFileSync( __dirname + '/data/' + test.source, 'utf8' ); - - let segmenter = new Segmenter( testData, lang ); - segmenter.segment(); - let result = normalize( segmenter.getSegmentedContent() ); + let parsedDoc = getParsedDoc( testData ); + let segmenter = new Segmenter(); + let segmentedLinearDoc = segmenter.segment( parsedDoc, lang ); + let
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Update dependent node module versions
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392366 ) Change subject: Update dependent node module versions .. Update dependent node module versions Bug: T151397 Change-Id: Ia1e1e04e799531868353ec8b06ecc3572969b0f9 --- M package.json 1 file changed, 17 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/66/392366/1 diff --git a/package.json b/package.json index ceb29c9..b2adfb9 100644 --- a/package.json +++ b/package.json @@ -15,23 +15,23 @@ "node": ">=6.11.1" }, "dependencies": { -"bluebird": "^3.4.1", -"body-parser": "^1.15.2", -"bunyan": "^1.8.1", +"bluebird": "^3.5.1", +"body-parser": "^1.18.2", +"bunyan": "^1.8.12", "cassandra-uuid": "^0.0.2", -"compression": "^1.6.2", +"compression": "^1.7.1", "core-js": "^2.4.1", -"domino": "^1.0.25", -"express": "^4.16.0", -"html-entities": "1.2.0", -"js-yaml": "^3.6.1", +"domino": "^1.0.30", +"express": "^4.16.2", +"html-entities": "^1.2.1", +"js-yaml": "^3.10.0", "jsonwebtoken": "~5.6.0", "language-data": "git+https://github.com/wikimedia/language-data#master;, -"mediawiki-title": "^0.6.4", -"preq": "^0.5.2", +"mediawiki-title": "^0.6.5", +"preq": "^0.5.3", "sax": "1.2.1", -"service-runner": "^2.2.5", -"swagger-router": "^0.4.6", +"service-runner": "^2.4.2", +"swagger-router": "^0.7.1", "swagger-ui": "git+https://github.com/wikimedia/swagger-ui#master;, "dompurify": "^1.0.2", "jsdom": "^10.1.0" @@ -39,12 +39,13 @@ "devDependencies": { "async": "^1.4.2", "check-dependencies": "^0.12.0", -"extend": "^3.0.0", -"mocha": "^2.5.3", +"extend": "^3.0.1", +"mocha": "^4.0.1", +"eslint": "^4.11.0", "mocha-eslint": "^4.1.0", -"mocha-lcov-reporter": "^1.2.0", +"mocha-lcov-reporter": "^1.3.0", "node-inspector": "^0.12.6", -"nsp": "^2.6.1", +"nsp": "^3.1.0", "eslint-config-wikimedia": "0.5.0" }, "scripts": { -- To view, visit https://gerrit.wikimedia.org/r/392366 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia1e1e04e799531868353ec8b06ecc3572969b0f9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: For invalid or missing campaign show error about enable beta...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390980 ) Change subject: For invalid or missing campaign show error about enable beta feature .. For invalid or missing campaign show error about enable beta feature Showing group access permission here does not make sense. Bug: T180082 Change-Id: I2823c7aa72d775085dc314f26c394ff63a017b33 --- M specials/SpecialContentTranslation.php 1 file changed, 3 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/80/390980/1 diff --git a/specials/SpecialContentTranslation.php b/specials/SpecialContentTranslation.php index 380d6be..68e9f3c 100644 --- a/specials/SpecialContentTranslation.php +++ b/specials/SpecialContentTranslation.php @@ -124,17 +124,11 @@ // Direct access, isListed only affects Special:SpecialPages if ( !ContentTranslationHooks::isEnabledForUser( $user ) ) { if ( $hasToken || $isCampaign ) { - // User has a token. Enabled cx for the user in this wiki. + // User has a token or a valid campaign param. + // Enable cx for the user in this wiki. $this->enableCXBetaFeature(); } else { - if ( $campaign ) { - // Show login page if the URL has campaign parameter - $out->showPermissionsErrorPage( - [ [ 'badaccess-groups' ] ], - 'edit' - ); - return; - } + // Invalid or missing campaign param $out->showErrorPage( 'cx', 'cx-specialpage-enable-betafeature', -- To view, visit https://gerrit.wikimedia.org/r/390980 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2823c7aa72d775085dc314f26c394ff63a017b33 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove Madan font for ne
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390979 ) Change subject: Remove Madan font for ne .. Remove Madan font for ne * Unknown upstream * Not updated for years * ne has better support in operating systems * Non-default font for ne Change-Id: Ife0b81e4db3bc069752d89c53f4690ddcfad7ef3 --- D data/fontrepo/fonts/madan/font.ini D data/fontrepo/fonts/madan/madan.ttf D data/fontrepo/fonts/madan/madan.woff D data/fontrepo/fonts/madan/madan.woff2 D data/fontrepo/fonts/madan/madan_license.txt M resources/js/ext.uls.webfonts.repository.js 6 files changed, 0 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/79/390979/1 diff --git a/data/fontrepo/fonts/madan/font.ini b/data/fontrepo/fonts/madan/font.ini deleted file mode 100644 index c3f6b23..000 --- a/data/fontrepo/fonts/madan/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Madan] -languages=ne -version=2 -license=GPL-2.0 -licensefile=gpl-2.0.txt -url=http://www.mpp.org.np diff --git a/data/fontrepo/fonts/madan/madan.ttf b/data/fontrepo/fonts/madan/madan.ttf deleted file mode 100644 index f9060bd..000 --- a/data/fontrepo/fonts/madan/madan.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/madan/madan.woff b/data/fontrepo/fonts/madan/madan.woff deleted file mode 100644 index aa43ef0..000 --- a/data/fontrepo/fonts/madan/madan.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/madan/madan.woff2 b/data/fontrepo/fonts/madan/madan.woff2 deleted file mode 100644 index ffeaed7..000 --- a/data/fontrepo/fonts/madan/madan.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/madan/madan_license.txt b/data/fontrepo/fonts/madan/madan_license.txt deleted file mode 100644 index f02dccb..000 --- a/data/fontrepo/fonts/madan/madan_license.txt +++ /dev/null @@ -1,16 +0,0 @@ -Open Type rules and Nepali glyphsets developed at Madan Puraskar Pustakalaya and released under GPL. - -Contacts: -Madan Puraskar Pustakalaya -Yalamaya Kendra, Patan, NEPAL -GPO Box. 42 -www.mpp.org.np -i...@mpp.org.np - -Font Developers: -Gaurav Shrestha | gau...@mpp.org.np -Anjan Ale | an...@mpp.org.np - - -Copyright (c) 2007 by Madan Puraskar Pustakalaya. All rights reserved. - diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index a334704..e3aecd3 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -278,10 +278,6 @@ "system", "OpenDyslexic" ], - "ne": [ - "system", - "Madan" - ], "nl": [ "system", "ComicNeue", @@ -596,10 +592,6 @@ "fontstyle": "italic", "woff": "LinuxLibertine/LinLibertine_Rah.woff?c0828", "woff2": "LinuxLibertine/LinLibertine_Rah.woff2?4d59a" - }, - "Madan": { - "woff": "madan/madan.woff?cee7d", - "woff2": "madan/madan.woff2?81dd1" }, "Miriam CLM": { "woff": "MiriamCLM/MiriamCLM-Book.woff?28216", -- To view, visit https://gerrit.wikimedia.org/r/390979 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife0b81e4db3bc069752d89c53f4690ddcfad7ef3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove non-default Gubby font for Kannada and Tulu
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390974 ) Change subject: Remove non-default Gubby font for Kannada and Tulu .. Remove non-default Gubby font for Kannada and Tulu Change-Id: I78af0a3889e48625ebb38b1b212cb8b454a5639c --- D data/fontrepo/fonts/Gubbi/Gubbi.ttf D data/fontrepo/fonts/Gubbi/Gubbi.woff D data/fontrepo/fonts/Gubbi/Gubbi.woff2 D data/fontrepo/fonts/Gubbi/font.ini M resources/js/ext.uls.webfonts.repository.js 5 files changed, 0 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/74/390974/1 diff --git a/data/fontrepo/fonts/Gubbi/Gubbi.ttf b/data/fontrepo/fonts/Gubbi/Gubbi.ttf deleted file mode 100644 index 57e3470..000 --- a/data/fontrepo/fonts/Gubbi/Gubbi.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Gubbi/Gubbi.woff b/data/fontrepo/fonts/Gubbi/Gubbi.woff deleted file mode 100644 index 2b79d1c..000 --- a/data/fontrepo/fonts/Gubbi/Gubbi.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Gubbi/Gubbi.woff2 b/data/fontrepo/fonts/Gubbi/Gubbi.woff2 deleted file mode 100644 index f8c7a72..000 --- a/data/fontrepo/fonts/Gubbi/Gubbi.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Gubbi/font.ini b/data/fontrepo/fonts/Gubbi/font.ini deleted file mode 100644 index 525d843..000 --- a/data/fontrepo/fonts/Gubbi/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Gubbi] -languages=kn, tcy -version=1.3 -license=GPL-3.0+ -licensefile=gpl-3.0.txt -url=https://github.com/aravindavk/Gubbi/ diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index 0025edb..a334704 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -220,10 +220,6 @@ "Nokora Regular", "Suwannaphum" ], - "kn": [ - "system", - "Gubbi" - ], "kte": [ "Jomolhari" ], @@ -353,10 +349,6 @@ ], "tcn": [ "Jomolhari" - ], - "tcy": [ - "system", - "Gubbi" ], "thw": [ "Jomolhari" @@ -506,10 +498,6 @@ "fontstyle": "italic", "woff": "GentiumPlus/GentiumPlus-R.woff?1abc3", "woff2": "GentiumPlus/GentiumPlus-R.woff2?aa576" - }, - "Gubbi": { - "woff": "Gubbi/Gubbi.woff?ce807", - "woff2": "Gubbi/Gubbi.woff2?66d38" }, "Hanuman": { "woff": "Hanuman/Hanumanb.woff?27aeb", -- To view, visit https://gerrit.wikimedia.org/r/390974 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I78af0a3889e48625ebb38b1b212cb8b454a5639c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove ttf format from repo and thereby from fontface css
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390973 ) Change subject: Remove ttf format from repo and thereby from fontface css .. Remove ttf format from repo and thereby from fontface css TTF files are not removed, the entries for them from the repo is removed. Generated CSS will also skip ttf. TTF format is not required for any browser now a days. https://caniuse.com/#feat=woff Change-Id: I018e74f6a50e63f55adeca480c03124092fba015 --- M includes/FontRepoCompiler.php M resources/js/ext.uls.webfonts.repository.js 2 files changed, 51 insertions(+), 127 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/73/390973/1 diff --git a/includes/FontRepoCompiler.php b/includes/FontRepoCompiler.php index eab9ebe..f2a8edd 100644 --- a/includes/FontRepoCompiler.php +++ b/includes/FontRepoCompiler.php @@ -91,7 +91,7 @@ $info['fontstyle'] = $font['fontstyle']; } - foreach ( [ 'ttf', 'woff', 'woff2' ] as $format ) { + foreach ( [ 'woff', 'woff2' ] as $format ) { if ( isset( $font[$format] ) ) { $info[$format] = $this->getFontWebPath( $fontpath, $fontdir, $font[$format] ); } @@ -99,7 +99,7 @@ // If font formats are not explicitly defined, scan the directory. if ( !isset( $info['ttf'] ) ) { - foreach ( glob( "$fontpath/*.{ttf,woff,woff2}", GLOB_BRACE ) as $fontfile ) { + foreach ( glob( "$fontpath/*.{woff,woff2}", GLOB_BRACE ) as $fontfile ) { $type = substr( $fontfile, strrpos( $fontfile, '.' ) + 1 ); $info[$type] = $this->getFontWebPath( $fontpath, $fontdir, basename( $fontfile ) ); } diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index 898b042..0025edb 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -401,17 +401,14 @@ }, "fonts": { "AbyssinicaSIL": { - "ttf": "AbyssinicaSIL/AbyssinicaSIL-R.ttf?9e3d4", "woff": "AbyssinicaSIL/AbyssinicaSIL-R.woff?893c7", "woff2": "AbyssinicaSIL/AbyssinicaSIL-R.woff2?361f7" }, "Akkadian": { - "ttf": "Akkadian/Akkadian.ttf?39422", "woff": "Akkadian/Akkadian.woff?fc09d", "woff2": "Akkadian/Akkadian.woff2?1e0a3" }, "Alef": { - "ttf": "Alef/Alef-Regular.ttf?fce9c", "woff": "Alef/Alef-Regular.woff?2b430", "woff2": "Alef/Alef-Regular.woff2?a2499", "variants": { @@ -420,14 +417,12 @@ }, "Alef Bold": { "fontweight": "bold", - "ttf": "Alef/Alef-Bold.ttf?42297", - "woff": "Alef/Alef-Bold.woff?bd85f", - "woff2": "Alef/Alef-Bold.woff2?7c873" + "woff": "Alef/Alef-Regular.woff?2b430", + "woff2": "Alef/Alef-Regular.woff2?a2499" }, "Amiri": { - "ttf": "amiri/amiri-regular.ttf?d51fb", - "woff": "amiri/amiri-regular.woff?e8973", - "woff2": "amiri/amiri-regular.woff2?1f55e", + "woff": "amiri/amiri-slanted.woff?7d658", + "woff2": "amiri/amiri-slanted.woff2?a90a0", "variants": { "bold": "Amiri Bold", "bolditalic": "Amiri Bold Italic", @@ -436,35 +431,29 @@ }, "Amiri Bold": { "fontweight": "bold", - "ttf": "amiri/amiri-bold.ttf?6d012", - "woff": "amiri/amiri-bold.woff?63eb0", - "woff2": "amiri/amiri-bold.woff2?a0e74" + "woff": "amiri/amiri-slanted.woff?7d658", + "woff2": "amiri/amiri-slanted.woff2?a90a0" }, "Amiri Bold Italic": { "fontweight": "bold", "fontstyle": "italic", - "ttf": "amiri/amiri-boldslanted.ttf?76aa4", - "woff": "amiri/amiri-boldslanted.woff?44410", - "woff2": "amiri/amiri-boldslanted.woff2?b0128" + "woff": "amiri/amiri-slanted.woff?7d658", + "woff2": "amiri/amiri-slanted.woff2?a90a0" }, "Amiri
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove fonts for Odia(or) from fontrepo
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390972 ) Change subject: Remove fonts for Odia(or) from fontrepo .. Remove fonts for Odia(or) from fontrepo Remove non-default Utkal font - Its upstream is unknown now. Change-Id: Iefa9eeaf953d87d4a5c8766fa575d61f9bd96d2b --- D data/fontrepo/fonts/utkal/font.ini D data/fontrepo/fonts/utkal/utkal.ttf D data/fontrepo/fonts/utkal/utkal.woff D data/fontrepo/fonts/utkal/utkal.woff2 M resources/js/ext.uls.webfonts.repository.js 5 files changed, 0 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/72/390972/1 diff --git a/data/fontrepo/fonts/utkal/font.ini b/data/fontrepo/fonts/utkal/font.ini deleted file mode 100644 index 486df0c..000 --- a/data/fontrepo/fonts/utkal/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Utkal] -languages=or -version=0.13 -license=GPL-2.0 -licensefile=gpl-2.0.txt -url=http://oriya.sarovar.org/user_download.html diff --git a/data/fontrepo/fonts/utkal/utkal.ttf b/data/fontrepo/fonts/utkal/utkal.ttf deleted file mode 100644 index 12d64f2..000 --- a/data/fontrepo/fonts/utkal/utkal.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/utkal/utkal.woff b/data/fontrepo/fonts/utkal/utkal.woff deleted file mode 100644 index f93a753..000 --- a/data/fontrepo/fonts/utkal/utkal.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/utkal/utkal.woff2 b/data/fontrepo/fonts/utkal/utkal.woff2 deleted file mode 100644 index 2c68781..000 --- a/data/fontrepo/fonts/utkal/utkal.woff2 +++ /dev/null Binary files differ diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index c33996d..898b042 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -298,10 +298,6 @@ "ola": [ "Jomolhari" ], - "or": [ - "system", - "Utkal" - ], "otb": [ "Jomolhari" ], @@ -861,11 +857,6 @@ "ttf": "UnifrakturMaguntia/UnifrakturMaguntia.ttf?1cf8f", "woff": "UnifrakturMaguntia/UnifrakturMaguntia.woff?6ad8f", "woff2": "UnifrakturMaguntia/UnifrakturMaguntia.woff2?23272" - }, - "Utkal": { - "ttf": "utkal/utkal.ttf?0c644", - "woff": "utkal/utkal.woff?58d5e", - "woff2": "utkal/utkal.woff2?d550c" }, "lklug": { "ttf": "lklug/lklug.ttf?96b2f", -- To view, visit https://gerrit.wikimedia.org/r/390972 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iefa9eeaf953d87d4a5c8766fa575d61f9bd96d2b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove Tamil fonts from fontrepo
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390970 ) Change subject: Remove Tamil fonts from fontrepo .. Remove Tamil fonts from fontrepo * These fonts are with no upstream now and little known among Tamil users. * Tamil is very well supported in all operating systems now a days. * Also reduce the metadata size for fontrepo Change-Id: I4e7afb6476a4714f8d87bd2a048309b732883b2f --- D data/fontrepo/fonts/Thendral/ThendralUni.ttf D data/fontrepo/fonts/Thendral/ThendralUni.woff D data/fontrepo/fonts/Thendral/ThendralUni.woff2 D data/fontrepo/fonts/Thendral/font.ini D data/fontrepo/fonts/Thenee/TheneeUni.ttf D data/fontrepo/fonts/Thenee/TheneeUni.woff D data/fontrepo/fonts/Thenee/TheneeUni.woff2 D data/fontrepo/fonts/Thenee/font.ini M resources/js/ext.uls.webfonts.repository.js 9 files changed, 0 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/70/390970/1 diff --git a/data/fontrepo/fonts/Thendral/ThendralUni.ttf b/data/fontrepo/fonts/Thendral/ThendralUni.ttf deleted file mode 100644 index 17cb07e..000 --- a/data/fontrepo/fonts/Thendral/ThendralUni.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thendral/ThendralUni.woff b/data/fontrepo/fonts/Thendral/ThendralUni.woff deleted file mode 100644 index 335a672..000 --- a/data/fontrepo/fonts/Thendral/ThendralUni.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thendral/ThendralUni.woff2 b/data/fontrepo/fonts/Thendral/ThendralUni.woff2 deleted file mode 100644 index 8490a71..000 --- a/data/fontrepo/fonts/Thendral/ThendralUni.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thendral/font.ini b/data/fontrepo/fonts/Thendral/font.ini deleted file mode 100644 index 792b528..000 --- a/data/fontrepo/fonts/Thendral/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Thendral] -languages=ta -version=1.0 -license=GPL-2.0 -licensefile=gpl-2.0.txt -url=https://github.com/thamizha/tamil-fonts diff --git a/data/fontrepo/fonts/Thenee/TheneeUni.ttf b/data/fontrepo/fonts/Thenee/TheneeUni.ttf deleted file mode 100644 index 2a99444..000 --- a/data/fontrepo/fonts/Thenee/TheneeUni.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thenee/TheneeUni.woff b/data/fontrepo/fonts/Thenee/TheneeUni.woff deleted file mode 100644 index 1e7023d..000 --- a/data/fontrepo/fonts/Thenee/TheneeUni.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thenee/TheneeUni.woff2 b/data/fontrepo/fonts/Thenee/TheneeUni.woff2 deleted file mode 100644 index e50229f..000 --- a/data/fontrepo/fonts/Thenee/TheneeUni.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Thenee/font.ini b/data/fontrepo/fonts/Thenee/font.ini deleted file mode 100644 index b196f41..000 --- a/data/fontrepo/fonts/Thenee/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Thenee] -languages=ta -version=1.0 -license=GPL-2.0 -licensefile=gpl-2.0.txt -url=https://github.com/thamizha/tamil-fonts diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index 5ed0715..c33996d 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -355,11 +355,6 @@ "East Syriac Adiabene", "SertoUrhoy" ], - "ta": [ - "system", - "Thendral", - "Thenee" - ], "tcn": [ "Jomolhari" ], @@ -856,16 +851,6 @@ "ttf": "TharLon/TharLon.ttf?91312", "woff": "TharLon/TharLon.woff?0df3e", "woff2": "TharLon/TharLon.woff2?9012f" - }, - "Thendral": { - "ttf": "Thendral/ThendralUni.ttf?c4f2d", - "woff": "Thendral/ThendralUni.woff?788be", - "woff2": "Thendral/ThendralUni.woff2?0af7d" - }, - "Thenee": { - "ttf": "Thenee/TheneeUni.ttf?f89c7", - "woff": "Thenee/TheneeUni.woff?a32ac", - "woff2": "Thenee/TheneeUni.woff2?c24ef" }, "Tuladha Jejeg": { "ttf": "TuladhaJejeg/TuladhaJejeg_gr.ttf?210ce", -- To view, visit https://gerrit.wikimedia.org/r/390970 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4e7afb6476a4714f8d87bd2a048309b732883b2f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove fonts for Malayalam from font repo
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390948 ) Change subject: Remove fonts for Malayalam from font repo .. Remove fonts for Malayalam from font repo * I maintain these fonts in upstream and there we several releases since these fonts were added. * Malayalam has better support in operating systems compared to 2012 when these fonts were added. * Reduce font metadata size for wikipedia pages when webfonts are enabled. Change-Id: Ie5b54cc866b1c67849b094a9701b2c80d876b55f --- D data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.ttf D data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff D data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff2 D data/fontrepo/fonts/AnjaliOldLipi/font.ini D data/fontrepo/fonts/Meera/Meera.ttf D data/fontrepo/fonts/Meera/Meera.woff D data/fontrepo/fonts/Meera/Meera.woff2 D data/fontrepo/fonts/Meera/font.ini M resources/js/ext.uls.webfonts.repository.js 9 files changed, 0 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/48/390948/1 diff --git a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.ttf b/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.ttf deleted file mode 100644 index 6c76fa7..000 --- a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff b/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff deleted file mode 100644 index 835a05e..000 --- a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff2 b/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff2 deleted file mode 100644 index 5feffa1..000 --- a/data/fontrepo/fonts/AnjaliOldLipi/AnjaliOldLipi.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/AnjaliOldLipi/font.ini b/data/fontrepo/fonts/AnjaliOldLipi/font.ini deleted file mode 100644 index b3852fa..000 --- a/data/fontrepo/fonts/AnjaliOldLipi/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[AnjaliOldLipi] -languages=ml -version=.0.730 -license=OFL-1.1 -licensefile=OFL.txt -url=https://sites.google.com/site/cibu/anjalioldlipi-font diff --git a/data/fontrepo/fonts/Meera/Meera.ttf b/data/fontrepo/fonts/Meera/Meera.ttf deleted file mode 100644 index c54a55b..000 --- a/data/fontrepo/fonts/Meera/Meera.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Meera/Meera.woff b/data/fontrepo/fonts/Meera/Meera.woff deleted file mode 100644 index cef8b92..000 --- a/data/fontrepo/fonts/Meera/Meera.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Meera/Meera.woff2 b/data/fontrepo/fonts/Meera/Meera.woff2 deleted file mode 100644 index e638955..000 --- a/data/fontrepo/fonts/Meera/Meera.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Meera/font.ini b/data/fontrepo/fonts/Meera/font.ini deleted file mode 100644 index 1b56134..000 --- a/data/fontrepo/fonts/Meera/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Meera] -languages=ml -version=6.0 -license=GPL-3.0.0+-with-font-exception -licensefile=gpl-3.0.txt -url=https://savannah.nongnu.org/projects/smc diff --git a/resources/js/ext.uls.webfonts.repository.js b/resources/js/ext.uls.webfonts.repository.js index 97d9c96..5ed0715 100644 --- a/resources/js/ext.uls.webfonts.repository.js +++ b/resources/js/ext.uls.webfonts.repository.js @@ -260,11 +260,6 @@ "system", "OpenDyslexic" ], - "ml": [ - "system", - "AnjaliOldLipi", - "Meera" - ], "ms": [ "system", "ComicNeue", @@ -467,11 +462,6 @@ "woff": "amiri/amiri-slanted.woff?7d658", "woff2": "amiri/amiri-slanted.woff2?a90a0" }, - "AnjaliOldLipi": { - "ttf": "AnjaliOldLipi/AnjaliOldLipi.ttf?b47e8", - "woff": "AnjaliOldLipi/AnjaliOldLipi.woff?1f259", - "woff2": "AnjaliOldLipi/AnjaliOldLipi.woff2?7db63" - }, "Artaxerxes": { "ttf": "Artaxerxes/Artaxerxes.ttf?79a74", "woff": "Artaxerxes/Artaxerxes.woff?c1ed7", @@ -671,11 +661,6 @@ "ttf": "madan/madan.ttf?a9297", "woff": "madan/madan.woff?cee7d", "woff2": "madan/madan.woff2?81dd1" - }, - "Meera": { - "ttf": "Meera/Meera.ttf?8895f", - "woff": "Meera/Meera.woff?9e162", - "woff2": "Meera/Meera.woff2?b597d" },
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove Lohit family of fonts from fontrepo
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390946 ) Change subject: Remove Lohit family of fonts from fontrepo .. Remove Lohit family of fonts from fontrepo * The languages covered by these fonts are now available in all operating systems. * These fonts are not updated for years in our repo * Saves the amount of font repo data we deliver for *every wikipedia page* when webfonts is enabled Change-Id: Ia0f1b6acc4cf8b7a354671bea47b58425ab8c08e --- D data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.ttf D data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff D data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff2 D data/fontrepo/fonts/LohitAssamese/font.ini D data/fontrepo/fonts/LohitBengali/Lohit-Bengali.ttf D data/fontrepo/fonts/LohitBengali/Lohit-Bengali.woff D data/fontrepo/fonts/LohitBengali/Lohit-Bengali.woff2 D data/fontrepo/fonts/LohitBengali/font.ini D data/fontrepo/fonts/LohitDevanagari/Lohit-Devanagari.ttf D data/fontrepo/fonts/LohitDevanagari/Lohit-Devanagari.woff D data/fontrepo/fonts/LohitDevanagari/Lohit-Devanagari.woff2 D data/fontrepo/fonts/LohitDevanagari/font.ini D data/fontrepo/fonts/LohitGujarati/Lohit-Gujarati.ttf D data/fontrepo/fonts/LohitGujarati/Lohit-Gujarati.woff D data/fontrepo/fonts/LohitGujarati/Lohit-Gujarati.woff2 D data/fontrepo/fonts/LohitGujarati/font.ini D data/fontrepo/fonts/LohitKannada/Lohit-Kannada.ttf D data/fontrepo/fonts/LohitKannada/Lohit-Kannada.woff D data/fontrepo/fonts/LohitKannada/Lohit-Kannada.woff2 D data/fontrepo/fonts/LohitKannada/font.ini D data/fontrepo/fonts/LohitMarathi/Lohit-Marathi.ttf D data/fontrepo/fonts/LohitMarathi/Lohit-Marathi.woff D data/fontrepo/fonts/LohitMarathi/Lohit-Marathi.woff2 D data/fontrepo/fonts/LohitMarathi/font.ini D data/fontrepo/fonts/LohitNepali/Lohit-Nepali.ttf D data/fontrepo/fonts/LohitNepali/Lohit-Nepali.woff D data/fontrepo/fonts/LohitNepali/Lohit-Nepali.woff2 D data/fontrepo/fonts/LohitNepali/font.ini D data/fontrepo/fonts/LohitOdia/Lohit-Odia.ttf D data/fontrepo/fonts/LohitOdia/Lohit-Odia.woff D data/fontrepo/fonts/LohitOdia/Lohit-Odia.woff2 D data/fontrepo/fonts/LohitOdia/font.ini D data/fontrepo/fonts/LohitPunjabi/Lohit-Punjabi.ttf D data/fontrepo/fonts/LohitPunjabi/Lohit-Punjabi.woff D data/fontrepo/fonts/LohitPunjabi/Lohit-Punjabi.woff2 D data/fontrepo/fonts/LohitPunjabi/font.ini D data/fontrepo/fonts/LohitTamil/Lohit-Tamil.ttf D data/fontrepo/fonts/LohitTamil/Lohit-Tamil.woff D data/fontrepo/fonts/LohitTamil/Lohit-Tamil.woff2 D data/fontrepo/fonts/LohitTamil/font.ini D data/fontrepo/fonts/LohitTamilClassical/Lohit-Tamil-Classical.ttf D data/fontrepo/fonts/LohitTamilClassical/Lohit-Tamil-Classical.woff D data/fontrepo/fonts/LohitTamilClassical/Lohit-Tamil-Classical.woff2 D data/fontrepo/fonts/LohitTamilClassical/font.ini D data/fontrepo/fonts/LohitTelugu/Lohit-Telugu.ttf D data/fontrepo/fonts/LohitTelugu/Lohit-Telugu.woff D data/fontrepo/fonts/LohitTelugu/Lohit-Telugu.woff2 D data/fontrepo/fonts/LohitTelugu/font.ini M resources/js/ext.uls.webfonts.repository.js 49 files changed, 7 insertions(+), 191 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/46/390946/1 diff --git a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.ttf b/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.ttf deleted file mode 100644 index 729164e..000 --- a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff b/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff deleted file mode 100644 index 779550f..000 --- a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff2 b/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff2 deleted file mode 100644 index 310f586..000 --- a/data/fontrepo/fonts/LohitAssamese/Lohit-Assamese.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/LohitAssamese/font.ini b/data/fontrepo/fonts/LohitAssamese/font.ini deleted file mode 100644 index 3470e87..000 --- a/data/fontrepo/fonts/LohitAssamese/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Lohit Assamese] -languages=as -version=2.5.3 -license=OFL-1.1 -licensefile=OFL.txt -url=https://fedorahosted.org/lohit/ diff --git a/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.ttf b/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.ttf deleted file mode 100644 index 2f537a1..000 --- a/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.woff b/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.woff deleted file mode 100644 index 1c42940..000 --- a/data/fontrepo/fonts/LohitBengali/Lohit-Bengali.woff +++ /dev/null Binary files differ diff --git
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Remove autonym font and its usage
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390945 ) Change subject: Remove autonym font and its usage .. Remove autonym font and its usage I no longer maintains the Autonym font. Also removes the tofu detection. Bug: T135464 Bug: T135465 Change-Id: I103aab40ea5f5fc403a7ee5b23d1b634cc9c6ee1 --- M UniversalLanguageSelector.hooks.php D data/fontrepo/fonts/Autonym/Autonym.ttf D data/fontrepo/fonts/Autonym/Autonym.woff D data/fontrepo/fonts/Autonym/Autonym.woff2 D data/fontrepo/fonts/Autonym/font.ini M resources/js/ext.uls.webfonts.js M resources/js/ext.uls.webfonts.repository.js D tests/autonym.html 8 files changed, 9 insertions(+), 234 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/45/390945/1 diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 70135b4..3dc19ad 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -188,7 +188,7 @@ 'uls' => [ 'text' => Language::fetchLanguageName( $langCode ), 'href' => '#', - 'class' => 'uls-trigger autonym', + 'class' => 'uls-trigger', 'active' => true ] ] + $personal_urls; diff --git a/data/fontrepo/fonts/Autonym/Autonym.ttf b/data/fontrepo/fonts/Autonym/Autonym.ttf deleted file mode 100644 index 0565206..000 --- a/data/fontrepo/fonts/Autonym/Autonym.ttf +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Autonym/Autonym.woff b/data/fontrepo/fonts/Autonym/Autonym.woff deleted file mode 100644 index 13b55d3..000 --- a/data/fontrepo/fonts/Autonym/Autonym.woff +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Autonym/Autonym.woff2 b/data/fontrepo/fonts/Autonym/Autonym.woff2 deleted file mode 100644 index 32b38ce..000 --- a/data/fontrepo/fonts/Autonym/Autonym.woff2 +++ /dev/null Binary files differ diff --git a/data/fontrepo/fonts/Autonym/font.ini b/data/fontrepo/fonts/Autonym/font.ini deleted file mode 100644 index 14e9ee4..000 --- a/data/fontrepo/fonts/Autonym/font.ini +++ /dev/null @@ -1,6 +0,0 @@ -[Autonym] -languages=mul -version=20131205 -license=OFL-1.1 -licensefile=OFL.txt -url=https://github.com/santhoshtr/AutonymFont/ diff --git a/resources/js/ext.uls.webfonts.js b/resources/js/ext.uls.webfonts.js index 0bf41b9..b536ee8 100644 --- a/resources/js/ext.uls.webfonts.js +++ b/resources/js/ext.uls.webfonts.js @@ -20,11 +20,7 @@ ( function ( $, mw ) { 'use strict'; - var ulsPreferences, - // Text to prepend the sample text. 0D00 is an unassigned unicode point. - tofuSalt = '\u0D00', - // cache languages with tofu. - tofuLanguages = {}; + var ulsPreferences; mw.webfonts = mw.webfonts || {}; ulsPreferences = mw.uls.preferences(); @@ -67,62 +63,6 @@ } }; - /** -* Detect tofu -* -* Create a temporary span in the page with fontsize 72px and font-family -* sans-serif for each letter of the text. -* For each of these spans, calculate the width and height. If they are same -* for all spans, we can understand that each of the letter is rendered using -* same glyph - it must be a tofu. -* -* @param {string} text -* @return {boolean} -*/ - function detectTofu( text ) { - var index, - $fixture, - width = {}, - height = {}, - length = Math.min( 4, text.length ), - detected = false; - - if ( $.client.test( { - msie: false - } ) ) { - // IE shows a different tofu for unassigned code points! - text = tofuSalt + text; - } - $fixture = $( '' ) - .css( { - fontSize: '72px', - fontFamily: 'sans-serif' - } ) - .appendTo( 'body' ); - - for ( index = 0; index < length; index++ ) { - $fixture.text( text[ index ] ); - width[ index ] = $fixture.width() || width[ index - 1 ]; - height[ index ] = $fixture.height(); - - if ( index > 0 && - ( width[ index ] !== width[ index - 1 ] || - height[ index ] !== height[ index - 1 ] ) - ) { - detected = false; -
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Bring back the overlay support for a specific screen region
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/390189 ) Change subject: Bring back the overlay support for a specific screen region .. Bring back the overlay support for a specific screen region Templates and template editor was using this and got accidentally removed in I0198e67dc2bcf This commit brings back that feature with the help of an option fullscreen. The value for this option is by default true, since that is the general usecase screnario. Change-Id: Iee396e8517245ec6de2093949c8352015dadb970 Follow-up: I0198e67dc2bcf98e90293d8809aa68b18a220ffb Bug: T179997 --- M modules/tools/ext.cx.tools.template.editor.js M modules/tools/ext.cx.tools.template.js M modules/widgets/overlay/ext.cx.overlay.js M modules/widgets/overlay/ext.cx.overlay.less 4 files changed, 21 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/89/390189/1 diff --git a/modules/tools/ext.cx.tools.template.editor.js b/modules/tools/ext.cx.tools.template.editor.js index bd98932..1876958 100644 --- a/modules/tools/ext.cx.tools.template.editor.js +++ b/modules/tools/ext.cx.tools.template.editor.js @@ -154,6 +154,7 @@ } $value.cxoverlay( { + fullscreen: false, showLoading: true } ); mw.cx.wikitextToHTML( self.siteMapper, language, value.wt ).then( function ( response ) { @@ -291,6 +292,7 @@ // The html value is not available. We need to parse wikitext here. $value.cxoverlay( { + fullscreen: false, showLoading: true } ); @@ -447,6 +449,7 @@ queue = $.Deferred().resolve(); self.targetTemplate.$template.first().cxoverlay( { + fullscreen: false, showLoading: true } ); diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index 5c16214..403bd87 100644 --- a/modules/tools/ext.cx.tools.template.js +++ b/modules/tools/ext.cx.tools.template.js @@ -962,6 +962,7 @@ var self = this; this.targetTemplate.$template.first().cxoverlay( { + fullscreen: false, showLoading: true } ); return this.targetTemplate.getUpdatedTemplate().then( function ( $newTemplate ) { @@ -1146,6 +1147,7 @@ // Not a processed template. Proceed with attempt to adapt. $targetTemplate.first().cxoverlay( { + fullscreen: false, showLoading: true } ); diff --git a/modules/widgets/overlay/ext.cx.overlay.js b/modules/widgets/overlay/ext.cx.overlay.js index ee852d4..f15a1e0 100644 --- a/modules/widgets/overlay/ext.cx.overlay.js +++ b/modules/widgets/overlay/ext.cx.overlay.js @@ -14,7 +14,7 @@ */ function CXOverlay( element, options ) { this.$container = $( element || 'body' ); - this.options = options || {}; + this.options = $.extend( {}, $.fn.cxoverlay.defaults, options ); this.$overlay = null; this.init(); } @@ -31,6 +31,11 @@ if ( this.options.showLoading ) { this.$overlay.append( mw.cx.widgets.spinner() ); + } + + if ( this.options.fullscreen ) { + this.$overlay + .addClass( 'cx-overlay-fullscreen' ); } if ( this.options.closeOnClick ) { @@ -74,4 +79,9 @@ } ); }; + $.fn.cxoverlay.defaults = { + fullscreen: true, + closeOnClick: false, + showLoading: false + }; }( jQuery, mediaWiki ) ); diff --git a/modules/widgets/overlay/ext.cx.overlay.less b/modules/widgets/overlay/ext.cx.overlay.less index 34317d0..3eff7e6 100644 --- a/modules/widgets/overlay/ext.cx.overlay.less +++ b/modules/widgets/overlay/ext.cx.overlay.less @@ -2,7 +2,7 @@ .cx-overlay { background-color: #fff; - position: fixed; + position: absolute; top: 0; left: 0; z-index: 300; // 200 is the z-index of sticky header @@ -13,6 +13,10 @@ &--clickable { background-color: transparent; } + + &-fullscreen { + position: fixed; + } } body.cx-noscroll { -- To view, visit https://gerrit.wikimedia.org/r/390189 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iee396e8517245ec6de2093949c8352015dadb970 Gerrit-PatchSet: 1 Gerrit-Project:
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: ApiQueryContentTranslation: Refactor anonymous access case
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/389451 ) Change subject: ApiQueryContentTranslation: Refactor anonymous access case .. ApiQueryContentTranslation: Refactor anonymous access case Refactor the API handling for anonymous contexts Follow up: Ia7ec94c23ae and If3871eb0d5 Change-Id: I9bddd8c5497037d34172cdcbdf8e1acf6262dac8 --- M api/ApiQueryContentTranslation.php 1 file changed, 30 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/51/389451/1 diff --git a/api/ApiQueryContentTranslation.php b/api/ApiQueryContentTranslation.php index 5b91733..636f209 100644 --- a/api/ApiQueryContentTranslation.php +++ b/api/ApiQueryContentTranslation.php @@ -38,9 +38,33 @@ $params = $this->extractRequestParams(); $result = $this->getResult(); $user = $this->getUser(); - $translator = new Translator( $user ); + $translator = null; - // Case A: Find a translation for given work + if ( !$user->isAnon() ) { + $translator = new Translator( $user ); + } + + // Case A: Find a translation for given work from anonymous context + if ( $translator === null ) { + if ( $params['translationid'] ) { + $this->dieWithError( 'apierror-cx-mustbeloggedin-viewtranslations', 'notloggedin' ); + } + if ( $params['sourcetitle'] && $params['from'] && $params['to'] ) { + $translation = Translation::find( + $params['from'], $params['to'], $params[ 'sourcetitle' ] + ); + + $result->addValue( + [ 'query', 'contenttranslation' ], + 'translation', + $translation->translation + ); + } + + return; + } + + // Case B: Find a translation for given work for the current user. if ( $params['sourcetitle'] && $params['from'] && $params['to'] ) { $work = new TranslationWork( $params['sourcetitle'], $params['from'], $params['to'] ); $this->find( $work, $translator ); @@ -48,15 +72,7 @@ return; } - // Case B: Find a translation for given id - if ( $user->isAnon() ) { - if ( is_callable( [ $this, 'dieWithError' ] ) ) { - $this->dieWithError( 'apierror-cx-mustbeloggedin-viewtranslations', 'notloggedin' ); - } else { - $this->dieUsage( 'To view your translations, you must log in', 'notloggedin' ); - } - } - + // Case C: Find a translation for given id if ( $params['translationid'] ) { $translation = $translator->getTranslation( $params['translationid'] ); if ( $translation !== null ) { @@ -78,7 +94,7 @@ return; } - // Case C: Find list of translations + // Case D: Find list of translations $translations = $translator->getAllTranslations( $params['limit'], $params['offset'], @@ -118,9 +134,8 @@ public function find( TranslationWork $work, Translator $translator ) { $translation = null; $result = $this->getResult(); - if ( isset( $this->user ) ) { - $translation = Translation::findForTranslator( $work, $translator ); - } + $translation = Translation::findForTranslator( $work, $translator ); + // Check for other drafts. If one exists, return that to the UI which will then // know to display an error to the user because we disallow two users to start // drafts on the same translation work. -- To view, visit https://gerrit.wikimedia.org/r/389451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9bddd8c5497037d34172cdcbdf8e1acf6262dac8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Restore translations - enhancements
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/388429 ) Change subject: Restore translations - enhancements .. Restore translations - enhancements * Restore CX1 translation * Restore even if section order changed - section numbers not matching but parsoid generated ids matching. Bug: T176843 Change-Id: I1595eefe485398cdc4aa8b880fab5f868aaf3c58 --- M modules/dm/mw.cx.dm.Translation.js M tests/qunit/dm/mw.cx.dm.Translation.test.js 2 files changed, 114 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/29/388429/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index 09ac712..bc458f6 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -143,12 +143,42 @@ mw.cx.dm.Translation.static.getSavedSection = function ( savedTranslationUnits, sourceSectionNode, sectionNumber ) { + var savedSection, translationUnitId, parsoidId, $savedTranslationUnitSource, savedSectionParsoidId; + if ( !savedTranslationUnits ) { return; } - // TODO: Port CX1 section restoring logic to here - // See ContentTranslationLoader#restore in ext.cx.translation.loader.js - return savedTranslationUnits[ sectionNumber ]; + + savedSection = savedTranslationUnits[ sectionNumber ]; + + if ( savedSection ) { + return savedSection; + } + // CX1 translations use parsoid generated Id attribute values in + // section content instead of numerical section numbers + parsoidId = sourceSectionNode.firstChild && sourceSectionNode.firstChild.id; + savedSection = savedTranslationUnits[ parsoidId ]; + + if ( savedSection ) { + return savedSection; + } + + // Even if source section number changed, try locating matching id in content + for ( translationUnitId in savedTranslationUnits ) { + $savedTranslationUnitSource = $( savedTranslationUnits[ translationUnitId ].source.content ); + if ( $savedTranslationUnitSource.is( 'section' ) ) { + // CX2 saved translation + savedSectionParsoidId = $savedTranslationUnitSource.children().attr( 'id' ); + } else { + // CX1 saved translation + savedSectionParsoidId = $savedTranslationUnitSource.attr( 'id' ); + } + + if ( parsoidId === savedSectionParsoidId || sectionNumber === savedSectionParsoidId ) { + return savedTranslationUnits[ translationUnitId ]; + } + } + }; /** diff --git a/tests/qunit/dm/mw.cx.dm.Translation.test.js b/tests/qunit/dm/mw.cx.dm.Translation.test.js index 339ab88..fc861f6 100644 --- a/tests/qunit/dm/mw.cx.dm.Translation.test.js +++ b/tests/qunit/dm/mw.cx.dm.Translation.test.js @@ -6,7 +6,8 @@ ( function ( $, mw ) { 'use strict'; - var testDataPath = mw.config.get( 'wgExtensionAssetsPath' ) + + var restoreTestData, + testDataPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/ContentTranslation/tests/qunit/data/dm-translation-source-article.html'; QUnit.module( 'mw.cx.dm.Translation', QUnit.newMwEnvironment() ); @@ -33,4 +34,83 @@ } ); } ); + restoreTestData = { + savedTranslationUnits: { + 12: { + source: { + content: 'Content' + }, + user: { + content: 'Translated content' + } + }, + mwAz: { + source: { + content: 'Content' + }, + user: { + content: 'Translated content' + } + }, + 16: { + source: { + content: 'Content mwAp' + }, + user: { + content: 'Translated content mwAp' + } + }, + 17: { + source: { + content: 'Content mwAr' + }, + user: { + content: 'Translated content mwAr' + } + } + }, +
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: ApiQueryContentTranslation: Fix php warnings
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/388388 ) Change subject: ApiQueryContentTranslation: Fix php warnings .. ApiQueryContentTranslation: Fix php warnings Fixes the following 2 warnings observed in production: Notice: Undefined property: ApiQueryContentTranslation::$user in /srv/mediawiki/php-1.31.0-wmf.6/extensions/ContentTranslation/api/ ApiQueryContentTranslation.php on line 120 Notice: Undefined variable: translation in /srv/mediawiki/php-1.31.0-wmf.6/ extensions/ContentTranslation/api/ApiQueryContentTranslation.php on line 126 Change-Id: If3871eb0d5ff5fedbaef3f20edff7fa1ccd808db --- M api/ApiQueryContentTranslation.php 1 file changed, 2 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/88/388388/1 diff --git a/api/ApiQueryContentTranslation.php b/api/ApiQueryContentTranslation.php index ea16f03..5b91733 100644 --- a/api/ApiQueryContentTranslation.php +++ b/api/ApiQueryContentTranslation.php @@ -116,8 +116,9 @@ * @param Translator $translator */ public function find( TranslationWork $work, Translator $translator ) { + $translation = null; $result = $this->getResult(); - if ( $this->user ) { + if ( isset( $this->user ) ) { $translation = Translation::findForTranslator( $work, $translator ); } // Check for other drafts. If one exists, return that to the UI which will then -- To view, visit https://gerrit.wikimedia.org/r/388388 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If3871eb0d5ff5fedbaef3f20edff7fa1ccd808db Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cldr[master]: Update to CLDR 32
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/388019 ) Change subject: Update to CLDR 32 .. Update to CLDR 32 Change-Id: Idf3cf1a176713e0f1b4e2fd837b801b1b38e73fe --- M CldrCurrency/Symbols.php M CldrNames/CldrNamesAf.php M CldrNames/CldrNamesAm.php M CldrNames/CldrNamesAr.php M CldrNames/CldrNamesAs.php M CldrNames/CldrNamesAst.php M CldrNames/CldrNamesAz.php M CldrNames/CldrNamesBe.php M CldrNames/CldrNamesBg.php M CldrNames/CldrNamesBn.php M CldrNames/CldrNamesBs.php M CldrNames/CldrNamesCa.php M CldrNames/CldrNamesCe.php M CldrNames/CldrNamesChr.php M CldrNames/CldrNamesCkb.php M CldrNames/CldrNamesCs.php M CldrNames/CldrNamesCy.php M CldrNames/CldrNamesDa.php M CldrNames/CldrNamesDe.php M CldrNames/CldrNamesDe_ch.php M CldrNames/CldrNamesEe.php M CldrNames/CldrNamesEl.php M CldrNames/CldrNamesEn.php M CldrNames/CldrNamesEn_ca.php A CldrNames/CldrNamesEn_gb.php M CldrNames/CldrNamesEs.php M CldrNames/CldrNamesEt.php M CldrNames/CldrNamesEu.php M CldrNames/CldrNamesFa.php M CldrNames/CldrNamesFi.php M CldrNames/CldrNamesFo.php M CldrNames/CldrNamesFr.php M CldrNames/CldrNamesFy.php M CldrNames/CldrNamesGa.php M CldrNames/CldrNamesGd.php M CldrNames/CldrNamesGl.php M CldrNames/CldrNamesGu.php M CldrNames/CldrNamesHe.php M CldrNames/CldrNamesHi.php M CldrNames/CldrNamesHr.php M CldrNames/CldrNamesHu.php M CldrNames/CldrNamesHy.php M CldrNames/CldrNamesId.php M CldrNames/CldrNamesIg.php M CldrNames/CldrNamesIs.php M CldrNames/CldrNamesIt.php M CldrNames/CldrNamesJa.php M CldrNames/CldrNamesKa.php M CldrNames/CldrNamesKab.php M CldrNames/CldrNamesKk_cyrl.php M CldrNames/CldrNamesKm.php M CldrNames/CldrNamesKn.php M CldrNames/CldrNamesKo.php M CldrNames/CldrNamesKy.php M CldrNames/CldrNamesLo.php M CldrNames/CldrNamesLt.php M CldrNames/CldrNamesLv.php M CldrNames/CldrNamesMk.php M CldrNames/CldrNamesMl.php M CldrNames/CldrNamesMn.php M CldrNames/CldrNamesMr.php M CldrNames/CldrNamesMs.php M CldrNames/CldrNamesMt.php M CldrNames/CldrNamesMy.php M CldrNames/CldrNamesNb.php M CldrNames/CldrNamesNe.php M CldrNames/CldrNamesNl.php M CldrNames/CldrNamesNn.php M CldrNames/CldrNamesOr.php M CldrNames/CldrNamesPa.php M CldrNames/CldrNamesPl.php M CldrNames/CldrNamesPs.php M CldrNames/CldrNamesPt.php M CldrNames/CldrNamesPt_br.php M CldrNames/CldrNamesRm.php M CldrNames/CldrNamesRo.php M CldrNames/CldrNamesRu.php M CldrNames/CldrNamesRw.php A CldrNames/CldrNamesSd.php M CldrNames/CldrNamesSi.php M CldrNames/CldrNamesSk.php M CldrNames/CldrNamesSl.php M CldrNames/CldrNamesSq.php M CldrNames/CldrNamesSr_ec.php M CldrNames/CldrNamesSv.php M CldrNames/CldrNamesSw.php M CldrNames/CldrNamesTa.php M CldrNames/CldrNamesTe.php A CldrNames/CldrNamesTg_cyrl.php M CldrNames/CldrNamesTh.php M CldrNames/CldrNamesTi.php M CldrNames/CldrNamesTk.php M CldrNames/CldrNamesTo.php M CldrNames/CldrNamesTr.php A CldrNames/CldrNamesTt.php M CldrNames/CldrNamesUk.php M CldrNames/CldrNamesUr.php M CldrNames/CldrNamesUz.php M CldrNames/CldrNamesUz_cyrl.php M CldrNames/CldrNamesVi.php A CldrNames/CldrNamesWo.php M CldrNames/CldrNamesYo.php M CldrNames/CldrNamesYue.php M CldrNames/CldrNamesZh_hans.php M CldrNames/CldrNamesZh_hant.php M CldrNames/CldrNamesZu.php M CldrSupplemental/Supplemental.php M Makefile M extension.json 109 files changed, 13,822 insertions(+), 4,981 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/cldr refs/changes/19/388019/1 -- To view, visit https://gerrit.wikimedia.org/r/388019 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idf3cf1a176713e0f1b4e2fd837b801b1b38e73fe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/cldr Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX1: Check for template adaptation failures before publishing
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/387783 ) Change subject: CX1: Check for template adaptation failures before publishing .. CX1: Check for template adaptation failures before publishing Remove typeof=mw:Transclusion if the element is invalid - without data-mw. Parsoid can not serialize mw:Transclusion without data-mw. Ideally we should not have this kind of content. But bugs had caused this and prevented publishing translations. Remove typeof attribute so that publishing can proceed. Bug: T154116 Change-Id: Ib6d058eac4957803f563fc1333c147719ee5ad1e --- M modules/publish/ext.cx.publish.js 1 file changed, 11 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/83/387783/1 diff --git a/modules/publish/ext.cx.publish.js b/modules/publish/ext.cx.publish.js index f3eb7e1..6855f0e 100644 --- a/modules/publish/ext.cx.publish.js +++ b/modules/publish/ext.cx.publish.js @@ -355,6 +355,17 @@ return $( this ).html(); } ); + // Parsoid can not serialize mw:Transclusion without data-mw. Ideally we should not + // have this kind of content. But bugs had caused this and prevented publishing + // translations. See T154116. Remove typeof attribute so that publishing can proceed. + $section.find( '[typeof*="mw:Transclusion"]' ).replaceWith( function () { + if ( !$( this ).attr( 'data-mw' ) ) { + mw.log( '[CX] Warning: Transclusion without data-mw. Removing typeof attribute' ); + return $( this ).removeAttr( 'typeof' ); + } + return this; + } ); + // Remove empty sections if ( !$.trim( $section.text() ) && !$section.children().length ) { $section.remove(); -- To view, visit https://gerrit.wikimedia.org/r/387783 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib6d058eac4957803f563fc1333c147719ee5ad1e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Allow anonymous usage of ApiQueryContentTranslation
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/386790 ) Change subject: Allow anonymous usage of ApiQueryContentTranslation .. Allow anonymous usage of ApiQueryContentTranslation There was a regression that caused the api failure if used from an anonymous context. For example, action=query=contenttranslation=en=es=Hibiscus will fail with error: 'User account is not global' This also unbreaks my translation debugger tooling. Change-Id: Ia7ec94c23ae3a97662db5417d314905be6c3450a --- M api/ApiQueryContentTranslation.php 1 file changed, 3 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/90/386790/1 diff --git a/api/ApiQueryContentTranslation.php b/api/ApiQueryContentTranslation.php index 534fc22..ea16f03 100644 --- a/api/ApiQueryContentTranslation.php +++ b/api/ApiQueryContentTranslation.php @@ -117,8 +117,9 @@ */ public function find( TranslationWork $work, Translator $translator ) { $result = $this->getResult(); - $translation = Translation::findForTranslator( $work, $translator ); - + if ( $this->user ) { + $translation = Translation::findForTranslator( $work, $translator ); + } // Check for other drafts. If one exists, return that to the UI which will then // know to display an error to the user because we disallow two users to start // drafts on the same translation work. -- To view, visit https://gerrit.wikimedia.org/r/386790 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia7ec94c23ae3a97662db5417d314905be6c3450a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...UniversalLanguageSelector[master]: Update language name data index with CLDR 31
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/385962 ) Change subject: Update language name data index with CLDR 31 .. Update language name data index with CLDR 31 Change-Id: I7c7b26a01b5c5780cbf7a19983388e16b4e97cc1 --- M data/LanguageNameSearchData.php 1 file changed, 7,236 insertions(+), 4,567 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/62/385962/1 -- To view, visit https://gerrit.wikimedia.org/r/385962 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7c7b26a01b5c5780cbf7a19983388e16b4e97cc1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MTClient HTML Sanitizer: Whitelist tags
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/385314 ) Change subject: MTClient HTML Sanitizer: Whitelist tags .. MTClient HTML Sanitizer: Whitelist tags link tags used for MW categories will be filtered out otherwise. Change-Id: Ic7bde94e0baa79f634e878784578dc942a87832a --- M lib/mt/MTClient.js 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/14/385314/1 diff --git a/lib/mt/MTClient.js b/lib/mt/MTClient.js index 61fe613..308849f 100644 --- a/lib/mt/MTClient.js +++ b/lib/mt/MTClient.js @@ -114,7 +114,7 @@ const rdfaAttrs = [ 'about', 'rel', 'resource', 'property', 'content', 'datatype', 'typeof', 'srcset' ]; return this.DOMPurify.sanitize( html, { // These are not known attributes for DOMPurify - ADD_TAGS: [ 'figure-inline' ], + ADD_TAGS: [ 'link', 'figure-inline' ], ADD_ATTR: rdfaAttrs, ADD_URI_SAFE_ATTR: rdfaAttrs } ); -- To view, visit https://gerrit.wikimedia.org/r/385314 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic7bde94e0baa79f634e878784578dc942a87832a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: bin/adapt: Pass api to Adapter constructor
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/385313 ) Change subject: bin/adapt: Pass api to Adapter constructor .. bin/adapt: Pass api to Adapter constructor Change-Id: Ibee9d57574fb5a4eeda7195e1ad72e219d022f3b --- M bin/adapt 1 file changed, 6 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/13/385313/1 diff --git a/bin/adapt b/bin/adapt index 4232801..2ec2b2a 100755 --- a/bin/adapt +++ b/bin/adapt @@ -3,7 +3,8 @@ yaml = require( 'js-yaml' ), Adapter = require( __dirname + '/../lib/Adapter' ), TestClient = require( __dirname + '/../lib/mt' ).TestClient, - Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer; + Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer, + MWApiRequestManager = require( __dirname + '/../lib/mw/ApiRequestManager' ); let config = yaml.load( fs.readFileSync( 'config.yaml' ) ); if ( !config ) { @@ -39,9 +40,10 @@ cxConfig.conf.mtClient = new TestClient( cxConfig ); -let from = process.argv[ 2 ]; -let to = process.argv[ 3 ]; -let adapter = new Adapter( from, to, cxConfig ); +const from = process.argv[ 2 ]; +const to = process.argv[ 3 ]; +const api = new MWApiRequestManager( cxConfig ); +const adapter = new Adapter( from, to, api, cxConfig ); adapter.adapt( xhtml ).then( function ( result ) { result = normalize( result.getHtml() ); process.stdout.write( result + '\n' ); -- To view, visit https://gerrit.wikimedia.org/r/385313 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibee9d57574fb5a4eeda7195e1ad72e219d022f3b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Clarify section Id and section number difference
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384933 ) Change subject: CX2: Clarify section Id and section number difference .. CX2: Clarify section Id and section number difference Section Id is sectionIdPrefix+ Section number Also, make sure section number is incremented unconditionally. This will help restoring sections from a saved translation when a new section from source article get support at later point. Otherwise that newly supported section in source will cause all section number order go wrong. Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 --- M modules/dm/mw.cx.dm.Translation.js 1 file changed, 8 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/33/384933/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index 1856841..fca6cda 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -70,7 +70,7 @@ */ mw.cx.dm.Translation.static.getSourceDom = function ( sourceHtml, forTarget, savedTranslationUnits ) { var lastAboutGroup, - nextSectionId = 1, + sectionNumber = 0, sectionIdPrefix = forTarget ? 'cxTargetSection' : 'cxSourceSection', domDoc = ve.init.target.parseDocument( sourceHtml, 'visual' ), articleNode = domDoc.createElement( 'article' ), @@ -89,10 +89,12 @@ // Wrap each top-level element with a // TODO: it would be better to do section wrapping on the CX server Array.prototype.forEach.call( domDoc.body.childNodes, function ( node ) { - var sectionNode, aboutGroup; - if ( forTarget && savedTranslationUnits && savedTranslationUnits[ nextSectionId ] ) { - sectionNode = this.getSavedTranslation( savedTranslationUnits[ nextSectionId ] ); - nextSectionId++; + var sectionNode, aboutGroup, sectionId; + + sectionNumber++; + sectionId = sectionIdPrefix + sectionNumber; + if ( forTarget && savedTranslationUnits && savedTranslationUnits[ sectionNumber ] ) { + sectionNode = this.getSavedTranslation( savedTranslationUnits[ sectionNumber ] ); } else { if ( node.nodeType !== Node.ELEMENT_NODE ) { return; @@ -105,11 +107,9 @@ if ( ( aboutGroup && aboutGroup === lastAboutGroup ) ) { lastAboutGroup = aboutGroup; } else { - sectionNode.setAttribute( 'id', sectionIdPrefix + nextSectionId ); + sectionNode.setAttribute( 'id', sectionId ); sectionNode.setAttribute( 'rel', forTarget ? 'cx:Placeholder' : 'cx:Section' ); - nextSectionId++; } - } if ( forTarget ) { node.parentNode.removeChild( node ); -- To view, visit https://gerrit.wikimedia.org/r/384933 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b91f759d2aecf0aceae00c84a30fb9deabee1d7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Give placeholder sections for blocklevel templates
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384932 ) Change subject: CX2: Give placeholder sections for blocklevel templates .. CX2: Give placeholder sections for blocklevel templates cxserver /translate api now gives adapted template for target language. Eventhough the adapted template's editing is not there yet and we need to think how to render the block level templates in UI, this will help development and testing of template adaptations Change-Id: Iefde67adf9aac7b0162473d8f9e701533ea125b8 --- M modules/dm/mw.cx.dm.Translation.js 1 file changed, 3 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/32/384932/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index dc9e585..1856841 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -100,10 +100,9 @@ sectionNode = domDoc.createElement( 'section' ); aboutGroup = node.getAttribute( 'about' ); - // For block level templates and their about-grouped siblings, don't give them - // a section ID as they can't be translated yet - // TODO: handle more systematically - if ( ( aboutGroup && aboutGroup === lastAboutGroup ) || ( node.getAttribute( 'typeof' ) || '' ).match( /\bmw:Transclusion\b/ ) ) { + // For about-grouped siblings of block level templates don't give them + // a section ID + if ( ( aboutGroup && aboutGroup === lastAboutGroup ) ) { lastAboutGroup = aboutGroup; } else { sectionNode.setAttribute( 'id', sectionIdPrefix + nextSectionId ); -- To view, visit https://gerrit.wikimedia.org/r/384932 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iefde67adf9aac7b0162473d8f9e701533ea125b8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Refactoring for translation restore when source article...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384934 ) Change subject: CX2: Refactoring for translation restore when source article changed .. CX2: Refactoring for translation restore when source article changed Bug: T176843 Change-Id: Ic3e01559aefef57ba4622971ef777a0b3311e409 --- M modules/dm/mw.cx.dm.Translation.js 1 file changed, 27 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/34/384934/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index fca6cda..51fc140 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -89,12 +89,13 @@ // Wrap each top-level element with a // TODO: it would be better to do section wrapping on the CX server Array.prototype.forEach.call( domDoc.body.childNodes, function ( node ) { - var sectionNode, aboutGroup, sectionId; + var sectionNode, aboutGroup, sectionId, savedSection; sectionNumber++; sectionId = sectionIdPrefix + sectionNumber; - if ( forTarget && savedTranslationUnits && savedTranslationUnits[ sectionNumber ] ) { - sectionNode = this.getSavedTranslation( savedTranslationUnits[ sectionNumber ] ); + savedSection = this.getSavedSection( savedTranslationUnits, node, sectionNumber ); + if ( forTarget && savedSection ) { + sectionNode = this.getSavedTranslation( savedSection ); } else { if ( node.nodeType !== Node.ELEMENT_NODE ) { return; @@ -128,6 +129,29 @@ }; /** + * From saved translation units, find a match for the source section, if any. + * Sometimes, both will have same section numbers, but in case source article + * changed, we will need to some approximate matching to find a corresponding + * source section. At the end, we should not have any saved translations that + * we were not able to restore. + * + * @param {Object} [savedTranslationUnits] Saved translation units if any + * @param {Node} sourceSectionNode + * @param {number} sectionNumber Section number + * @return {Object} saved translationUnit + */ +mw.cx.dm.Translation.static.getSavedSection = function ( + savedTranslationUnits, sourceSectionNode, sectionNumber +) { + if ( !savedTranslationUnits ) { + return; + } + // TODO: Port CX1 section restoring logic to here + // See ContentTranslationLoader#restore in ext.cx.translation.loader.js + return savedTranslationUnits[ sectionNumber ]; +}; + +/** * Get HTML content of a translation unit to restore. * * @param {Object} translationUnit -- To view, visit https://gerrit.wikimedia.org/r/384934 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic3e01559aefef57ba4622971ef777a0b3311e409 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Parse: Disable commafy for magicvar values for month, days
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384026 ) Change subject: Parse: Disable commafy for magicvar values for month, days .. Parse: Disable commafy for magicvar values for month, days In Parser#getVariableValue For the following Magic variable identifiers Language#formatNum was called without any commafy argument. currentmonth, currentmonth1, currentday, currentday2, localmonth, localmonth1, localday, localday2 The default value for formatNum nocommafy is false, meaning formatNum will do commafication. For the above context, it is commafy process is not needed since the passed values are often month values like 02, 03 etc. Commafy is noop on this values. Explicitly pass false value for formatNum's nocommafy argument. Language#formatNum method documentation for nocommafy also recommends setting it true in case of dates. Change-Id: I3233d5458af8cef583e5d1d599d9408542ba08c9 --- M includes/parser/Parser.php 1 file changed, 8 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/26/384026/1 diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 49f2ce1..f2e47dc 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2504,10 +2504,10 @@ $value = '|'; break; case 'currentmonth': - $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'm' ) ); + $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'm' ), true ); break; case 'currentmonth1': - $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'n' ) ); + $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'n' ), true ); break; case 'currentmonthname': $value = $pageLang->getMonthName( MWTimestamp::getInstance( $ts )->format( 'n' ) ); @@ -2519,16 +2519,16 @@ $value = $pageLang->getMonthAbbreviation( MWTimestamp::getInstance( $ts )->format( 'n' ) ); break; case 'currentday': - $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'j' ) ); + $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'j' ), true ); break; case 'currentday2': - $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'd' ) ); + $value = $pageLang->formatNum( MWTimestamp::getInstance( $ts )->format( 'd' ), true ); break; case 'localmonth': - $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'm' ) ); + $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'm' ), true ); break; case 'localmonth1': - $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'n' ) ); + $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'n' ), true ); break; case 'localmonthname': $value = $pageLang->getMonthName( MWTimestamp::getLocalInstance( $ts )->format( 'n' ) ); @@ -2540,10 +2540,10 @@ $value = $pageLang->getMonthAbbreviation( MWTimestamp::getLocalInstance( $ts )->format( 'n' ) ); break; case 'localday': - $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'j' ) ); + $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'j' ), true ); break; case 'localday2': - $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'd' ) ); + $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'd' ), true ); break; case 'pagename': $value = wfEscapeWikiText( $this->mTitle->getText() ); -- To view, visit https://gerrit.wikimedia.org/r/384026 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Update formatNum implmentation to match tr35 and latest CLDR
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384006 ) Change subject: Update formatNum implmentation to match tr35 and latest CLDR .. Update formatNum implmentation to match tr35 and latest CLDR * Update digitGroupingPattern to match CLDR 31: New versions of CLDR has digit grouping pattern with decimal part. Update digitGroupingPattern values in Message classes with this improved pattern. Refer: http://unicode.org/reports/tr35/tr35-numbers.html * Refer the following chart for the decimal patterns. http://www.unicode.org/cldr/charts/31/by_type/numbers.number_formatting_patterns.html * Uses PHP NumberFormatter class for the commafy implementation. Fallbacks to Simple ###,###.### pattern if that class is not available. * Some tests need to update to match the TR 35 spec * Add support for minimumGroupingDigits in the spec. Since MediaWiki has customized values for this in many languages, introduced minimumGroupingDigits in MessageXX classes. Since this support is added, a large set of overridden commafy implementation in LanguageXX classes removed. That also resulted removing some LanguageXX classes. * The formatNum public method in Language.php is the preferred way to use this feature. It does seperator transformation and digit transformation wherever applicable. The commafy method in Language.php is just a fallback implementation when NumberFormatter class is not available. Also removed tests based on commafy methods and replaced it with tests based on formatNum Note: The corresponding js implmentaiton is not changed in this commit. Bug: T167088 Change-Id: Ic721b9a91e78e4ef07040339d1006b7a90a910c0 --- M autoload.php M includes/cache/localisation/LocalisationCache.php M languages/Language.php M languages/classes/LanguageBe_tarask.php D languages/classes/LanguageBg.php D languages/classes/LanguageEs.php D languages/classes/LanguageEt.php M languages/classes/LanguageHy.php M languages/classes/LanguageKaa.php M languages/classes/LanguageKk_cyrl.php M languages/classes/LanguageKm.php M languages/classes/LanguageKsh.php M languages/classes/LanguageKu.php D languages/classes/LanguageKu_ku.php M languages/classes/LanguageMy.php M languages/classes/LanguagePl.php D languages/classes/LanguageRu.php D languages/classes/LanguageUk.php M languages/messages/MessagesAr.php M languages/messages/MessagesAs.php M languages/messages/MessagesBe_tarask.php M languages/messages/MessagesBg.php M languages/messages/MessagesBn.php M languages/messages/MessagesEn.php M languages/messages/MessagesEs.php M languages/messages/MessagesEt.php M languages/messages/MessagesGu.php M languages/messages/MessagesHi.php M languages/messages/MessagesHy.php M languages/messages/MessagesKaa.php M languages/messages/MessagesKk_cyrl.php M languages/messages/MessagesKn.php M languages/messages/MessagesKsh.php M languages/messages/MessagesKu.php M languages/messages/MessagesKu_latn.php M languages/messages/MessagesMl.php M languages/messages/MessagesMr.php M languages/messages/MessagesOr.php M languages/messages/MessagesPa.php M languages/messages/MessagesPl.php M languages/messages/MessagesRu.php M languages/messages/MessagesSa.php M languages/messages/MessagesTa.php M languages/messages/MessagesTe.php M languages/messages/MessagesUk.php M tests/phpunit/languages/LanguageTest.php M tests/phpunit/languages/classes/LanguageArTest.php M tests/phpunit/languages/classes/LanguageArqTest.php M tests/phpunit/languages/classes/LanguageBe_taraskTest.php M tests/phpunit/languages/classes/LanguageMlTest.php M tests/phpunit/languages/classes/LanguageNlTest.php M tests/phpunit/languages/classes/LanguagePlTest.php M tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js 53 files changed, 169 insertions(+), 481 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/06/384006/1 diff --git a/autoload.php b/autoload.php index 0a2ecf0..a9ec935 100644 --- a/autoload.php +++ b/autoload.php @@ -700,15 +700,12 @@ 'LanguageAr' => __DIR__ . '/languages/classes/LanguageAr.php', 'LanguageAz' => __DIR__ . '/languages/classes/LanguageAz.php', 'LanguageBe_tarask' => __DIR__ . '/languages/classes/LanguageBe_tarask.php', - 'LanguageBg' => __DIR__ . '/languages/classes/LanguageBg.php', 'LanguageBs' => __DIR__ . '/languages/classes/LanguageBs.php', 'LanguageCode' => __DIR__ . '/languages/LanguageCode.php', 'LanguageConverter' => __DIR__ . '/languages/LanguageConverter.php', 'LanguageCu' => __DIR__ . '/languages/classes/LanguageCu.php', 'LanguageDsb' => __DIR__ . '/languages/classes/LanguageDsb.php', 'LanguageEn' => __DIR__ . '/languages/classes/LanguageEn.php', - 'LanguageEs' => __DIR__ . '/languages/classes/LanguageEs.php', - 'LanguageEt' => __DIR__ . '/languages/classes/LanguageEt.php', 'LanguageFi'
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Use cxserver v2 api
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383773 ) Change subject: CX2: Use cxserver v2 api .. CX2: Use cxserver v2 api Change-Id: I20334f08bda616732bbf192b9362ba180989a4f0 --- M modules/base/ext.cx.sitemapper.js 1 file changed, 6 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/73/383773/1 diff --git a/modules/base/ext.cx.sitemapper.js b/modules/base/ext.cx.sitemapper.js index cdd1d89..2258ad0 100644 --- a/modules/base/ext.cx.sitemapper.js +++ b/modules/base/ext.cx.sitemapper.js @@ -96,13 +96,18 @@ * @return {string} */ mw.cx.SiteMapper.prototype.getCXServerUrl = function ( module, params ) { + var cxserverURL = this.config.cx; if ( params !== undefined ) { $.each( params, function ( key, value ) { module = module.replace( key, encodeURIComponent( value ) ); } ); } - return this.config.cx + module; + if ( parseInt( mw.config.get( 'wgContentTranslationDomainCodeMapping' ), 10 ) === 2 ) { + cxserverURL.replace( 'v1', 'v2' ); + } + + return cxserverURL + module; }; mw.cx.SiteMapper.prototype.getRestbaseUrl = function ( language, module, params ) { -- To view, visit https://gerrit.wikimedia.org/r/383773 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I20334f08bda616732bbf192b9362ba180989a4f0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: SanthoshGerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: WIP: V2 apis
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383788 ) Change subject: WIP: V2 apis .. WIP: V2 apis Change-Id: I8ca37ce4884aa8d65c16b14ae682b395afb848ab --- M app.js D lib/routes/doc.js M lib/routes/v1.js A lib/routes/v2.js A lib/swagger-ui.js M spec.yaml 6 files changed, 533 insertions(+), 161 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/88/383788/1 diff --git a/app.js b/app.js index 1795d04..e18ac46 100644 --- a/app.js +++ b/app.js @@ -148,7 +148,7 @@ } // import the route file route = require( __dirname + '/lib/routes/' + fname ); - return route( app ); + return route.create ? route.create( app ) : route( app ); } ).then( function ( route ) { if ( route === undefined ) { return undefined; diff --git a/lib/routes/doc.js b/lib/routes/doc.js deleted file mode 100644 index b2be3b1..000 --- a/lib/routes/doc.js +++ /dev/null @@ -1,93 +0,0 @@ -'use strict'; - -var app, sUtil = require( '../util' ), - BBPromise = require( 'bluebird' ), - fs = BBPromise.promisifyAll( require( 'fs' ) ), - // Swagger-ui helpfully exports the absolute path of its dist directory - docRoot = require( 'swagger-ui' ).dist + '/', - router = sUtil.router(); - -function staticServe( req ) { - // Expand any relative paths for security - var filePath = req.query.path.replace( /\.\.\//g, '' ); - return fs.readFileAsync( docRoot + filePath, 'utf8' ) - .then( function ( body ) { - var contentType; - if ( filePath === '/index.html' ) { - // Rewrite the HTML to use a query string - body = body.replace( /((?:src|href)=['"])/g, '$1?doc==' ) - // Some self-promotion - .replace( //, - 'https://www.mediawiki.org/wiki/CX;>' + app.conf.spec.info.title + '' ) - .replace( /[^<]*<\/title>/, - '' + app.conf.spec.info.title + ' docs' ) - // Replace the default url with ours, switch off validation & - // limit the size of documents to apply syntax highlighting to - .replace( /Sorter: "alpha"/, 'Sorter: "alpha", validatorUrl: null, ' + - 'highlightSizeThreshold: 1, docExpansion: "list"' ) - .replace( / url: url,/, 'url: "?spec",' ); - } - - contentType = 'text/html'; - if ( /\.js$/.test( filePath ) ) { - contentType = 'text/javascript'; - } else if ( /\.png/.test( filePath ) ) { - contentType = 'image/png'; - } else if ( /\.css/.test( filePath ) ) { - contentType = 'text/css'; - body = body.replace( /\.\.\/(images|fonts)\//g, '?doc=$1/' ); - } - return BBPromise.resolve( { - status: 200, - headers: { - 'content-type': contentType, - 'content-security-policy': 'default-src \'none\'; ' + - 'script-src \'self\' \'unsafe-inline\'; connect-src \'self\'; ' + - 'style-src \'self\' \'unsafe-inline\'; img-src \'self\'; font-src \'self\';' - }, - body: body - } ); - } ); -} - -router.get( '/', function ( req, res, next ) { - var spec; - if ( req.query.spec !== undefined && app.conf.spec ) { - spec = Object.assign( {}, app.conf.spec, { - // Set the base path dynamically - basePath: req.path.toString().replace( /\/$/, '' ) - } ); - - if ( req.params.domain === req.headers.host.replace( /:[0-9]+$/, '' ) ) { - // This is a host-based request. Set an appropriate base path. - spec.basePath = spec[ 'x-host-basePath' ] || spec.basePath; - } - - res.send( spec ); - } else if ( req.query.doc !== undefined || - (
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MT test: Remove unwanted server.start
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383535 ) Change subject: MT test: Remove unwanted server.start .. MT test: Remove unwanted server.start Change-Id: Iec460c6cd5ecc1032c207fecb505381ca1fda6b7 --- M test/mt/Apertium.test.js 1 file changed, 0 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/35/383535/1 diff --git a/test/mt/Apertium.test.js b/test/mt/Apertium.test.js index 34aecf3..d22d1ee 100644 --- a/test/mt/Apertium.test.js +++ b/test/mt/Apertium.test.js @@ -95,9 +95,6 @@ ]; describe( 'Apertium machine translation', function () { - before( function () { - return server.start(); - } ); async.forEach( tests, function ( test ) { it( 'Test: ' + test.title, function () { var textTranslations, apertium; -- To view, visit https://gerrit.wikimedia.org/r/383535 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iec460c6cd5ecc1032c207fecb505381ca1fda6b7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Remove parsoid generated section tags if any from the parsed...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383329 ) Change subject: Remove parsoid generated section tags if any from the parsed page content .. Remove parsoid generated section tags if any from the parsed page content Makes cxserver content parser ready to support T114072 - Section wrapping for MediaWiki sections. CX Will do its own section wrapping based on translatable section concept. Added tests and did some code cleanup for LinearDoc.test.js Bug: T177752 Change-Id: I743ca44b1f431e9a42a7f907922b8fe6048b6081 --- M lib/lineardoc/Builder.js M test/lineardoc/LinearDoc.test.js A test/lineardoc/data/test6-result.xhtml A test/lineardoc/data/test6-result.xml A test/lineardoc/data/test6.xhtml 5 files changed, 101 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/29/383329/1 diff --git a/lib/lineardoc/Builder.js b/lib/lineardoc/Builder.js index b8fc92d..36e9a67 100644 --- a/lib/lineardoc/Builder.js +++ b/lib/lineardoc/Builder.js @@ -32,7 +32,14 @@ Builder.prototype.pushBlockTag = function ( tag ) { this.finishTextBlock(); this.blockTags.push( tag ); + if ( this.isParsoidSection( tag ) ) { + return; + } this.doc.addItem( 'open', tag ); +}; + +Builder.prototype.isParsoidSection = function ( tag ) { + return tag.name === 'section' && tag.attributes[ 'data-section-number' ]; }; Builder.prototype.popBlockTag = function ( tagName ) { @@ -43,7 +50,11 @@ ); } this.finishTextBlock(); - this.doc.addItem( 'close', tag ); + + if ( !this.isParsoidSection( tag ) ) { + this.doc.addItem( 'close', tag ); + } + return tag; }; diff --git a/test/lineardoc/LinearDoc.test.js b/test/lineardoc/LinearDoc.test.js index 3907fc1..e2bc9ce 100644 --- a/test/lineardoc/LinearDoc.test.js +++ b/test/lineardoc/LinearDoc.test.js @@ -1,54 +1,57 @@ 'use strict'; -var assert = require( '../utils/assert.js' ), +const assert = require( '../utils/assert' ), LinearDoc = require( '../../lib/lineardoc' ), fs = require( 'fs' ), transTests = require( __dirname + '/translate.test.json' ); -describe( 'LinearDoc', function () { - it( 'should be possible to linearise all kind of HTML inputs', function () { - var parser, testXhtmlFile, resultXmlFile, resultXhtmlFile, testXhtml, resultXml, - resultXhtml, i, - numTests = 5; - for ( i = 1; i <= numTests; i++ ) { - testXhtmlFile = __dirname + '/data/test' + i + '.xhtml'; - resultXmlFile = __dirname + '/data/test' + i + '-result.xml'; - resultXhtmlFile = __dirname + '/data/test' + i + '-result.xhtml'; +function normalize( html ) { + const normalizer = new LinearDoc.Normalizer(); + normalizer.init(); + normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) ); + return normalizer.getHtml(); +} - testXhtml = fs.readFileSync( testXhtmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); - resultXml = fs.readFileSync( resultXmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); - resultXhtml = fs.readFileSync( resultXhtmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); - parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); +describe( 'LinearDoc', () => { + it( 'should be possible to linearise all kind of HTML inputs', () => { + const numTests = 6; + for ( let i = 1; i <= numTests; i++ ) { + const testXhtmlFile = __dirname + '/data/test' + i + '.xhtml'; + const resultXmlFile = __dirname + '/data/test' + i + '-result.xml'; + const resultXhtmlFile = __dirname + '/data/test' + i + '-result.xhtml'; + + const testXhtml = fs.readFileSync( testXhtmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); + const resultXml = fs.readFileSync( resultXmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); + const resultXhtml = fs.readFileSync( resultXhtmlFile, 'utf8' ).replace( /^\s+|\s+$/, '' ); + const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); parser.init(); parser.write( testXhtml ); assert.deepEqual( - parser.builder.doc.dumpXml(), - resultXml, + normalize( parser.builder.doc.dumpXml() ), + normalize( resultXml ), 'Linearised structure' ); assert.deepEqual( -
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: CXSegmenter: Rewrite as ES6 class
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383108 ) Change subject: CXSegmenter: Rewrite as ES6 class .. CXSegmenter: Rewrite as ES6 class Change-Id: I3fdabadcba038f8095af6c65120f0598fec7a97f --- M lib/segmentation/CXSegmenter.js 1 file changed, 40 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/08/383108/1 diff --git a/lib/segmentation/CXSegmenter.js b/lib/segmentation/CXSegmenter.js index dbe952e..a1f793c 100644 --- a/lib/segmentation/CXSegmenter.js +++ b/lib/segmentation/CXSegmenter.js @@ -3,41 +3,48 @@ var LinearDoc = require( '../lineardoc' ), segmenters = require( __dirname + '/languages' ).Segmenters; -function CXSegmenter( content, language ) { - this.parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); - this.parser.init(); - this.getBoundaries = this.getSegmenter( language ); - this.content = content; - this.originalDoc = null; - this.segmentedDoc = null; -} - -CXSegmenter.prototype.segment = function () { - this.parser.write( this.content ); - this.originalDoc = this.parser.builder.doc; - this.segmentedDoc = this.originalDoc.segment( this.getBoundaries ); -}; - -/** - * Get the segmenter for the given language. - * - * @param {string} language Language code - * @return {Function} The segmenter function - */ -CXSegmenter.prototype.getSegmenter = function ( language ) { - var segmenter; - if ( !segmenters[ language ] ) { - // fallback to default segmenter - segmenter = segmenters.default; - } else { - segmenter = segmenters[ language ]; +class CXSegmenter { + constructor( content, language ) { + this.parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); + this.parser.init(); + this.getBoundaries = this.getSegmenter( language ); + this.content = content; + this.originalDoc = null; + this.segmentedDoc = null; } - return segmenter.getBoundaries; -}; + segment() { + this.parser.write( this.content ); + this.originalDoc = this.parser.builder.doc; + this.segmentedDoc = this.originalDoc.segment( this.getBoundaries ); + } -CXSegmenter.prototype.getSegmentedContent = function () { - return this.segmentedDoc.getHtml(); -}; + /** +* Get the segmenter for the given language. +* +* @param {string} language Language code +* @return {Function} The segmenter function +*/ + getSegmenter( language ) { + var segmenter; + if ( !segmenters[ language ] ) { + // fallback to default segmenter + segmenter = segmenters.default; + } else { + segmenter = segmenters[ language ]; + } + + return segmenter.getBoundaries; + } + + getSegmentedContent() { + return this.segmentedDoc.getHtml(); + } + + getSegmentedDoc() { + return this.segmentedDoc; + } + +} module.exports = CXSegmenter; -- To view, visit https://gerrit.wikimedia.org/r/383108 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3fdabadcba038f8095af6c65120f0598fec7a97f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Combine page fetch, segmentation to a new class
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/383109 ) Change subject: Combine page fetch, segmentation to a new class .. Combine page fetch, segmentation to a new class * Simplify the API end point for page/:language/:title/:revision? in v1.js. Router is not supposed to data processing as it does now. * Move pageloader/PageLoader.js to mw/MWPage class which now does page fetch and segmentation call. In follow ups, we will add section wrapping call to ths class(T177752). * The new MWPage class inherits APIRequest. Move the remaining utility methods in apiUtil to APIRequest class so that api related methods are in single place. Known issues to be fixed: * The language parameter passed to the /page api is sometimes domain because of the way services is keeping cxserver behind xx.wikipedia.org/api. Using our domain template we need to understand which one is passed and derive language code from it. Change-Id: I2ad6e1f183c8fe69c960597a29632989965cce82 --- M app.js D lib/api-util.js M lib/mw/ApiRequest.js A lib/mw/MWPage.js D lib/pageloader/PageLoader.js M lib/routes/v1.js 6 files changed, 145 insertions(+), 169 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/09/383109/1 diff --git a/app.js b/app.js index 907fbe6..1795d04 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,6 @@ bodyParser = require( 'body-parser' ), fs = BBPromise.promisifyAll( require( 'fs' ) ), sUtil = require( './lib/util' ), - apiUtil = require( './lib/api-util' ), packageInfo = require( './package.json' ), yaml = require( 'js-yaml' ); @@ -59,9 +58,6 @@ } } } - - // set up the request templates for the APIs - apiUtil.setupApiTemplates( app ); // set up the spec if ( !app.conf.spec ) { diff --git a/lib/api-util.js b/lib/api-util.js deleted file mode 100644 index 435cd37..000 --- a/lib/api-util.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -var preq = require( 'preq' ), - Template = require( 'swagger-router' ).Template; - -/** - * Calls the REST API with the supplied domain, path and request parameters - * - * @param {Object} app the application object - * @param {string} domain the domain to issue the request for - * @param {string} path the REST API path to contact without the leading slash - * @param {Object} [restReq={}] the object containing the REST request details - * @param {string} [restReq.method=get] the request method - * @param {Object} [restReq.query={}] the query string to send, if any - * @param {Object} [restReq.headers={}] the request headers to send - * @param {Object} [restReq.body=null] the body of the request, if any - * @return {Promise} a promise resolving as the response object from the REST API - * - */ -function restApiGet( app, domain, path, restReq ) { - var request; - restReq = restReq || {}; - path = path[ 0 ] === '/' ? path.slice( 1 ) : path; - - request = app.restbase_tpl.expand( { - request: { - method: restReq.method, - params: { - domain: domain, - path: path - }, - query: restReq.query, - headers: Object.assign( { - 'user-agent': app.conf.user_agent - }, restReq.headers ), - body: restReq.body - } - } ); - - return preq( request ); -} - -/** - * Sets up the request templates for MW and RESTBase API requests - * - * @param {Application} app the application object - */ -function setupApiTemplates( app ) { - /* eslint-disable camelcase */ - // set up the MW API request template - if ( !app.conf.mwapi_req ) { - app.conf.mwapi_req = { - uri: 'https://{{domain}}/w/api.php', - headers: { - 'user-agent': '{{user-agent}}' - }, - query: '{{ default(request.query, {}) }}', - body: '{{request.body}}' - }; - } - app.mwapi_tpl = new Template( app.conf.mwapi_req ); - - // set up the RESTBase request template - if ( !app.conf.restbase_req ) { - app.conf.restbase_req = { - method: '{{request.method}}', - uri: 'http://{{domain}}/api/rest_v1/{+path}', - query: '{{ default(request.query, {}) }}', - headers: '{{request.headers}}', - body: '{{request.body}}' - }; - } - app.restbase_tpl = new Template( app.conf.restbase_req ); - /* eslint-enable camelcase */ -}
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Include scripts in bin folder for eslint and make it pass tests
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382377 ) Change subject: Include scripts in bin folder for eslint and make it pass tests .. Include scripts in bin folder for eslint and make it pass tests Change-Id: Ib63491db26d5fc660b5d646779825fdf46b395cd --- M bin/linearize M bin/mt M bin/segment M test/index.js 4 files changed, 20 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/77/382377/1 diff --git a/bin/linearize b/bin/linearize index 5dc027c..0118b9e 100755 --- a/bin/linearize +++ b/bin/linearize @@ -1,11 +1,10 @@ #!/usr/bin/env node -var script, xhtml, parser, - fs = require( 'fs' ), +const fs = require( 'fs' ), LinearDoc = require( __dirname + '/../lib/lineardoc' ); -xhtml = fs.readFileSync( '/dev/stdin', 'utf8' ); +const xhtml = fs.readFileSync( '/dev/stdin', 'utf8' ); if ( xhtml.trim() === '' ) { - script = process.argv[ 1 ]; + const script = process.argv[ 1 ]; process.stderr.write( 'Usage: node ' + script + ' < file\n' + 'Input must be wrapped in a block element such as ... or ...\n' @@ -14,7 +13,7 @@ } -parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); +const parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); parser.init(); parser.write( xhtml ); process.stdout.write( parser.builder.doc.dumpXml() ); diff --git a/bin/mt b/bin/mt index 4796cf5..e20ff8e 100755 --- a/bin/mt +++ b/bin/mt @@ -5,7 +5,7 @@ const config = yaml.load( fs.readFileSync( 'config.yaml' ) ); if ( !config ) { - console.error( 'Failed to load config' ); + process.stderr.write( 'Failed to load config' ); process.exit( 1 ); } const cxConfig = config.services && Array.isArray( config.services ) && @@ -13,7 +13,7 @@ return item && item.name === 'cxserver'; } )[ 0 ]; if ( !cxConfig ) { - console.error( 'Cannot find cxserver config' ); + process.stderr.write( 'Cannot find cxserver config' ); process.exit( 1 ); } @@ -42,7 +42,7 @@ } if ( !MTClients[ mtService ] ) { - console.error( `Cannot find MT service: ${mtService}` ); + process.stderr.write( `Cannot find MT service: ${mtService}` ); process.exit( 1 ); } @@ -56,9 +56,9 @@ process.stdout.write( targetHtml + '\n' ); } ).catch( ( error ) => { if ( error.stack ) { - console.error( 'error', error.stack ); + process.stderr.write( 'error', error.stack ); } else { - console.error( 'error', error ); + process.stderr.write( 'error', error ); } process.exit( 2 ); } ); diff --git a/bin/segment b/bin/segment index 31da4b2..c32dc2a 100755 --- a/bin/segment +++ b/bin/segment @@ -1,19 +1,18 @@ #!/usr/bin/env node -var script, xhtmlSource, xhtml, result, segmenter, - fs = require( 'fs' ), +const fs = require( 'fs' ), Segmenter = require( __dirname + '/../lib/segmentation/CXSegmenter' ), LinearDoc = require( __dirname + '/../lib/lineardoc' ); function normalize( html ) { - var normalizer = new LinearDoc.Normalizer(); + const normalizer = new LinearDoc.Normalizer(); normalizer.init(); normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) ); return normalizer.getHtml(); } -html = fs.readFileSync( '/dev/stdin', 'utf8' ); +const html = fs.readFileSync( '/dev/stdin', 'utf8' ); if ( html.trim() === '' ) { - script = process.argv[ 1 ]; + const script = process.argv[ 1 ]; process.stderr.write( 'Usage: node ' + script + ' < file\n' + 'Input must be wrapped in a block element such as ... or ...\n' @@ -22,7 +21,7 @@ } -segmenter = new Segmenter( html, 'en' ); +const segmenter = new Segmenter( html, 'en' ); segmenter.segment(); -result = normalize( segmenter.getSegmentedContent() ); +const result = normalize( segmenter.getSegmentedContent() ); process.stdout.write( result + '\n' ); diff --git a/test/index.js b/test/index.js index eaa94e6..2dec3d5 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,11 @@ paths = [ 'lib/*.js', 'lib/**/*.js', - 'test/**/*.js' + 'test/**/*.js', + 'bin/mt', + 'bin/adapt', + 'bin/linearize', + 'bin/segment' ]; // Run the tests -- To view, visit https://gerrit.wikimedia.org/r/382377 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib63491db26d5fc660b5d646779825fdf46b395cd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Remove config.yaml from the repository
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382133 ) Change subject: Remove config.yaml from the repository .. Remove config.yaml from the repository It is a symlink to config.dev.yaml. But having the default configuration tracked in git makes development and debugging with local customization difficult. Extra care needed to avoid changes getting committed. Instructions in README already recommends copying config.dev.yaml to config.yaml and do customization. Change-Id: I6137c12b998fce4cbd70a34f0ccbfacd6c3cb9e8 --- D config.yaml 1 file changed, 0 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/33/382133/1 diff --git a/config.yaml b/config.yaml deleted file mode 12 index c11eec8..000 --- a/config.yaml +++ /dev/null @@ -1 +0,0 @@ -config.dev.yaml \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/382133 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6137c12b998fce4cbd70a34f0ccbfacd6c3cb9e8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Adaptation tests: Do assertions on structured data
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382126 ) Change subject: Adaptation tests: Do assertions on structured data .. Adaptation tests: Do assertions on structured data Avoid DOM comparison about the text which is less relevant to adaptation. Follow up for I12a723732b87 Do comparison on 1. data-cx if any 2. data-mw if any 3. Also match id attributes in source and result. While at that, MWCategory required minor updates to have proper data-cx. This should fix the failing tests due to strict check on MT output. Change-Id: Ife940ebce6f26cfe0bde0181a2982670add61a96 --- M lib/translationunits/MWCategory.js M test/adaptation/AdaptationTest.js M test/adaptation/AdaptationTests.json 3 files changed, 606 insertions(+), 71 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/26/382126/1 diff --git a/lib/translationunits/MWCategory.js b/lib/translationunits/MWCategory.js index bfc4a44..c0dc879 100644 --- a/lib/translationunits/MWCategory.js +++ b/lib/translationunits/MWCategory.js @@ -7,24 +7,25 @@ class MWCategory extends TranslationUnit {} MWCategory.prototype.adapt = cxutil.async( function* () { - var namespaceAlias, adaptedTitle, titlePairInfo, + let dataCX = { adapted: false }, categoryTitle = this.node.attributes.href; - titlePairInfo = yield new MWAPIRequestManager( this.context ) + const titlePairInfo = yield new MWAPIRequestManager( this.context ) .titlePairRequest( categoryTitle, this.sourceLanguage, this.targetLanguage ); + dataCX.sourceTitle = titlePairInfo.sourceTitle; if ( titlePairInfo.targetTitle ) { - adaptedTitle = titlePairInfo.targetTitle; - namespaceAlias = yield new MWAPIRequestManager( this.context ) + let adaptedTitle = titlePairInfo.targetTitle; + let namespaceAlias = yield new MWAPIRequestManager( this.context ) .getNamespaceAlias( 'Category', this.targetLanguage ); adaptedTitle = adaptedTitle.replace( /^(\.\.?\/)*([^:]+)(:)/, '$1' + namespaceAlias + '$3' ); this.node.attributes.href = adaptedTitle; - } else { - this.node.attributes[ 'data-cx' ] = JSON.stringify( { - adapted: false, - sourceTitle: titlePairInfo.sourceTitle - } ); + + dataCX.adapted = true; + dataCX.targetTitle = titlePairInfo.targetTitle; } + + this.node.attributes[ 'data-cx' ] = JSON.stringify( dataCX ); return this.node; } ); diff --git a/test/adaptation/AdaptationTest.js b/test/adaptation/AdaptationTest.js index 04691c2..536182a 100644 --- a/test/adaptation/AdaptationTest.js +++ b/test/adaptation/AdaptationTest.js @@ -3,7 +3,7 @@ const assert = require( 'assert' ), server = require( '../utils/server.js' ), async = require( 'async' ), - Apertium = require( '../../lib/mt' ).Apertium, + TestClient = require( '../../lib/mt' ).TestClient, Adapter = require( '../../lib/Adapter' ), tests = require( './AdaptationTests.json' ), jsdom = require( 'jsdom' ); @@ -13,28 +13,26 @@ let adapter, cxserver; cxserver = server.config.conf.services[ server.config.conf.services.length - 1 ]; - cxserver.conf.mtClient = new Apertium( cxserver ); + cxserver.conf.mtClient = new TestClient( cxserver ); adapter = new Adapter( test.from, test.to, cxserver ); it( test.desc, () => { - let expectedDom = new jsdom.JSDOM( test.result ); - // Put data-cx in - if ( test[ 'data-cx' ] ) { - for ( let id in test[ 'data-cx' ] ) { - expectedDom.window.document.getElementById( id ) - .setAttribute( 'data-cx', JSON.stringify( test[ 'data-cx' ][ id ] ) ); - } - } - return adapter.adapt( test.source ).then( ( result ) => { let actualDom = new jsdom.JSDOM( result.getHtml() ); - if ( actualDom.window.document.body.isEqualNode( expectedDom.window.document.body ) ) { - assert.ok( true, test.desc ); - } else { - assert.equal( - actualDom.window.document.body.outerHTML, - expectedDom.window.document.body.outerHTML, - test.desc - ); +
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Make bin/apertium-xhtml a generic mt testing utility
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382113 ) Change subject: Make bin/apertium-xhtml a generic mt testing utility .. Make bin/apertium-xhtml a generic mt testing utility Moved it to bin/mt and accepts MT service name. Helps testing mt services easily. Change-Id: Ic214822132e339208b2e7c158510c7d8779ed18f --- D bin/apertium-xhtml A bin/mt 2 files changed, 56 insertions(+), 55 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/13/382113/1 diff --git a/bin/apertium-xhtml b/bin/apertium-xhtml deleted file mode 100755 index 61cde1a..000 --- a/bin/apertium-xhtml +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env node -var sourceLang, targetLang, sourceHtml, script, args, config, cxConfig, - fs = require( 'fs' ), - yaml = require( 'js-yaml' ), - Apertium = require( __dirname + '/../lib/mt/Apertium.js' ); - -config = yaml.load( fs.readFileSync( 'config.yaml' ) ); -if ( !config ) { - console.error( 'Failed to load config' ); - process.exit( 1 ); -} -cxConfig = config.services && Array.isArray( config.services ) && - config.services.filter( function ( item ) { - return item && item.name === 'cxserver'; - } )[ 0 ]; -if ( !cxConfig ) { - console.error( 'Cannot find cxserver config' ); - process.exit( 1 ); -} - -script = process.argv[ 1 ]; -args = process.argv.slice( 2 ); -if ( args.length !== 2 ) { - process.stderr.write( - 'Usage: node ' + script + ' < xhtmlSource\n\n' + - 'xhtml must be wrapped in a block element such as ... or ...\n' + - 'Example:\n\techo "A red box." | node ' + script + ' en es\n\n' - ); - process.exit( 1 ); -} - -sourceLang = args[ 0 ]; -targetLang = args[ 1 ]; - -sourceHtml = []; - -process.stdin.on( 'data', function ( data ) { - sourceHtml.push( data ); -} ); -process.stdin.on( 'end', function () { - new Apertium( cxConfig ).translate( - sourceLang, - targetLang, - sourceHtml.join( '' ) - ).then( function ( targetHtml ) { - process.stdout.write( targetHtml + '\n' ); - } ).catch( function ( error ) { - if ( error.stack ) { - console.error( 'error', error.stack ); - } else { - console.error( 'error', error ); - } - process.exit( 2 ); - } ); -} ); diff --git a/bin/mt b/bin/mt new file mode 100755 index 000..6d0c5c0 --- /dev/null +++ b/bin/mt @@ -0,0 +1,56 @@ +#!/usr/bin/env node +const fs = require( 'fs' ), + yaml = require( 'js-yaml' ), + MTClients = require( __dirname + '/../lib/mt/' ); + +const config = yaml.load( fs.readFileSync( 'config.yaml' ) ); +if ( !config ) { + console.error( 'Failed to load config' ); + process.exit( 1 ); +} +const cxConfig = config.services && Array.isArray( config.services ) && + config.services.filter( function ( item ) { + return item && item.name === 'cxserver'; + } )[ 0 ]; +if ( !cxConfig ) { + console.error( 'Cannot find cxserver config' ); + process.exit( 1 ); +} + +const script = process.argv[ 1 ]; +const args = process.argv.slice( 2 ); +const mtService = args[ 0 ]; +const sourceLang = args[ 1 ]; +const targetLang = args[ 2 ]; + +let sourceHtml = fs.readFileSync( '/dev/stdin', 'utf8' ); +if ( sourceHtml.trim() === '' || args.length !== 3 ) { + process.stderr.write( + 'Usage: node ' + script + ' < xhtmlSource\n\n' + + 'Example:\n\techo "A red box." | node ' + script + ' Apertium en es\n\n' + ); + process.exit( 1 ); + +} + +if ( !MTClients[ mtService ] ) { + console.error( `Cannot find MT service: ${mtService}` ); + process.exit( 1 ); +} + +let mt = new MTClients[ mtService ]( cxConfig ); + +return mt.translate( + sourceLang, + targetLang, + sourceHtml +).then( ( targetHtml ) => { + process.stdout.write( targetHtml + '\n' ); +} ).catch( ( error ) => { + if ( error.stack ) { + console.error( 'error', error.stack ); + } else { + console.error( 'error', error ); + } + process.exit( 2 ); +} ); -- To view, visit https://gerrit.wikimedia.org/r/382113 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic214822132e339208b2e7c158510c7d8779ed18f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Matxin MT: Use an API key to access the service
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382111 ) Change subject: Matxin MT: Use an API key to access the service .. Matxin MT: Use an API key to access the service As Matchin maintainers suggested, the API is adding a key to control the usage of service. Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a --- M lib/mt/Matxin.js 1 file changed, 5 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/11/382111/1 diff --git a/lib/mt/Matxin.js b/lib/mt/Matxin.js index c48959d..6b9546f 100644 --- a/lib/mt/Matxin.js +++ b/lib/mt/Matxin.js @@ -23,11 +23,16 @@ return preq.post( { uri: this.conf.mt.Matxin.api, body: { + key: this.conf.mt.Matxin.key, direction: sourceLang + '-' + targetLang, text: sourceText } } ).then( ( response ) => response.body.translation.replace( /\. ॥ ॥\. /g, '.॥॥.' ) ); } + + requiresAuthorization() { + return true; + } } module.exports = Matxin; -- To view, visit https://gerrit.wikimedia.org/r/382111 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MWImage: Support Inline images with figute-inline tag
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381960 ) Change subject: MWImage: Support Inline images with figute-inline tag .. MWImage: Support Inline images with figute-inline tag Support translation of caption in data-mw if present and an MT Client is available for the language pair. Whitelist figure-inline in DOM sanitization. Change-Id: I8db09d11bb64701811720a45b526cc6395fbd84e --- M bin/adapt M lib/lineardoc/Parser.js M lib/mt/MTClient.js M lib/translationunits/MWImage.js 4 files changed, 23 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/60/381960/1 diff --git a/bin/adapt b/bin/adapt index 7e90699..4232801 100755 --- a/bin/adapt +++ b/bin/adapt @@ -2,6 +2,7 @@ const fs = require( 'fs' ), yaml = require( 'js-yaml' ), Adapter = require( __dirname + '/../lib/Adapter' ), + TestClient = require( __dirname + '/../lib/mt' ).TestClient, Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer; let config = yaml.load( fs.readFileSync( 'config.yaml' ) ); @@ -36,6 +37,8 @@ } +cxConfig.conf.mtClient = new TestClient( cxConfig ); + let from = process.argv[ 2 ]; let to = process.argv[ 3 ]; let adapter = new Adapter( from, to, cxConfig ); diff --git a/lib/lineardoc/Parser.js b/lib/lineardoc/Parser.js index f34cdc6..5af4172 100644 --- a/lib/lineardoc/Parser.js +++ b/lib/lineardoc/Parser.js @@ -25,7 +25,7 @@ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup', // HTML5 sectioning content 'article', 'aside', 'body', 'nav', 'section', 'footer', 'header', 'figure', - 'figcaption', 'fieldset', 'details', 'blockquote', + 'figcaption', 'figure-inline', 'fieldset', 'details', 'blockquote', // other 'hr', 'button', 'canvas', 'center', 'col', 'colgroup', 'embed', 'map', 'object', 'pre', 'progress', 'video', diff --git a/lib/mt/MTClient.js b/lib/mt/MTClient.js index 755283d..0722166 100644 --- a/lib/mt/MTClient.js +++ b/lib/mt/MTClient.js @@ -107,6 +107,7 @@ return this.DOMPurify.sanitize( html, { // These are not known attributes for DOMPurify + ADD_TAGS: [ 'figure-inline' ], ADD_ATTR: [ 'typeof', 'resource', 'src', 'srcset' ], ADD_URI_SAFE_ATTR: [ 'rel', 'typeof' ] // Without this rel="mw:WikiLink" attributes will be removed. } ); diff --git a/lib/translationunits/MWImage.js b/lib/translationunits/MWImage.js index d99903a..bb48fbf 100644 --- a/lib/translationunits/MWImage.js +++ b/lib/translationunits/MWImage.js @@ -9,6 +9,9 @@ class MWImage extends TranslationUnit { constructor( node, sourceLanguage, targetLanguage, context ) { super( node, sourceLanguage, targetLanguage, context ); + this.imageSource = null; + this.sourceResource = null; + this.isInlineImage = node.name === 'figure-inline'; } /** @@ -52,10 +55,10 @@ } MWImage.prototype.adapt = cxutil.async( function* () { - var i, len, chunk, sourceImage, imageLink, targetResource, namespaceAlias; + var sourceImage, imageLink; - for ( i = 0, len = this.node.children.textChunks.length; i < len; i++ ) { - chunk = this.node.children.textChunks[ i ]; + for ( let i = 0, len = this.node.children.textChunks.length; i < len; i++ ) { + let chunk = this.node.children.textChunks[ i ]; if ( chunk.tags[ 0 ] && chunk.tags[ 0 ].name === 'a' ) { imageLink = chunk.tags[ 0 ]; } @@ -72,23 +75,31 @@ this.sourceResource = sourceImage.attributes.resource; this.adaptImageAlignment(); + if ( this.isInlineImage && this.context.conf.mtClient && this.node.attributes[ 'data-mw' ] ) { + const caption = JSON.parse( this.node.attributes[ 'data-mw' ] ).caption; + const translatedCaption = yield this.context.conf.mtClient.translate( + this.sourceLanguage, this.targetLanguage, caption + ); + this.node.attributes[ 'data-mw' ] = JSON.stringify( { caption: translatedCaption } ); + } + if ( this.isCommonsImage( sourceImage.attributes.src ) ) { - namespaceAlias = yield new MWApiRequestManager( this.context ).getNamespaceAlias( 'File', this.targetLanguage ); - targetResource = this.sourceResource.replace( /^(\.\.?\/)*([^:]+)(:)/, '$1' + namespaceAlias + '$3' ); + let namespaceAlias = yield new MWApiRequestManager( this.context ).getNamespaceAlias( 'File', this.targetLanguage ); + let targetResource = this.sourceResource.replace( /^(\.\.?\/)*([^:]+)(:)/, '$1' + namespaceAlias + '$3' );
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Adapter#getAdaper: Do not ignore mismatch with explicit tags...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381951 ) Change subject: Adapter#getAdaper: Do not ignore mismatch with explicit tags and rdfa .. Adapter#getAdaper: Do not ignore mismatch with explicit tags and rdfa If tags is defined and an element could not match with any of it, do not proceed with rdfa matching. For example, an inline image with tag with typeof="mw:Image/Frameless" will match MWImage translation unit now eventhough the tags does not define span. It defines only Change-Id: Ic39cf1f1aa89137407b62396887761e5db9cbab6 --- M lib/Adapter.js 1 file changed, 9 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/51/381951/1 diff --git a/lib/Adapter.js b/lib/Adapter.js index 167a415..64c4c8e 100644 --- a/lib/Adapter.js +++ b/lib/Adapter.js @@ -33,9 +33,18 @@ let translationUnit = translationUnits[ name ]; if ( translationUnit.matchTagNames ) { match = translationUnit.matchTagNames.includes( element.name ); + + if ( !match ) { + // If matchTagNames is explicitly defined, a match is must. + break; + } } if ( translationUnit.matchRdfaTypes ) { match = translationUnit.matchRdfaTypes.includes( element.attributes.rel ) || translationUnit.matchRdfaTypes.includes( element.attributes.typeof ); + if ( !match ) { + // If matchRdfaTypes is explicitly defined, a match is must. + break; + } } if ( match ) { break; -- To view, visit https://gerrit.wikimedia.org/r/381951 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic39cf1f1aa89137407b62396887761e5db9cbab6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MWImage: Fix js error when textchunk is \n with no tags
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381949 ) Change subject: MWImage: Fix js error when textchunk is \n with no tags .. MWImage: Fix js error when textchunk is \n with no tags Add a check for tags array before accessing. Can be tested using the bin/adapt utility and the following html caption Change-Id: I1f31ccfe940725bd9cde0d990df3851ad0a9eb15 --- M lib/translationunits/MWImage.js 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/49/381949/1 diff --git a/lib/translationunits/MWImage.js b/lib/translationunits/MWImage.js index 1d7dce9..d99903a 100644 --- a/lib/translationunits/MWImage.js +++ b/lib/translationunits/MWImage.js @@ -56,7 +56,7 @@ for ( i = 0, len = this.node.children.textChunks.length; i < len; i++ ) { chunk = this.node.children.textChunks[ i ]; - if ( chunk.tags[ 0 ].name === 'a' ) { + if ( chunk.tags[ 0 ] && chunk.tags[ 0 ].name === 'a' ) { imageLink = chunk.tags[ 0 ]; } if ( chunk.inlineContent && chunk.inlineContent.name === 'img' ) { -- To view, visit https://gerrit.wikimedia.org/r/381949 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1f31ccfe940725bd9cde0d990df3851ad0a9eb15 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add utility binary adapt
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381945 ) Change subject: Add utility binary adapt .. Add utility binary adapt Adapts given HTML content using cxserver adaptation system. Useful for debugging and development Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307 --- A bin/adapt 1 file changed, 45 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/45/381945/1 diff --git a/bin/adapt b/bin/adapt new file mode 100755 index 000..7e90699 --- /dev/null +++ b/bin/adapt @@ -0,0 +1,45 @@ +#!/usr/bin/env node +const fs = require( 'fs' ), + yaml = require( 'js-yaml' ), + Adapter = require( __dirname + '/../lib/Adapter' ), + Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer; + +let config = yaml.load( fs.readFileSync( 'config.yaml' ) ); +if ( !config ) { + process.stdout.write( 'Failed to load config' ); + process.exit( 1 ); +} + +let cxConfig = config.services && Array.isArray( config.services ) && + config.services.filter( function ( item ) { + return item && item.name === 'cxserver'; + } )[ 0 ]; +if ( !cxConfig ) { + process.stdout.write( 'Cannot find cxserver config' ); + process.exit( 1 ); +} + +function normalize( html ) { + var normalizer = new Normalizer(); + normalizer.init(); + normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) ); + return normalizer.getHtml(); +} + +let xhtml = fs.readFileSync( '/dev/stdin', 'utf8' ); +if ( xhtml.trim() === '' || process.argv.length !== 4 ) { + let script = process.argv[ 1 ]; + process.stderr.write( + 'Usage: node ' + script + ' fromLang toLang < file\n' + ); + process.exit( 1 ); + +} + +let from = process.argv[ 2 ]; +let to = process.argv[ 3 ]; +let adapter = new Adapter( from, to, cxConfig ); +adapter.adapt( xhtml ).then( function ( result ) { + result = normalize( result.getHtml() ); + process.stdout.write( result + '\n' ); +} ); -- To view, visit https://gerrit.wikimedia.org/r/381945 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Templates: If templatedata not found, try to extract info fr...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381943 ) Change subject: Templates: If templatedata not found, try to extract info from source code .. Templates: If templatedata not found, try to extract info from source code Bug: T162114 Change-Id: I75390c6621d7b84fb04666281c875f0b7e6ed51a --- M lib/mw/TemplateDataRequest.js 1 file changed, 60 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/43/381943/1 diff --git a/lib/mw/TemplateDataRequest.js b/lib/mw/TemplateDataRequest.js index 02424ec..22728d0 100644 --- a/lib/mw/TemplateDataRequest.js +++ b/lib/mw/TemplateDataRequest.js @@ -4,6 +4,19 @@ class TemplateDataRequest extends BatchedAPIRequest { processPage( page ) { + if ( page.revisions && page.revisions[ 0 ] ) { + let title, + pageContent = ''; + if ( page.revisions && page.revisions[ 0 ] ) { + pageContent = page.revisions[ 0 ].content; + title = page.title; + } + return { + title: title, + params: this.extractParametersFromTemplateCode( pageContent ) + }; + } + return page; } @@ -20,7 +33,53 @@ redirects: true }; domain = this.getDomain( this.sourceLanguage ); - return this.mwPost( domain, query ); + + return this.mwPost( domain, query ).then( ( resp ) => { + if ( !Object.keys( resp.pages ).length ) { + return this.getTemplateParamsUsingSource( titles ); + } + return resp; + } ); + } + + /** +* Fetch the template source code and extract the template parameters from it. +* +* @param {string[]} titles Template name with namespace prefix. +* @return {Object} +*/ + getTemplateParamsUsingSource( titles ) { + let query = { + formatversion: 2, + action: 'query', + titles: titles.join( '|' ), + redirects: true, + prop: 'revisions', + rvprop: 'content' + }; + let domain = this.getDomain( this.sourceLanguage ); + + return this.mwPost( domain, query ).then( ( resp ) => resp.query ); + } + + /** +* Retrieve template parameters from the template code. +* Adapted from https://he.wikipedia.org/wiki/MediaWiki:Gadget-TemplateParamWizard.js +* +* @param {string} templateCode Source of the template. +* @return {Object} An associative array of parameters that appear in the template code +*/ + extractParametersFromTemplateCode( templateCode ) { + var matches, + templateParams = {}, + paramExtractor = /{{3,}(.*?)[<|}]/mg; + + while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) { + let paramName = matches[ 1 ].trim(); + templateParams[ paramName ] = { desc: '', options: { multiline: 5 } }; + } + + return templateParams; } } -- To view, visit https://gerrit.wikimedia.org/r/381943 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I75390c6621d7b84fb04666281c875f0b7e6ed51a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Template adaptation: Implement template param name matching
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381418 ) Change subject: Template adaptation: Implement template param name matching .. Template adaptation: Implement template param name matching Algorithm: 1. Get template data for both source and target 2. Get aliases array for each parameter in source template, also add the param name to that and form aliases+name set 3. For each param in target template data, form a similar set of aliases and param. 4. Find intersection of above two sets. 5. If the intersection set is not empty, the source param maps to the param name we located in target template data Tests for name matching added. TODO: 1. Use the param mapping to build target template definition. 2. Update tests for MWTemplate.js Bug: T162114 Change-Id: I4ea9ae0dc902fecba0d300864e40cae6595c61b6 --- D config.yaml A config.yaml A lib/adaptation/TemplateParameterMapper.js M lib/adaptation/TemplateTransclusion.js A test/adaptation/TemplateParameterMapper.test.js M test/translationunits/MWTemplate.test.json 6 files changed, 357 insertions(+), 49 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/18/381418/1 diff --git a/config.yaml b/config.yaml deleted file mode 12 index c11eec8..000 --- a/config.yaml +++ /dev/null @@ -1 +0,0 @@ -config.dev.yaml \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 000..36280af --- /dev/null +++ b/config.yaml @@ -0,0 +1,93 @@ +# Number of worker processes to spawn. +# Set to 0 to run everything in a single process without clustering. +# Use ncpu to run as many workers as there are CPU units +num_workers: 0 + +# Log error messages and gracefully restart a worker if v8 reports that it +# uses more heap (note: not RSS) than this many megabytes. +worker_heap_limit_mb: 250 + +# Logger info +logging: + level: trace +# streams: +# # Use gelf-stream -> logstash +#- type: gelf +#host: logstash1003.eqiad.wmnet +#port: 12201 + +# Statsd metrics reporter +metrics: + type: log + #host: localhost + #port: 8125 + +services: + - name: cxserver +# a relative path or the name of an npm package, if different from name +module: ./app.js +# optionally, a version constraint of the npm package +# version: ^0.4.0 +# per-service config +conf: + port: 8080 + # interface: localhost # uncomment to only listen on localhost + # More per-service config settings + # The location of the spec, defaults to spec.yaml if not specified + # spec: ./spec.yaml + # allow cross-domain requests to the API (default *) + cors: '*' + # to disable use: + # cors: false + # to restrict to a particular domain, use: + # cors: restricted.domain.org + # URL of the outbound proxy to use (complete with protocol) + # proxy: http://my.proxy.org:8080 + # the list of domains for which not to use the proxy defined above + # no_proxy_list: + # - domain1.com + # - domain2.org + user_agent: cxserver + # Mediawiki host name. Example {lang}.wikisource.org which get expanded internally to + # es.wikisource.org in a spanish language context. + # Do not prefix with http or https:// + # mw_host: '{lang}.wikipedia.org' + mwapi_req: +body: "{{request.body}}" +query: "{{ default(request.query, {}) }}" +headers: + host: "{{request.params.domain}}" + user-agent: "{{user-agent}}" +method: post +uri: "https://{{domain}}/w/api.php; + restbase_req: +method: '{{request.method}}' +uri: https://{{domain}}/api/rest_v1/{+path} +query: '{{ default(request.query, {}) }}' +headers: '{{request.headers}}' +body: '{{request.body}}' + jwt: +secret: 'secret' +algorithms: + - HS256 + languages: config/languages.yaml + mt: +Apertium: + api: http://apertium.wmflabs.org + languages: config/Apertium.yaml +Yandex: + api: https://translate.yandex.net + key: null + languages: config/Yandex.yaml +Youdao: + api: https://fanyi.youdao.com/paidapi/fanyiapi + key: null + languages: config/Youdao.yaml +Matxin: + api: http://matxin.elhuyar.eus/API + languages: config/Matxin.yaml + dictionary: +Dictd: + languages: config/Dictd.yaml +JsonDict: + languages: config/JsonDict.yaml diff --git a/lib/adaptation/TemplateParameterMapper.js b/lib/adaptation/TemplateParameterMapper.js new file mode 100644 index 000..cb9a1f0 --- /dev/null +++ b/lib/adaptation/TemplateParameterMapper.js @@ -0,0 +1,59 @@ +class TemplateParameterMapper { + constructor( sourceParams, sourceTemplateData,
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Reference adaptation: Add a check for mt service
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381383 ) Change subject: Reference adaptation: Add a check for mt service .. Reference adaptation: Add a check for mt service Not all language pairs has mt client. Avoid error if mtClient is undefined. Change-Id: I16c59984420d44f87f0610b4d18c3b76a2bd0e17 --- M lib/translationunits/MWReference.js 1 file changed, 9 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/83/381383/1 diff --git a/lib/translationunits/MWReference.js b/lib/translationunits/MWReference.js index 4e74580..337f24e 100644 --- a/lib/translationunits/MWReference.js +++ b/lib/translationunits/MWReference.js @@ -42,12 +42,16 @@ } // TODO: Parse recursively instead of just MTing to handle templates - // Translate reference contents - let translatedRefBody = yield this.context.conf.mtClient.translate( - this.sourceLanguage, this.targetLanguage, refBody - ); - refData.body.html = translatedRefBody; + if ( this.context.conf.mtClient ) { + // Translate reference contents + let translatedRefBody = yield this.context.conf.mtClient.translate( + this.sourceLanguage, this.targetLanguage, refBody + ); + + refData.body.html = translatedRefBody; + } + this.node.attributes[ 'data-mw' ] = JSON.stringify( refData ); this.node.attributes[ 'data-cx' ] = JSON.stringify( { adapted: true -- To view, visit https://gerrit.wikimedia.org/r/381383 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I16c59984420d44f87f0610b4d18c3b76a2bd0e17 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Update express to 4.16
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381376 ) Change subject: Update express to 4.16 .. Update express to 4.16 Per https://nodesecurity.io/advisories/535 express released new verson https://github.com/expressjs/express/issues/3431 Change-Id: If4e4b48dd6a9be89ab2a21b1dfbf1744651f65f5 --- M package.json 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/76/381376/1 diff --git a/package.json b/package.json index b22efe3..965183c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "compression": "^1.6.2", "core-js": "^2.4.1", "domino": "^1.0.25", -"express": "^4.14.0", +"express": "^4.16.0", "html-entities": "1.2.0", "js-yaml": "^3.6.1", "jsonwebtoken": "~5.6.0", -- To view, visit https://gerrit.wikimedia.org/r/381376 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If4e4b48dd6a9be89ab2a21b1dfbf1744651f65f5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX2: Restore the saved translation
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380935 ) Change subject: CX2: Restore the saved translation .. CX2: Restore the saved translation Fill the translation sections with saved translations from earlier sessions by matching the section number. This commit implements the very basic section number matching logic. So it matches a linear order of source sections. If source article changed heavily, we need to use a better algorithm to identify source sections even if it changed. And fallback to original source revision if source article changed beyond restoring a saved translation. That is for follow up. Bug: T176843 Change-Id: Idd2dae87b487219d80391ff4f1a9cf74d6e9e8e4 --- M modules/dm/mw.cx.dm.Translation.js M modules/mw.cx.TranslationController.js M modules/mw.cx.init.Translation.js 3 files changed, 61 insertions(+), 66 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/35/380935/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index 75e5a55..57dcea3 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -10,9 +10,10 @@ * @param {mw.cx.dm.WikiPage} sourceWikiPage Details of source wiki page * @param {mw.cx.dm.WikiPage} targetWikiPage Details of target wiki page * @param {string} sourceHtml Segmented source HTML + * @param {Object} draft Saved translation * @param {Object} config */ -mw.cx.dm.Translation = function MwCxDmTranslation( sourceWikiPage, targetWikiPage, sourceHtml, config ) { +mw.cx.dm.Translation = function MwCxDmTranslation( sourceWikiPage, targetWikiPage, sourceHtml, draft, config ) { // Mixin constructor OO.EventEmitter.call( this ); @@ -38,13 +39,17 @@ this.topTranslationUnits = []; this.translationUnitById = {}; + if ( draft ) { + this.setSavedTranslation( draft ); + } + this.sourceDoc = ve.dm.converter.getModelFromDom( this.constructor.static.getSourceDom( sourceHtml, false ), { lang: this.sourceWikiPage.getLanguage(), dir: this.sourceWikiPage.getDirection() } ); this.targetDoc = ve.dm.converter.getModelFromDom( - this.constructor.static.getSourceDom( sourceHtml, true ), + this.constructor.static.getSourceDom( sourceHtml, true, this.savedTranslationUnits ), { lang: this.targetWikiPage.getLanguage(), dir: this.targetWikiPage.getDirection() } ); @@ -62,9 +67,10 @@ * * @param {string} sourceHtml The source HTML * @param {boolean} forTarget Replace each top-level wrapper section with an empty placeholder? + * @param {Object} savedTranslationUnits Saved translatin units if any * @return {HTMLDocument} Restructured source DOM */ -mw.cx.dm.Translation.static.getSourceDom = function ( sourceHtml, forTarget ) { +mw.cx.dm.Translation.static.getSourceDom = function ( sourceHtml, forTarget, savedTranslationUnits ) { var lastAboutGroup, nextSectionId = 1, sectionIdPrefix = forTarget ? 'cxTargetSection' : 'cxSourceSection', @@ -85,12 +91,16 @@ // Wrap each top-level element with a // TODO: it would be better to do section wrapping on the CX server Array.prototype.forEach.call( domDoc.body.childNodes, function ( node ) { - var sectionNode, aboutGroup; + var sectionNode, aboutGroup, savedTranslationNode; if ( node.nodeType !== Node.ELEMENT_NODE ) { return; } sectionNode = domDoc.createElement( 'section' ); aboutGroup = node.getAttribute( 'about' ); + + if ( forTarget && savedTranslationUnits && savedTranslationUnits[ nextSectionId ] ) { + savedTranslationNode = this.getSavedTranslation( savedTranslationUnits[ nextSectionId ] ); + } // For block level templates and their about-grouped siblings, don't give them // a section ID as they can't be translated yet // TODO: handle more systematically @@ -101,23 +111,49 @@ sectionNode.setAttribute( 'rel', forTarget ? 'cx:Placeholder' : 'cx:Section' ); nextSectionId++; } + if ( forTarget ) { node.parentNode.removeChild( node ); } else { sectionNode.appendChild( node ); } - articleNode.appendChild( sectionNode ); - } ); + articleNode.appendChild( savedTranslationNode || sectionNode ); + }.bind( this ) ); + + // TODO: We need to see if all savedTranslationUnit items were restored or not. + // Based on that we should inform
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Enable config ContentTranslationEnableSuggestions by default
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378673 ) Change subject: Enable config ContentTranslationEnableSuggestions by default .. Enable config ContentTranslationEnableSuggestions by default Change-Id: I8d710ec11baf7bfcbcfd8bdb50453ae554a96fd3 --- M extension.json 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/73/378673/1 diff --git a/extension.json b/extension.json index f459880..6c270d8 100644 --- a/extension.json +++ b/extension.json @@ -162,7 +162,7 @@ "key": "", "age": "3600" }, - "ContentTranslationEnableSuggestions": false, + "ContentTranslationEnableSuggestions": true, "@RecommendToolAPIURL": "Web API URL for translation recommendation tool", "RecommendToolAPIURL": "https://recommend.wmflabs.org/types/translation/v1/articles;, "ContentTranslationVersion": "1" -- To view, visit https://gerrit.wikimedia.org/r/378673 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8d710ec11baf7bfcbcfd8bdb50453ae554a96fd3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Save and publish: Avoid references to ApiVisualEditorEdit
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378668 ) Change subject: Save and publish: Avoid references to ApiVisualEditorEdit .. Save and publish: Avoid references to ApiVisualEditorEdit In 21486e0c tryDeflate method from ApiVisualEditorEdit. But CX1 does not declare a depedency to VE extension eventhough the same publish/save code is used by CX2. Referring ApiVisualEditorEdit may cause issues to our test or any other installation without VE extension. I created a copy of tryDeflate method in ApiContentTranslationPublish and used it for save and publish for now. Change-Id: Ie21b8710530b1c71026141aaca76f5086cfc3b67 --- M api/ApiContentTranslationPublish.php M api/ApiContentTranslationSave.php 2 files changed, 21 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/68/378668/1 diff --git a/api/ApiContentTranslationPublish.php b/api/ApiContentTranslationPublish.php index 9c6d0d4..8ff23a3 100644 --- a/api/ApiContentTranslationPublish.php +++ b/api/ApiContentTranslationPublish.php @@ -173,7 +173,7 @@ try { $wikitext = $this->restbaseClient->convertHtmlToWikitext( $targetTitle, - ApiVisualEditorEdit::tryDeflate( $params['html'] ) + self::tryDeflate( $params['html'] ) ); } catch ( MWException $e ) { if ( is_callable( [ $this, 'dieWithError' ] ) ) { @@ -264,6 +264,25 @@ } } + public static function tryDeflate( $content ) { + if ( substr( $content, 0, 11 ) === 'rawdeflate,' ) { + $deflated = base64_decode( substr( $content, 11 ) ); + MediaWiki\suppressWarnings(); + $inflated = gzinflate( $deflated ); + MediaWiki\restoreWarnings(); + if ( $deflated === $inflated || $inflated === false ) { + // Static equivalent of $this->dieWithError + throw ApiUsageException::newWithMessage( + null, + 'apierror-cx-invalidsectioncontent', + 'invalidcontent' + ); + } + return $inflated; + } + return $content; + } + public function getAllowedParams() { return [ 'title' => [ diff --git a/api/ApiContentTranslationSave.php b/api/ApiContentTranslationSave.php index 9924ff2..b02947e 100644 --- a/api/ApiContentTranslationSave.php +++ b/api/ApiContentTranslationSave.php @@ -46,7 +46,7 @@ $translationId = $translation->getTranslationId(); $translationUnits = $this->getTranslationUnits( - ApiVisualEditorEdit::tryDeflate( $params['content'] ), + ApiContentTranslationPublish::tryDeflate( $params['content'] ), $translationId ); $this->saveTranslationUnits( $translationUnits, $translation ); -- To view, visit https://gerrit.wikimedia.org/r/378668 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie21b8710530b1c71026141aaca76f5086cfc3b67 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Use the title description and image in CX link inspector
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378666 ) Change subject: Use the title description and image in CX link inspector .. Use the title description and image in CX link inspector Show the title image and desciption in the custom CX Link inspector. No attention to styling is given for now. Change-Id: I0e95ee2e36e053cd5295329421113670d09d0d80 --- M modules/ve-cx/ui/ve.ui.CXLinkContextItem.js M modules/ve-cx/ui/ve.ui.CXTranslationUnitContextItem.js 2 files changed, 57 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/66/378666/1 diff --git a/modules/ve-cx/ui/ve.ui.CXLinkContextItem.js b/modules/ve-cx/ui/ve.ui.CXLinkContextItem.js index d88152f..6e23ce3 100644 --- a/modules/ve-cx/ui/ve.ui.CXLinkContextItem.js +++ b/modules/ve-cx/ui/ve.ui.CXLinkContextItem.js @@ -9,12 +9,14 @@ // Parent constructor ve.ui.CXLinkContextItem.super.apply( this, arguments ); // Mixin constructor - ve.ui.CXTranslationUnitContextItem.apply( this ); + ve.ui.CXTranslationUnitContextItem.apply( this, arguments ); + this.$sourceBody = $( '' ) .addClass( 've-ui-linearContextItem-body' ) .addClass( 've-ui-cxLinkContextItem-sourceBody' ) .insertBefore( this.$body ); this.$element.addClass( 've-ui-cxLinkContextItem' ); + }; /* Inheritance */ @@ -37,38 +39,60 @@ */ ve.ui.CXLinkContextItem.prototype.renderBody = function () { var $sourceLink, $targetLink, - targetSurface = this.context.getSurface(), - translation = ve.init.target.getTranslation(), - unit = translation.getTranslationUnit( this.model.getTranslationUnitId() ), - sourceModel = unit.sourceModel; + adaptationInfo = this.model.element.attributes.cx; // Source link - $sourceLink = this.constructor.static.generateBody( - // TODO: this ought to be a linkCache pointing at the source wiki - ve.init.platform.linkCache, - sourceModel, - translation.sourceDoc.getHtmlDocument() - ); - // Target link - $targetLink = this.constructor.static.generateBody( - ve.init.platform.linkCache, - this.model, - targetSurface.getModel().getDocument().getHtmlDocument() - ); + $sourceLink = this.generateBody( adaptationInfo.sourceTitle ); + this.$sourceBody.empty().append( $sourceLink ); - function addLanguageDescription( $link, lang ) { - $link.find( '.ve-ui-mwInternalLinkContextItem-link' ).after( - $( '' ) - .addClass( 've-ui-mwInternalLinkContextItem-description' ) - .text( ve.init.platform.getLanguageAutonym( lang ) ) - ); + // Target link + if ( adaptationInfo.adapted ) { + $targetLink = this.generateBody( adaptationInfo.targetTitle ); + this.$body.empty().append( $targetLink ); + } +}; + +/** + * Generate the body of the link context item + * + * @param {Object} linkInfo The object with title meta data + * @return {jQuery} The jQuery object of the link context item + */ +ve.ui.CXLinkContextItem.prototype.generateBody = function ( linkInfo ) { + var panel, $linkTitle, $linkDesc, linkInfoPanel, + icon; + + $linkTitle = $( '' ) + .addClass( 'cx-tools-link-text' ) + .text( linkInfo.title ) + .prop( { + target: '_blank', + title: linkInfo.title, + href: this.translation.config.siteMapper.getPageUrl( linkInfo.pagelanguage, linkInfo.title ) + } ); + $linkDesc = $( '' ) + .addClass( 'cx-tools-link-desc' ) + .text( linkInfo.terms && linkInfo.terms.description || '' ); + linkInfoPanel = new OO.ui.PanelLayout( { + expanded: false, + framed: false, + padded: false, + classes: [ 'cx-tools-link-info' ], + content: [ $linkTitle, $linkDesc ] + } ); + icon = new OO.ui.IconWidget( { icon: 'page-existing' } ); + if ( linkInfo.thumbnail && linkInfo.thumbnail.source ) { + icon.$element.css( 'background-image', 'url(' + linkInfo.thumbnail.source + ')' ); } - addLanguageDescription( $sourceLink, translation.sourceDoc.getLang() ); - addLanguageDescription( $targetLink, translation.targetDoc.getLang() ); + panel = new OO.ui.HorizontalLayout( { + expanded: false, + framed: false, + padded: false, + items: [ icon, linkInfoPanel ] + } ); -
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: ve.dm.CXLinkAnnotation: Use the adaptation info supplied by ...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378659 ) Change subject: ve.dm.CXLinkAnnotation: Use the adaptation info supplied by cxserver .. ve.dm.CXLinkAnnotation: Use the adaptation info supplied by cxserver For now, just take the data-cx fom DOM and have it in model. In follow up commits, we will start using the adaptation data in inspectors. Change-Id: I57a62d51ddd5151fb5fc5800954760db299bbe04 --- M modules/ve-cx/dm/ve.dm.CXLinkAnnotation.js 1 file changed, 10 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/59/378659/1 diff --git a/modules/ve-cx/dm/ve.dm.CXLinkAnnotation.js b/modules/ve-cx/dm/ve.dm.CXLinkAnnotation.js index b36dde0..6e7df51 100644 --- a/modules/ve-cx/dm/ve.dm.CXLinkAnnotation.js +++ b/modules/ve-cx/dm/ve.dm.CXLinkAnnotation.js @@ -28,14 +28,23 @@ }; ve.dm.CXLinkAnnotation.static.toDataElement = function ( domElements, converter ) { - var dataElement = ve.dm.CXLinkAnnotation.super.static.toDataElement.call( this, domElements, converter ); + var dataCX, + dataElement = ve.dm.CXLinkAnnotation.super.static.toDataElement.call( this, domElements, converter ); dataElement.attributes.linkid = domElements[ 0 ].getAttribute( 'data-linkid' ); + + dataCX = domElements[ 0 ].getAttribute( 'data-cx' ); + if ( dataCX ) { + dataElement.attributes.cx = JSON.parse( domElements[ 0 ].getAttribute( 'data-cx' ) ); + } return dataElement; }; ve.dm.CXLinkAnnotation.static.toDomElements = function ( dataElement, doc ) { var domElements = ve.dm.CXLinkAnnotation.super.static.toDomElements.call( this, dataElement, doc ); domElements[ 0 ].setAttribute( 'data-linkid', dataElement.attributes.linkid ); + if ( dataElement.attributes.cx ) { + domElements[ 0 ].setAttribute( 'data-cx', JSON.stringify( dataElement.attributes.cx ) ); + } return domElements; }; -- To view, visit https://gerrit.wikimedia.org/r/378659 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I57a62d51ddd5151fb5fc5800954760db299bbe04 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: mw.cx.init.Translation: Pass the config to translation model
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378655 ) Change subject: mw.cx.init.Translation: Pass the config to translation model .. mw.cx.init.Translation: Pass the config to translation model Fix the missing argument to the Translation model instance Change-Id: I251aaf8055c0e10568d4c96612e3c9f5a8e615ff --- M modules/mw.cx.init.Translation.js 1 file changed, 2 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/55/378655/1 diff --git a/modules/mw.cx.init.Translation.js b/modules/mw.cx.init.Translation.js index 6c78230..08ed387 100644 --- a/modules/mw.cx.init.Translation.js +++ b/modules/mw.cx.init.Translation.js @@ -70,7 +70,8 @@ this.translationModel = new mw.cx.dm.Translation( this.sourceWikiPage, this.targetWikiPage, - sourcePageContent.segmentedContent + sourcePageContent.segmentedContent, + this.config ); // Initialize translation controller this.translationController = new mw.cx.TranslationController( -- To view, visit https://gerrit.wikimedia.org/r/378655 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I251aaf8055c0e10568d4c96612e3c9f5a8e615ff Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Show progress indicator after clicking on the placeholder se...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378224 ) Change subject: Show progress indicator after clicking on the placeholder section .. Show progress indicator after clicking on the placeholder section Change-Id: I01cbd9090c4ad1094ca1554631102d7ecaad143d --- M modules/ve-cx/ce/ve.ce.CXPlaceholderNode.js 1 file changed, 5 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/24/378224/1 diff --git a/modules/ve-cx/ce/ve.ce.CXPlaceholderNode.js b/modules/ve-cx/ce/ve.ce.CXPlaceholderNode.js index 88de981..aee26d6 100644 --- a/modules/ve-cx/ce/ve.ce.CXPlaceholderNode.js +++ b/modules/ve-cx/ce/ve.ce.CXPlaceholderNode.js @@ -48,9 +48,14 @@ ve.ce.CXPlaceholderNode.prototype.executeCommand = function () { this.active = true; + this.showProgressIndicator(); this.getDocument().emit( 'activatePlaceholder', this ); }; +ve.ce.CXPlaceholderNode.prototype.showProgressIndicator = function () { + this.$element.empty().append( mw.cx.widgets.spinner() ); +}; + ve.ce.CXPlaceholderNode.prototype.createHighlights = function () { }; -- To view, visit https://gerrit.wikimedia.org/r/378224 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I01cbd9090c4ad1094ca1554631102d7ecaad143d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Styling for the section placeholder
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378210 ) Change subject: Styling for the section placeholder .. Styling for the section placeholder Center the label 'Add translation'. Adjust color, font-size according to design Change-Id: Iaaa89b56bcde4d4da0307730221f3045ce124cfb --- M modules/ve-cx/ce/styles/ve.ce.CXPlaceholderNode.css 1 file changed, 10 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/10/378210/1 diff --git a/modules/ve-cx/ce/styles/ve.ce.CXPlaceholderNode.css b/modules/ve-cx/ce/styles/ve.ce.CXPlaceholderNode.css index 2910f68..d33f7ba 100644 --- a/modules/ve-cx/ce/styles/ve.ce.CXPlaceholderNode.css +++ b/modules/ve-cx/ce/styles/ve.ce.CXPlaceholderNode.css @@ -5,10 +5,16 @@ -webkit-transition: opacity 200ms ease-out; -moz-transition: opacity 200ms ease-out; transition: opacity 200ms ease-out; - - outline: 1px dashed #c8ccd1; - /* rgba( #f1f7fb, 0.75 ) */ - background-color: rgba( 241, 247, 251, 0.75 ); + font-size: 20px; + font-weight: lighter; + color: #72777d; + background-color: #f8f9fa; + /* In supported browsers, center the placeholder text */ + display: flex; + /* align horizontally */ + justify-content: center; + /* align vertically */ + align-items: center; } .ve-ce-cxPlaceholderNode:hover, -- To view, visit https://gerrit.wikimedia.org/r/378210 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaaa89b56bcde4d4da0307730221f3045ce124cfb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Fix the js error while loading a translation with saved tran...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378199 ) Change subject: Fix the js error while loading a translation with saved translation .. Fix the js error while loading a translation with saved translation This will not make the restore-translation feature working. Just prevents the js error that prevents loading the source article to translation view. Change-Id: I28fcd0b7885b333c5cfbce6946f3fe04133ce3f9 --- M modules/dm/mw.cx.dm.Translation.js M modules/mw.cx.TranslationController.js 2 files changed, 10 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/99/378199/1 diff --git a/modules/dm/mw.cx.dm.Translation.js b/modules/dm/mw.cx.dm.Translation.js index 36c9cbf..774b86f 100644 --- a/modules/dm/mw.cx.dm.Translation.js +++ b/modules/dm/mw.cx.dm.Translation.js @@ -281,6 +281,15 @@ return this.translationUnitById[ id ]; }; +/** + * Get a translation units + * + * @return {mw.cx.dm.TranslationUnit|undefined} The translation unit + */ +mw.cx.dm.Translation.prototype.getTranslationUnits = function () { + return this.topTranslationUnits; +}; + mw.cx.dm.Translation.prototype.getProgress = function () { return this.progress; }; diff --git a/modules/mw.cx.TranslationController.js b/modules/mw.cx.TranslationController.js index c5fb722..45e8023 100644 --- a/modules/mw.cx.TranslationController.js +++ b/modules/mw.cx.TranslationController.js @@ -292,7 +292,7 @@ this.translation.getTranslationUnits().forEach( function ( unit ) { var savedSection, provider, document, - sectionId = unit.getSectionId(); + sectionId = unit.getId(); if ( !savedUnits[ sectionId ] ) { return; -- To view, visit https://gerrit.wikimedia.org/r/378199 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I28fcd0b7885b333c5cfbce6946f3fe04133ce3f9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Refactor the API router to ES6 class
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377739 ) Change subject: Refactor the API router to ES6 class .. Refactor the API router to ES6 class In follow ups, we are trying to make the router a simple path to handler mapper and handlers in seperate files. This refactoring will help us to provide v2 of apis in future without much code duplication. Change-Id: I10009261b311c80fdea4c300199b73a44880cbe4 --- M lib/routes/v1.js 1 file changed, 281 insertions(+), 223 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/39/377739/1 diff --git a/lib/routes/v1.js b/lib/routes/v1.js index 77fb8d1..3f29352 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -1,274 +1,332 @@ 'use strict'; -var app, router, registry; +let registry; const sUtil = require( '../util' ), jwt = require( 'jsonwebtoken' ), CXConfig = require( '../Config.js' ); -/** - * The main router object - */ -router = sUtil.router(); +class Routes { + constructor( app, registry ) { + this.app = app; + this.registry = registry; + this.router = sUtil.router(); + if ( !this.app ) { throw new Error( 'Missing app property' ); } + this.registerRoutes(); + } -router.get( '/page/:language/:title/:revision?', function ( req, res ) { - var sourceLanguage = req.params.language, - title = req.params.title, - revision = req.params.revision, - CXSegmenter = require( __dirname + '/../segmentation/CXSegmenter.js' ), - PageLoader = require( __dirname + '/../pageloader/PageLoader.js' ), - pageloader = new PageLoader( app ); + /** +* routes definitions +*/ + get routes() { + return { + '/page/:language/:title/:revision?': this.fetchPage.bind( this ), + 'POST /mt/:from/:to/:provider?': this.machineTranslate.bind( this ), + '/dictionary/:word/:from/:to/:provider?': this.dictionary.bind( this ), + '/list/tool/:tool': this.listTool.bind( this ), + '/list/pair/:from/:to': this.listToolForLanguagePair.bind( this ), + '/list/languagepairs': this.listLanguagePairs.bind( this ), + '/list/:tool/:from?/:to?': this.listToolForLanguagePairsAndTool.bind( this ), + 'POST /translate/:from/:to/:provider?': this.translate.bind( this ) + }; + } - return pageloader.load( title, sourceLanguage, revision ).then( - function ( response ) { - var segmenter, segmentedContent; + /** +* It goes through each route defition, figures out the verb/action to use +* (default: get), the function to call to handle the request and registers +* the whole for the given path. +*/ + registerRoutes() { + var routes = this.routes; + + Object.keys( routes ).forEach( ( path ) => { + let parts = path.split( ' ' ); + let verb = parts[ 1 ] ? parts[ 0 ] : 'get'; + path = parts[ 1 ] || parts[ 0 ]; + verb = verb.toLowerCase(); + this.router[ verb ]( path, routes[ path ] ); + } ); + } + + fetchPage( req, res ) { + var sourceLanguage = req.params.language, + title = req.params.title, + revision = req.params.revision, + CXSegmenter = require( __dirname + '/../segmentation/CXSegmenter.js' ), + PageLoader = require( __dirname + '/../pageloader/PageLoader.js' ), + pageloader = new PageLoader( this.app ); + + return pageloader.load( title, sourceLanguage, revision ).then( + function ( response ) { + var segmenter, segmentedContent; + + try { + this.app.logger.log( 'debug', 'Fetch page', { + title: title, + sourceLanguage: sourceLanguage + } ); + segmenter = new CXSegmenter( response.body, sourceLanguage ); + segmenter.segment(); + segmentedContent = segmenter.getSegmentedContent(); + this.app.logger.log( 'debug', 'Segment page', { + title: title, + sourceLanguage:
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: CX1 MT: Unwrap the MT output if wrapped by legacy cxserver api
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377707 ) Change subject: CX1 MT: Unwrap the MT output if wrapped by legacy cxserver api .. CX1 MT: Unwrap the MT output if wrapped by legacy cxserver api cxserver /mt api won't wrap the output in unwanted tag since https://gerrit.wikimedia.org/r/#/c/374520/ Make the unwrapping conditional by checking the root tag of the MT output recieved. Change-Id: I014ced5bc306654053cf47c8cdfe4384ce90bdfb --- M modules/tools/ext.cx.tools.mt.js 1 file changed, 13 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/07/377707/1 diff --git a/modules/tools/ext.cx.tools.mt.js b/modules/tools/ext.cx.tools.mt.js index 44eacee..03449fc 100644 --- a/modules/tools/ext.cx.tools.mt.js +++ b/modules/tools/ext.cx.tools.mt.js @@ -346,19 +346,24 @@ } else { this.getTranslatedSection( this.$sourceSection ) .done( function ( translation ) { + var $translation; if ( !translation || !translation.length ) { return self.useSource(); } + $translation = $( translation ); + if ( $translation.is( 'div' ) && !self.$sourceSection.is( 'div' ) ) { + // Translation is wrapped in tag. Legacy cxserver behavior. Unwrap it. + $translation = $translation.children(); + } + $translation.attr( { + id: 'cx' + self.sourceId, + 'data-source': self.sourceId, + 'data-cx-state': 'mt', + 'data-cx-mt-provider': self.provider + } ); // Use fresh copy - self.replaceSectionWith( $( translation ) - .children() - .attr( { - id: 'cx' + self.sourceId, - 'data-source': self.sourceId, - 'data-cx-state': 'mt', - 'data-cx-mt-provider': self.provider - } ) ); + self.replaceSectionWith( $translation ); } ).fail( function () { return self.useSource(); } ).always( function () { -- To view, visit https://gerrit.wikimedia.org/r/377707 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I014ced5bc306654053cf47c8cdfe4384ce90bdfb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: ApiRequest title normalisation: Use getPrefixedText from med...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377401 ) Change subject: ApiRequest title normalisation: Use getPrefixedText from mediawiki-title .. ApiRequest title normalisation: Use getPrefixedText from mediawiki-title Update mediawiki-title to 0.6.4 Change-Id: I5ff530e241737df9442d4416438e759971adf27f --- M lib/mw/ApiRequest.js M package.json 2 files changed, 3 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/01/377401/1 diff --git a/lib/mw/ApiRequest.js b/lib/mw/ApiRequest.js index d8aab41..d540cad 100644 --- a/lib/mw/ApiRequest.js +++ b/lib/mw/ApiRequest.js @@ -191,8 +191,8 @@ if ( !titleObj ) { return title; } - // API wants spaces instead of underscores - return titleObj.getPrefixedDBKey().replace( /_/g, ' ' ); + // API wants titles without underscores. + return titleObj.getPrefixedText(); } ); MWApiRequest.siteInfoCache = new Map(); diff --git a/package.json b/package.json index 8ae0528..970f80f 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "js-yaml": "^3.6.1", "jsonwebtoken": "~5.6.0", "language-data": "git+https://github.com/wikimedia/language-data#master;, -"mediawiki-title": "^0.6.3", +"mediawiki-title": "^0.6.4", "preq": "^0.5.2", "sax": "1.2.1", "service-runner": "^2.2.5", -- To view, visit https://gerrit.wikimedia.org/r/377401 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5ff530e241737df9442d4416438e759971adf27f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MT Sanitize: Add resource, src, srcset as whiteisted attributes
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374941 ) Change subject: MT Sanitize: Add resource, src, srcset as whiteisted attributes .. MT Sanitize: Add resource, src, srcset as whiteisted attributes Missing these attributes from MT output was causing Image adaptation fail. Change-Id: I8c776553eed73545afd8f67887d976b671e5b628 --- M lib/mt/MTClient.js 1 file changed, 2 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/41/374941/1 diff --git a/lib/mt/MTClient.js b/lib/mt/MTClient.js index 242c9c2..755283d 100644 --- a/lib/mt/MTClient.js +++ b/lib/mt/MTClient.js @@ -106,7 +106,8 @@ } return this.DOMPurify.sanitize( html, { - ADD_ATTR: [ 'typeof' ], // typeof is not a known attribute for DOMPurify + // These are not known attributes for DOMPurify + ADD_ATTR: [ 'typeof', 'resource', 'src', 'srcset' ], ADD_URI_SAFE_ATTR: [ 'rel', 'typeof' ] // Without this rel="mw:WikiLink" attributes will be removed. } ); } -- To view, visit https://gerrit.wikimedia.org/r/374941 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8c776553eed73545afd8f67887d976b671e5b628 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Reference: Remove wrapping of reference body
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374526 ) Change subject: Reference: Remove wrapping of reference body .. Reference: Remove wrapping of reference body Change-Id: I5c1e60176b54095773c429c8e47c9c923552e2a1 --- M lib/translationunits/MWReference.js 1 file changed, 2 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/26/374526/1 diff --git a/lib/translationunits/MWReference.js b/lib/translationunits/MWReference.js index ff0294c..d7d7b9c 100644 --- a/lib/translationunits/MWReference.js +++ b/lib/translationunits/MWReference.js @@ -14,7 +14,7 @@ class MWReference extends TranslationUnit {} MWReference.prototype.adapt = cxutil.async( function* () { - let refData, refBody, wrappedRefBody, translatedRefBody, unwrappedTranslatedRefBody; + let refData, refBody, translatedRefBody, unwrappedTranslatedRefBody; // TODO: This format is not decided yet. We do need to inform client about failed // adaptations somehow. @@ -41,12 +41,10 @@ return this.node; } - // MTClient only accepts content wrapped in block element tags in HTML mode. - wrappedRefBody = '' + refBody + ''; // TODO: Parse recursively instead of just MTing to handle templates // Translate reference contents translatedRefBody = yield this.context.conf.mtClient.translate( - this.sourceLanguage, this.targetLanguage, wrappedRefBody + this.sourceLanguage, this.targetLanguage, refBody ); unwrappedTranslatedRefBody = translatedRefBody.replace( /^(.*)<\/div>$/, '$1' ); -- To view, visit https://gerrit.wikimedia.org/r/374526 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c1e60176b54095773c429c8e47c9c923552e2a1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: MT: Abstract the wrapping of content from API usage
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374520 ) Change subject: MT: Abstract the wrapping of content from API usage .. MT: Abstract the wrapping of content from API usage MTClient does a quick check whether the content is plaintext, if so, translateText is used. Otherwise proceeds to translateHTML, but the sourceDoc building step checks if we were able to build one. Without a wrapper tag, the sourceDoc will be empty. At that point we will re-attempt parsing with wrapper tag. For the result of this wrapped input, unwrap it after MT is recieved. The annoying wrapper for plain text input will not occur now. Change-Id: If7d93a1f268d87b6980e022b107608cb6af8e559 --- M lib/mt/MTClient.js M lib/routes/v1.js M spec.yaml 3 files changed, 15 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/20/374520/1 diff --git a/lib/mt/MTClient.js b/lib/mt/MTClient.js index 242c9c2..90b5e44 100644 --- a/lib/mt/MTClient.js +++ b/lib/mt/MTClient.js @@ -3,6 +3,7 @@ const LinearDoc = require( __dirname + '/../lineardoc' ), SubSequenceMatcher = require( './annotationmapper/SubsequenceMatcher.js' ), createDOMPurify = require( 'dompurify' ), + cxUtil = require( '../util.js' ), jsdom = require( 'jsdom' ); /** @@ -17,6 +18,7 @@ this.conf = options.conf; this.sourceDoc = null; this.sourceHTML = null; + this.contentWrapped = false; } log( level, info ) { @@ -35,7 +37,7 @@ * @return {Object} Deferred promise: Target language text */ translate( sourceLang, targetLang, content, format ) { - if ( format === 'text' ) { + if ( format === 'text' || cxUtil.isPlainText( content ) ) { return this.translateText( sourceLang, targetLang, content ); } else { return this.translateHtml( sourceLang, targetLang, content ); @@ -85,8 +87,12 @@ return Promise.all( chain ).then( ( results ) => { targetDoc.items = results; + if ( this.contentWrapped ) { + // Unwrap + targetDoc = targetDoc.items[ 1 ].item; + } // Return sanitized HTML output - return this.sanitize( targetDoc.getHtml() ); + { return this.sanitize( targetDoc.getHtml() ); } } ); } @@ -359,6 +365,11 @@ parser.write( sourceHtml ); this.sourceHTML = sourceHtml; this.sourceDoc = parser.builder.doc; + if ( !this.sourceDoc || !this.sourceDoc.items.length ) { + this.log( 'debug', 'Could not build a source doc. May be plain text? Re-attempting with wrapper' ); + this.contentWrapped = true; + this.buildSourceDoc( [ '', sourceHtml, '' ].join( '' ) ); + } } /** diff --git a/lib/routes/v1.js b/lib/routes/v1.js index d976697..715e59e 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -112,7 +112,7 @@ // We support setting html as body or as body.html. But body.html is the recommended way. // The other way will be removed soon. - sourceHtml = [ '', req.body.html || req.rawBody, '' ].join( '' ); + sourceHtml = req.body.html || req.rawBody; return mtClient.translate( from, to, sourceHtml ).then( function ( data ) { res.json( { diff --git a/spec.yaml b/spec.yaml index df2f066..0e27708 100644 --- a/spec.yaml +++ b/spec.yaml @@ -182,7 +182,7 @@ - Matxin - name: html in: formData - description: The HTML content to translate + description: The HTML or plaintext content to translate type: string required: true x-textarea: true -- To view, visit https://gerrit.wikimedia.org/r/374520 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If7d93a1f268d87b6980e022b107608cb6af8e559 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Move the plaintext or html check to utility method
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374519 ) Change subject: Move the plaintext or html check to utility method .. Move the plaintext or html check to utility method Change-Id: Iea3a278f9959ba313bfa071c4aa9bbad20c9366b --- M lib/mw/ApiRequest.js M lib/util.js 2 files changed, 6 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/19/374519/1 diff --git a/lib/mw/ApiRequest.js b/lib/mw/ApiRequest.js index 7175157..efaecb6 100644 --- a/lib/mw/ApiRequest.js +++ b/lib/mw/ApiRequest.js @@ -130,7 +130,7 @@ htmlToWikiText( html, language ) { var restReq, path, domain = this.getDomain( language ); - if ( !html || !html.trim() || !/<[a-zA-Z][\s\S]*>/i.test( html ) ) { + if ( cxUtil.isPlainText( html ) ) { // Does not contain HTML elements. Save api call. return Promise.resolve( html ); } diff --git a/lib/util.js b/lib/util.js index 9292fcf..d9b8fcc 100644 --- a/lib/util.js +++ b/lib/util.js @@ -321,12 +321,17 @@ this.catch = this.promise.catch.bind( this.promise ); } +function isPlainText( content ) { + return !content || !content.trim() || !/<[a-zA-Z][\s\S]*>/i.test( content ); +} + module.exports = { HTTPError, initAndLogRequest, wrapRouteHandlers, setErrorHandler, router: createRouter, + isPlainText, spawn, async, Deferred -- To view, visit https://gerrit.wikimedia.org/r/374519 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iea3a278f9959ba313bfa071c4aa9bbad20c9366b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: bin/linearize: Accept input content from stdin
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374517 ) Change subject: bin/linearize: Accept input content from stdin .. bin/linearize: Accept input content from stdin Change-Id: I673cef98ab40d01bad63f83503833351d64636fd --- M bin/linearize 1 file changed, 7 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/17/374517/1 diff --git a/bin/linearize b/bin/linearize index 76cc2b0..5dc027c 100755 --- a/bin/linearize +++ b/bin/linearize @@ -1,19 +1,19 @@ #!/usr/bin/env node -var script, xhtmlSource, xhtml, parser, +var script, xhtml, parser, fs = require( 'fs' ), LinearDoc = require( __dirname + '/../lib/lineardoc' ); -script = process.argv[ 1 ]; -if ( process.argv.length !== 3 ) { +xhtml = fs.readFileSync( '/dev/stdin', 'utf8' ); +if ( xhtml.trim() === '' ) { + script = process.argv[ 1 ]; process.stderr.write( - 'Usage: node ' + script + ' xhtmlSource\n' + - 'xhtml must be wrapped in a block element such as ... or ...\n' + 'Usage: node ' + script + ' < file\n' + + 'Input must be wrapped in a block element such as ... or ...\n' ); process.exit( 1 ); + } -xhtmlSource = process.argv[ 2 ]; -xhtml = fs.readFileSync( xhtmlSource, 'utf8' ); parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); parser.init(); parser.write( xhtml ); -- To view, visit https://gerrit.wikimedia.org/r/374517 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I673cef98ab40d01bad63f83503833351d64636fd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: bin/apertium-xhtml: Unbreak the Apertium path
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374518 ) Change subject: bin/apertium-xhtml: Unbreak the Apertium path .. bin/apertium-xhtml: Unbreak the Apertium path Change-Id: Id568fc79d9f33abce9f30d9c18b2e97af30f044a --- M bin/apertium-xhtml 1 file changed, 5 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/18/374518/1 diff --git a/bin/apertium-xhtml b/bin/apertium-xhtml index 56ec7f4..61cde1a 100755 --- a/bin/apertium-xhtml +++ b/bin/apertium-xhtml @@ -2,7 +2,7 @@ var sourceLang, targetLang, sourceHtml, script, args, config, cxConfig, fs = require( 'fs' ), yaml = require( 'js-yaml' ), - Apertium = require( __dirname + '/../mt/Apertium.js' ); + Apertium = require( __dirname + '/../lib/mt/Apertium.js' ); config = yaml.load( fs.readFileSync( 'config.yaml' ) ); if ( !config ) { @@ -34,17 +34,17 @@ sourceHtml = []; -process.stdin.on( 'data', function( data ) { +process.stdin.on( 'data', function ( data ) { sourceHtml.push( data ); } ); -process.stdin.on( 'end', function() { +process.stdin.on( 'end', function () { new Apertium( cxConfig ).translate( sourceLang, targetLang, sourceHtml.join( '' ) - ).then( function( targetHtml ) { + ).then( function ( targetHtml ) { process.stdout.write( targetHtml + '\n' ); - } ).catch( function( error ) { + } ).catch( function ( error ) { if ( error.stack ) { console.error( 'error', error.stack ); } else { -- To view, visit https://gerrit.wikimedia.org/r/374518 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id568fc79d9f33abce9f30d9c18b2e97af30f044a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Remove /languagepairs in favour of /list/languagepairs
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374508 ) Change subject: Remove /languagepairs in favour of /list/languagepairs .. Remove /languagepairs in favour of /list/languagepairs Bug: T162576 Change-Id: I927ae8119eab0245f523fb3266347ac22badaa4f --- M lib/routes/v1.js M spec.yaml 2 files changed, 0 insertions(+), 22 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/08/374508/1 diff --git a/lib/routes/v1.js b/lib/routes/v1.js index d976697..daa255e 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -194,14 +194,6 @@ /** * Get a list of all language pairs. */ -router.get( '/languagepairs', function ( req, res ) { - registry = require( __dirname + '/../registry' )( app ); - res.json( registry.getLanguagePairs() ); -} ); - -/** - * Get a list of all language pairs. - */ router.get( '/list/languagepairs', function ( req, res ) { registry = require( __dirname + '/../registry' )( app ); res.json( registry.getLanguagePairs() ); diff --git a/spec.yaml b/spec.yaml index df2f066..fcbe8cb 100644 --- a/spec.yaml +++ b/spec.yaml @@ -355,20 +355,6 @@ status: 200 headers: content-type: application/json - /v1/languagepairs: -get: - tags: -- Languages -- Service information - description: Lists the language pairs supported by the server - produces: -- application/json - x-amples: -- title: Get all the language pairs - response: -status: 200 -headers: - content-type: application/json # from routes/info.js /_info: get: -- To view, visit https://gerrit.wikimedia.org/r/374508 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I927ae8119eab0245f523fb3266347ac22badaa4f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Source selector: Use /list/languagepairs api of cxserver
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374506 ) Change subject: Source selector: Use /list/languagepairs api of cxserver .. Source selector: Use /list/languagepairs api of cxserver /languagepairs is now under /list Bug: T162576 Change-Id: I1e4b49bce82163e7a0a9c629f156e46aef90152e --- M modules/source/ext.cx.source.selector.js 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/06/374506/1 diff --git a/modules/source/ext.cx.source.selector.js b/modules/source/ext.cx.source.selector.js index f500149..0145240 100644 --- a/modules/source/ext.cx.source.selector.js +++ b/modules/source/ext.cx.source.selector.js @@ -154,7 +154,7 @@ var languagePairsAPIUrl, cxSourceSelector = this; - languagePairsAPIUrl = this.siteMapper.getCXServerUrl( '/languagepairs' ); + languagePairsAPIUrl = this.siteMapper.getCXServerUrl( '/list/languagepairs' ); return $.get( languagePairsAPIUrl ) .done( function ( response ) { -- To view, visit https://gerrit.wikimedia.org/r/374506 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1e4b49bce82163e7a0a9c629f156e46aef90152e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Avoid hardcoding wikipedia.org domain for APIs
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374493 ) Change subject: Avoid hardcoding wikipedia.org domain for APIs .. Avoid hardcoding wikipedia.org domain for APIs Make the host configurable. Defaults to {lang}.wikipedia.org Bug: T172075 Change-Id: I8196b70280a9d2b756c1a4b2e877288d79ce3fa7 --- M config.dev.yaml M config.prod.yaml M lib/mw/ApiRequest.js M lib/pageloader/PageLoader.js 4 files changed, 12 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/93/374493/1 diff --git a/config.dev.yaml b/config.dev.yaml index be6c6b2..994 100644 --- a/config.dev.yaml +++ b/config.dev.yaml @@ -48,6 +48,10 @@ # - domain1.com # - domain2.org user_agent: cxserver + # Mediawiki host name. Example {lang}.wikisource.org which get expanded internaly to + # es.wikisource.org in a spanish language context. + # Do not prefix with http or https:// + # mw_host: '{lang}.wikipedia.org' mwapi_req: body: "{{request.body}}" query: "{{ default(request.query, {}) }}" diff --git a/config.prod.yaml b/config.prod.yaml index 9a3f876..19b2d5f 100644 --- a/config.prod.yaml +++ b/config.prod.yaml @@ -48,6 +48,10 @@ # - domain1.com # - domain2.org user_agent: cxserver + # Mediawiki host name. Example {lang}.wikisource.org which get expanded internaly to + # es.wikisource.org in a spanish language context. + # Do not prefix with http or https:// + # mw_host: '{lang}.wikipedia.org' mwapi_req: body: "{{request.body}}" query: "{{ default(request.query, {}) }}" diff --git a/lib/mw/ApiRequest.js b/lib/mw/ApiRequest.js index 7175157..fcd42d9 100644 --- a/lib/mw/ApiRequest.js +++ b/lib/mw/ApiRequest.js @@ -90,7 +90,7 @@ } getDomain( language ) { - return this.getSiteCode( language ) + '.wikipedia.org'; + return ( this.context.conf.mw_host || '{lang}.wikipedia.org' ).replace( '{lang}', language ); } /** diff --git a/lib/pageloader/PageLoader.js b/lib/pageloader/PageLoader.js index dde851a..a5c8f35 100644 --- a/lib/pageloader/PageLoader.js +++ b/lib/pageloader/PageLoader.js @@ -1,7 +1,7 @@ 'use strict'; -var apiUtil = require( '../api-util' ); - +const apiUtil = require( '../api-util' ); +const ApiRequest = require( '../mw/ApiRequest.js' ); /** * Cheap body extraction. * @@ -43,7 +43,7 @@ domain = source; } else { // Assume the client means a WP project - domain = source + '.wikipedia.org'; + domain = new ApiRequest( { context: this.app } ).getDomain( source ); } if ( revision ) { -- To view, visit https://gerrit.wikimedia.org/r/374493 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8196b70280a9d2b756c1a4b2e877288d79ce3fa7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Tests: Group the segmentation tests per language
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374452 ) Change subject: Tests: Group the segmentation tests per language .. Tests: Group the segmentation tests per language Segmentation tests were not grouped. Change-Id: I6668d91bf57224047d8feaf89f658a1fbd2f8128 --- M test/segmentation/CXSegmenter.test.js 1 file changed, 21 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/52/374452/1 diff --git a/test/segmentation/CXSegmenter.test.js b/test/segmentation/CXSegmenter.test.js index 8df4c04..8cc612c 100644 --- a/test/segmentation/CXSegmenter.test.js +++ b/test/segmentation/CXSegmenter.test.js @@ -1,7 +1,6 @@ 'use strict'; -var fs = require( 'fs' ), - lang, i, len, lang, test, tests, +const fs = require( 'fs' ), assert = require( '../utils/assert.js' ), LinearDoc = require( '../../lib/lineardoc' ), Segmenter = require( '../../lib/segmentation/CXSegmenter' ), @@ -14,32 +13,29 @@ return normalizer.getHtml(); } -function runTest( test ) { - var segmenter, result, testData, expectedResultData; +function runTest( test, lang ) { + let testData = fs.readFileSync( __dirname + '/data/' + test.source, 'utf8' ); - describe( 'Segmentation tests', function () { - testData = fs.readFileSync( __dirname + '/data/' + test.source, 'utf8' ); - - segmenter = new Segmenter( testData, lang ); - segmenter.segment(); - result = normalize( segmenter.getSegmentedContent() ); - expectedResultData = normalize( - fs.readFileSync( __dirname + '/data/' + test.result, 'utf8' ) - ); - it( 'should not have any errors when: ' + test.desc, function () { - assert.deepEqual( result, expectedResultData, test.source + ': ' + test.desc || '' ); - } ); + let segmenter = new Segmenter( testData, lang ); + segmenter.segment(); + let result = normalize( segmenter.getSegmentedContent() ); + let expectedResultData = normalize( + fs.readFileSync( __dirname + '/data/' + test.result, 'utf8' ) + ); + it( 'should not have any errors when: ' + test.desc, () => { + assert.deepEqual( result, expectedResultData, test.source + ': ' + test.desc || '' ); } ); } -for ( lang in allTests ) { - tests = allTests[ lang ]; - len = tests.length; - for ( i = 0; i < len; i++ ) { - test = tests[ i ]; - if ( test.skip ) { - continue; +for ( let lang in allTests ) { + describe( 'Segmentation tests for ' + lang, () => { + let tests = allTests[ lang ]; + let len = tests.length; + for ( let i = 0; i < len; i++ ) { + if ( tests[ i ].skip ) { + continue; + } + runTest( tests[ i ], lang ); } - runTest( test ); - } + } ); } -- To view, visit https://gerrit.wikimedia.org/r/374452 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6668d91bf57224047d8feaf89f658a1fbd2f8128 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Update Adapter to use Class semantics
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374229 ) Change subject: Update Adapter to use Class semantics .. Update Adapter to use Class semantics Change-Id: I9b04d57cee0942308b93a9232a5fa38d90578690 --- M lib/Adapter.js 1 file changed, 48 insertions(+), 46 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/29/374229/1 diff --git a/lib/Adapter.js b/lib/Adapter.js index 8b9f0f2..d7aa71d 100644 --- a/lib/Adapter.js +++ b/lib/Adapter.js @@ -1,52 +1,54 @@ 'use strict'; -var LinearDoc = require( './lineardoc' ); +const LinearDoc = require( './lineardoc' ); -function Adapter( sourceLanguage, targetLanguage, context ) { - this.parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); - this.parser.init(); - this.sourceLanguage = sourceLanguage; - this.targetLanguage = targetLanguage; - this.originalDoc = null; - this.adaptedDoc = null; - this.context = context; - this.logger = context.logger; +class Adapter { + constructor( sourceLanguage, targetLanguage, context ) { + this.parser = new LinearDoc.Parser( new LinearDoc.MwContextualizer() ); + this.parser.init(); + this.sourceLanguage = sourceLanguage; + this.targetLanguage = targetLanguage; + this.originalDoc = null; + this.adaptedDoc = null; + this.context = context; + this.logger = context.logger; + } + + adapt( content ) { + this.parser.write( content ); + this.originalDoc = this.parser.builder.doc; + return this.originalDoc.adapt( this.getAdapter.bind( this ) ); + } + + /** +* Get the adapter for the given tag(translation unit). +* @param {Object} element +* @return {TranslationUnit} +*/ + getAdapter( element ) { + let name, match = false, + translationUnits = require( __dirname + '/translationunits/' ); + + for ( name in translationUnits ) { + let translationUnit = translationUnits[ name ]; + if ( translationUnit.matchTagNames ) { + match = translationUnit.matchTagNames.includes( element.name ); + } + if ( translationUnit.matchRdfaTypes ) { + match = translationUnit.matchRdfaTypes.includes( element.attributes.rel ) || translationUnit.matchRdfaTypes.includes( element.attributes.typeof ); + } + if ( match ) { + break; + } + } + + if ( !match ) { + // this.logger.log( 'debug', 'No adapter for ' + element.name ); + return null; + } + + return new translationUnits[ name ]( element, this.sourceLanguage, this.targetLanguage, this.context ); + } } - -Adapter.prototype.adapt = function ( content ) { - this.parser.write( content ); - this.originalDoc = this.parser.builder.doc; - return this.originalDoc.adapt( this.getAdapter.bind( this ) ); -}; - -/** - * Get the adapter for the given tag(translation unit). - * @param {Object} element - * @return {TranslationUnit} - */ -Adapter.prototype.getAdapter = function ( element ) { - var name, match = false, translationUnit, translationUnits; - - translationUnits = require( __dirname + '/translationunits/' ); - for ( name in translationUnits ) { - translationUnit = translationUnits[ name ]; - if ( translationUnit.matchTagNames ) { - match = translationUnit.matchTagNames.includes( element.name ); - } - if ( translationUnit.matchRdfaTypes ) { - match = translationUnit.matchRdfaTypes.includes( element.attributes.rel ) || translationUnit.matchRdfaTypes.includes( element.attributes.typeof ); - } - if ( match ) { - break; - } - } - - if ( !match ) { - // this.logger.log( 'debug', 'No adapter for ' + element.name ); - return null; - } - - return new translationUnits[ name ]( element, this.sourceLanguage, this.targetLanguage, this.context ); -}; module.exports = Adapter; -- To view, visit https://gerrit.wikimedia.org/r/374229 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b04d57cee0942308b93a9232a5fa38d90578690 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: eslint: one-var configuration- Allow const and let not grouped
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374222 ) Change subject: eslint: one-var configuration- Allow const and let not grouped .. eslint: one-var configuration- Allow const and let not grouped Change-Id: Ia2c97966e70ad803e30dee4b7253ca3bce9dcb06 --- M .eslintrc.json 1 file changed, 2 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/22/374222/1 diff --git a/.eslintrc.json b/.eslintrc.json index 9f49bb6..efcda8c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,6 +16,7 @@ }, "rules": { "dot-notation": 0, - "wrap-iife": 0 + "wrap-iife": 0, + "one-var": ["error", {"var": "always"}] } } -- To view, visit https://gerrit.wikimedia.org/r/374222 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia2c97966e70ad803e30dee4b7253ca3bce9dcb06 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Update Contextualizer to use Class semantics
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374223 ) Change subject: Update Contextualizer to use Class semantics .. Update Contextualizer to use Class semantics Change-Id: I547030a9b6363110cae960e10991639a6db06404 --- M lib/lineardoc/Contextualizer.js M lib/lineardoc/MwContextualizer.js 2 files changed, 97 insertions(+), 103 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/23/374223/1 diff --git a/lib/lineardoc/Contextualizer.js b/lib/lineardoc/Contextualizer.js index b3d506c..f9d361c 100644 --- a/lib/lineardoc/Contextualizer.js +++ b/lib/lineardoc/Contextualizer.js @@ -2,70 +2,70 @@ /** * Contextualizer for HTML - tracks the segmentation context of the currently open node - * @class - * @constructor */ -function Contextualizer() { - this.contexts = []; -} +class Contextualizer { + constructor() { + this.contexts = []; + } -/** - * Get the context for a new tag being opened - * - * @param {Object} openTag - * @param {string} openTag.name HTML tag name - * @param {Object} openTag.attributes HTML attributes as a string map - * @return {string|undefined} The new context - */ -Contextualizer.prototype.getChildContext = function ( openTag ) { + /** +* Get the context for a new tag being opened +* +* @param {Object} openTag +* @param {string} openTag.name HTML tag name +* @param {Object} openTag.attributes HTML attributes as a string map +* @return {string|undefined} The new context +*/ + getChildContext( openTag ) { // Change to 'media' context inside figure - if ( openTag.name === 'figure' ) { - return 'media'; + if ( openTag.name === 'figure' ) { + return 'media'; + } + + // Exception: return to undefined context inside figure//figcaption + if ( openTag.name === 'figcaption' ) { + return undefined; + } + + // No change: same as parent context + return this.getContext(); } - // Exception: return to undefined context inside figure//figcaption - if ( openTag.name === 'figcaption' ) { - return undefined; + /** +* Get the current context +* +* @return {string|undefined} The current context +*/ + getContext() { + return this.contexts[ this.contexts.length - 1 ]; } - // No change: same as parent context - return this.getContext(); -}; + /** +* Call when a tag opens +* +* @param {Object} openTag +* @param {string} openTag.name HTML tag name +* @param {Object} openTag.attributes HTML attributes as a string map +*/ + onOpenTag( openTag ) { + this.contexts.push( this.getChildContext( openTag ) ); + } -/** - * Get the current context - * - * @return {string|undefined} The current context - */ -Contextualizer.prototype.getContext = function () { - return this.contexts[ this.contexts.length - 1 ]; -}; + /** +* Call when a tag closes (or just after an empty tag opens) +*/ + onCloseTag() { + this.contexts.pop(); + } -/** - * Call when a tag opens - * - * @param {Object} openTag - * @param {string} openTag.name HTML tag name - * @param {Object} openTag.attributes HTML attributes as a string map - */ -Contextualizer.prototype.onOpenTag = function ( openTag ) { - this.contexts.push( this.getChildContext( openTag ) ); -}; + /** +* Determine whether sentences can be segmented into spans in this context +* +* @return {boolean} Whether sentences can be segmented into spans in this context +*/ + canSegment() { + return this.getContext() === undefined; + } -/** - * Call when a tag closes (or just after an empty tag opens) - */ -Contextualizer.prototype.onCloseTag = function () { - this.contexts.pop(); -}; - -/** - * Determine whether sentences can be segmented into spans in this context - * - * @return {boolean} Whether sentences can be segmented into spans in this context - */ -Contextualizer.prototype.canSegment = function () { - return this.getContext() === undefined; -}; - +} module.exports = Contextualizer; diff --git a/lib/lineardoc/MwContextualizer.js b/lib/lineardoc/MwContextualizer.js index 981225f..c5d3742 100644 --- a/lib/lineardoc/MwContextualizer.js +++ b/lib/lineardoc/MwContextualizer.js @@ -1,10 +1,7 @@ 'use strict'; -var contentBranchNodeNames, - util = require( 'util' ), - Contextualizer = require( './Contextualizer' ); - -contentBranchNodeNames = [ 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre' ]; +const
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Fix the issue of no adaptation if MT provider is not specified
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373435 ) Change subject: Fix the issue of no adaptation if MT provider is not specified .. Fix the issue of no adaptation if MT provider is not specified Adaptation should proceed if no MT provider is specificed. It should fail if provider is given, but fails the validation against the language pair and authentication token. Change-Id: Iad82cd4e9da4e06db1f31a98fd9fac140342529b --- M lib/routes/v1.js 1 file changed, 7 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/35/373435/1 diff --git a/lib/routes/v1.js b/lib/routes/v1.js index 6a43dfc..2f561d6 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -234,7 +234,13 @@ from = req.params.from, to = req.params.to; - mtClient = getMTClient( req, res ); + if ( req.params.provider ) { + mtClient = getMTClient( req, res ); + if ( !mtClient ) { + // With explicit provider, if not MT Client found, it is an error. + return; + } + } sourceHtml = req.body.html; -- To view, visit https://gerrit.wikimedia.org/r/373435 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad82cd4e9da4e06db1f31a98fd9fac140342529b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Unit tests for MWLink translation unit class
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373279 ) Change subject: Unit tests for MWLink translation unit class .. Unit tests for MWLink translation unit class Change-Id: I25ffb50cf7c27ca1f5cf71176d31465fde470db0 --- M lib/translationunits/MWLink.js M test/index.js A test/translationunits/MWLink.test.js A test/translationunits/MWLink.test.json 4 files changed, 313 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/79/373279/1 diff --git a/lib/translationunits/MWLink.js b/lib/translationunits/MWLink.js index d28269d..01e1345 100644 --- a/lib/translationunits/MWLink.js +++ b/lib/translationunits/MWLink.js @@ -30,6 +30,7 @@ if ( linkPairInfo.targetTitle ) { // NOTE: This paths we are setting here are not relative paths. this.node.attributes[ 'href' ] = linkPairInfo.targetTitle; + this.node.attributes[ 'title' ] = linkPairInfo.targetTitle; adaptationInfo.targetTitle = yield apiRequestManager.titleInfoRequest( linkPairInfo.targetTitle, this.targetLanguage ); diff --git a/test/index.js b/test/index.js index b6feadd..142b56e 100644 --- a/test/index.js +++ b/test/index.js @@ -13,6 +13,7 @@ 'lib/pageloader', 'lib/routes', 'lib/segmentation', + 'lib/translationunits', 'tests/**/*.js' ]; diff --git a/test/translationunits/MWLink.test.js b/test/translationunits/MWLink.test.js new file mode 100644 index 000..eb17808 --- /dev/null +++ b/test/translationunits/MWLink.test.js @@ -0,0 +1,24 @@ +'use strict'; + +var assert = require( '../utils/assert.js' ), + server = require( '../utils/server.js' ), + async = require( 'async' ), + Adapter = require( '../../lib/Adapter' ), + tests = require( './MWLink.test.json' ); + +describe( 'Link Adaptation tests', function () { + async.forEach( tests, function ( test ) { + it( 'should not have any errors when: ' + test.desc, function () { + var translationunit, adapter; + + adapter = new Adapter( test.from, test.to, server.config ); + translationunit = adapter.getAdapter( test.source ); + return translationunit.adapt( test.source ).then( function ( adaptedNode ) { + assert.deepEqual( adaptedNode.attributes.href, test.result.attributes.href ); + assert.deepEqual( adaptedNode.attributes.rel, test.result.attributes.rel ); + assert.deepEqual( adaptedNode.attributes.title, test.result.attributes.title ); + assert.deepEqual( JSON.parse( adaptedNode.attributes[ 'data-cx' ] ), test.result.attributes[ 'data-cx' ] ); + } ); + } ); + } ); +} ); diff --git a/test/translationunits/MWLink.test.json b/test/translationunits/MWLink.test.json new file mode 100644 index 000..f39befe --- /dev/null +++ b/test/translationunits/MWLink.test.json @@ -0,0 +1,287 @@ +[ + { + "desc": "Basic test", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Oxygen", + "title": "Oxygen" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Oxígeno", + "title": "Oxígeno", + "data-cx": { + "adapted": true, + "targetTitle": { + "pageid": 3267, + "ns": 0, + "title": "Oxígeno", + "contentmodel": "wikitext", + "pagelanguage": "es", + "pagelanguagehtmlcode": "es", + "pagelanguagedir": "ltr", + "touched": "2017-08-22T17:53:12Z", + "lastrevid": 101258484, + "length": 104691, + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/O%2C8.jpg/80px-O%2C8.jpg;, + "width":
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Provide title info- description, image along with the adapta...
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373255 ) Change subject: Provide title info- description, image along with the adaptation .. Provide title info- description, image along with the adaptation Since the comparison of HTML after adaptation is very inefficient and difficult to comprehend, I changed it to just string length comparison. In a follow up commit, we will try to write unit test against the TranslationUnit classes by passing the node Object directly. Bug: T170674 Change-Id: I22640d11baf70e5a16103df77eabb17f9290e5f7 --- M lib/mw/ApiRequestManager.js A lib/mw/TitleInfoRequest.js M lib/translationunits/MWLink.js M test/adaptation/AdaptationTest.js 4 files changed, 90 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/55/373255/1 diff --git a/lib/mw/ApiRequestManager.js b/lib/mw/ApiRequestManager.js index dd0e799..33adac2 100644 --- a/lib/mw/ApiRequestManager.js +++ b/lib/mw/ApiRequestManager.js @@ -1,6 +1,7 @@ 'use strict'; const TitlePairRequest = require( './TitlePairRequest.js' ), + TitleInfoRequest = require( './TitleInfoRequest.js' ), ApiRequest = require( './ApiRequest.js' ); class MWApiRequestManager { @@ -55,6 +56,24 @@ return canonicalNamespace; } ); } + + /** +* Creates a title info request for a given given language +* @param {string} title Title for which we want to get the information +* @param {string} language Language for the title +* @return {Promise} +*/ + titleInfoRequest( title, language ) { + if ( !MWApiRequestManager.titleInfoCache[ language ] ) { + MWApiRequestManager.titleInfoCache[ language ] = new TitleInfoRequest( { + sourceLanguage: language, + context: this.context + } ); + } + + return MWApiRequestManager.titleInfoCache[ language ].get( title ); + } + } /** @@ -65,4 +84,10 @@ */ MWApiRequestManager.titlePairCache = new Map(); +/** + * Cached instances for TitleInfoRequest for each language. + * @type {Map} + */ +MWApiRequestManager.titleInfoCache = new Map(); + module.exports = MWApiRequestManager; diff --git a/lib/mw/TitleInfoRequest.js b/lib/mw/TitleInfoRequest.js new file mode 100644 index 000..af7441b --- /dev/null +++ b/lib/mw/TitleInfoRequest.js @@ -0,0 +1,42 @@ +'use strict'; + +/** + * ContentTranslation Title Info request + * + */ +const BatchedAPIRequest = require( './BatchedAPIRequest.js' ); + +/** + * Fetches information about titles in batches. + * + * @class + * @extends BatchedAPIRequest + * @constructor + * @param {Object} config Configuration + */ +class TitleInfoRequest extends BatchedAPIRequest { + processPage( page ) { + return page; + } + + getRequestPromise( subqueue ) { + var domain, query; + query = { + action: 'query', + prop: 'info|pageprops|pageimages|pageterms', + pithumbsize: 80, + pilimit: subqueue.length, + wbptterms: 'description', + ppprop: 'disambiguation', + titles: subqueue.join( '|' ), + redirects: true, + 'continue': '' + }; + domain = this.getDomain( this.sourceLanguage ); + // We use POST here because the titles when joined will result in a longer query string + // that GET requests cannot process sometimes. + return this.mwPost( domain, query ); + } +} + +module.exports = TitleInfoRequest; diff --git a/lib/translationunits/MWLink.js b/lib/translationunits/MWLink.js index 44b65f3..d28269d 100644 --- a/lib/translationunits/MWLink.js +++ b/lib/translationunits/MWLink.js @@ -5,33 +5,40 @@ MWApiRequestManager = require( '../mw/ApiRequestManager.js' ); class MWLink extends TranslationUnit { - constructor( node, sourceLanguage, targetLanguage, context ) { - super( node, sourceLanguage, targetLanguage, context ); - // Nothing else? - } } MWLink.matchTagNames = [ 'a' ]; MWLink.matchRdfaTypes = [ 'mw:WikiLink' ]; MWLink.prototype.adapt = cxutil.async( function* () { - var linkPairInfo; + var linkPairInfo, adaptationInfo, sourceTitleInfoRequest, + apiRequestManager = new MWApiRequestManager( this.context ); - linkPairInfo = yield new MWApiRequestManager( this.context ) - .titlePairRequest( this.node.attributes.href, this.sourceLanguage, this.targetLanguage ); + adaptationInfo = { + adapted: false + }; + + //
[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Remove hardcoded cxserver /translate API url
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373178 ) Change subject: Remove hardcoded cxserver /translate API url .. Remove hardcoded cxserver /translate API url Use the sitemapper module for doing cxserver request. We need move these methods from mw.cx.ui.TranslationView to a better place as next step. Change-Id: Idf2bd169f2bd9b890472c8615fb0a775469e60b4 --- M modules/ui/mw.cx.ui.TranslationView.js 1 file changed, 76 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/78/373178/1 diff --git a/modules/ui/mw.cx.ui.TranslationView.js b/modules/ui/mw.cx.ui.TranslationView.js index 59e04c0..eebe74f 100644 --- a/modules/ui/mw.cx.ui.TranslationView.js +++ b/modules/ui/mw.cx.ui.TranslationView.js @@ -1,4 +1,5 @@ 'use strict'; + /** * TranslationView * @@ -366,14 +367,83 @@ }; +/** + * Translate and adapt the given source section + * @param {string} source Source html content + * @return {jQuery.Promise} + */ mw.cx.ui.TranslationView.prototype.translate = function ( source ) { - return $.ajax( { - method: 'POST', - contentType: 'application/x-www-form-urlencoded', - // TODO hardcoded - url: 'http://localhost:8080/v1/translate/en/es/Apertium', - data: { html: source } + var translateURL; + + translateURL = this.config.siteMapper.getCXServerUrl( '/translate/$from/$to', { + $from: this.config.sourceLanguage, + $to: this.config.targetLanguage + // $provider: this.provider // TOOD: Pass the MT provider, else default will be used } ); + + return this.getCXServerToken().then( function ( token ) { + return $.ajax( { + type: 'post', + url: translateURL, + headers: { + Authorization: token + }, + data: { html: source } + } ); + } ); +}; + +mw.cx.ui.TranslationView.static.cxserverToken = { + expires: undefined, + jwt: undefined, + promise: undefined +}; + +/** + * Fetch token for authentication with cxserver. + * + * @return {jQuery.Promise} + */ +mw.cx.ui.TranslationView.prototype.getCXServerToken = function () { + var now = Math.floor( Date.now() / 1000 ), + cxserverToken = mw.cx.ui.TranslationView.static.cxserverToken; + + // If request in progress, wait for it + if ( cxserverToken.promise ) { + return cxserverToken.promise; + } + + // Return cached token if fresh and not expiring soon. + // And hope that client clock is at correct time. + if ( + cxserverToken.expires !== undefined && + cxserverToken.expires + 5 < now + ) { + return $.Deferred().resolve( cxserverToken.jwt ); + } + + // (Re-)fetch cxserver token + cxserverToken.promise = ( new mw.Api() ) + .postWithToken( 'csrf', { + action: 'cxtoken' + } ) + .always( function () { + cxserverToken.promise = undefined; + } ) + .then( function ( response ) { + cxserverToken.jwt = response.jwt; + cxserverToken.expires = response.exp; + + return response.jwt; + }, + // Not all MT services require token, so let the caller try + // with empty token to see if it fails. + function () { + return $.Deferred().resolve( '' ); + } + ); + + return cxserverToken.promise; }; mw.cx.ui.TranslationView.prototype.showCategories = function () { -- To view, visit https://gerrit.wikimedia.org/r/373178 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idf2bd169f2bd9b890472c8615fb0a775469e60b4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add default mwapi_req template configuration to config.yaml
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373051 ) Change subject: Add default mwapi_req template configuration to config.yaml .. Add default mwapi_req template configuration to config.yaml Bug: T173038 Change-Id: Iaeb6bf7a6124d51e2e6599a641f195a11912be8f --- M config.dev.yaml M config.prod.yaml 2 files changed, 16 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/51/373051/1 diff --git a/config.dev.yaml b/config.dev.yaml index f171eef..055d4a0 100644 --- a/config.dev.yaml +++ b/config.dev.yaml @@ -48,6 +48,14 @@ # - domain1.com # - domain2.org user_agent: cxserver + mwapi_req: +body: "{{request.body}}" +query: "{{ default(request.query, {}) }}" +headers: + host: "{{request.params.domain}}" + user-agent: "{{user-agent}}" +method: post +uri: "https://{{domain}}/w/api.php; restbase_req: method: '{{request.method}}' uri: https://{{domain}}/api/rest_v1/{+path} diff --git a/config.prod.yaml b/config.prod.yaml index 362ab26..c05a7ab 100644 --- a/config.prod.yaml +++ b/config.prod.yaml @@ -48,6 +48,14 @@ # - domain1.com # - domain2.org user_agent: cxserver + mwapi_req: +body: "{{request.body}}" +query: "{{ default(request.query, {}) }}" +headers: + host: "{{request.params.domain}}" + user-agent: "{{user-agent}}" +method: post +uri: "https://{{domain}}/w/api.php; restbase_req: method: '{{request.method}}' uri: https://{{domain}}/api/rest_v1/{+path} -- To view, visit https://gerrit.wikimedia.org/r/373051 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaeb6bf7a6124d51e2e6599a641f195a11912be8f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Fix the unwanted nesting of Segmenter and PageLoader modules
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372528 ) Change subject: Fix the unwanted nesting of Segmenter and PageLoader modules .. Fix the unwanted nesting of Segmenter and PageLoader modules Expose them directly instead of using a wrapper object with same name. Change-Id: I580e3d17577f068178f76ac1415fd04ca81d1ee6 --- M bin/segment M lib/index.js M lib/pageloader/PageLoader.js M lib/routes/v1.js M lib/segmentation/CXSegmenter.js M test/segmentation/CXSegmenter.test.js 6 files changed, 7 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/28/372528/1 diff --git a/bin/segment b/bin/segment index 0ccb3a5..31da4b2 100755 --- a/bin/segment +++ b/bin/segment @@ -1,7 +1,7 @@ #!/usr/bin/env node var script, xhtmlSource, xhtml, result, segmenter, fs = require( 'fs' ), - Segmenter = require( __dirname + '/../lib/segmentation/CXSegmenter' ).CXSegmenter, + Segmenter = require( __dirname + '/../lib/segmentation/CXSegmenter' ), LinearDoc = require( __dirname + '/../lib/lineardoc' ); function normalize( html ) { diff --git a/lib/index.js b/lib/index.js index 0a9b5db..a23edec 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = { - Segmenter: require( './segmentation/CXSegmenter.js' ).CXSegmenter, + Segmenter: require( './segmentation/CXSegmenter.js' ), Apertium: require( './mt/Apertium.js' ), Yandex: require( './mt/Yandex.js' ), MTClient: require( './mt/MTClient.js' ), diff --git a/lib/pageloader/PageLoader.js b/lib/pageloader/PageLoader.js index 6a75cd4..dde851a 100644 --- a/lib/pageloader/PageLoader.js +++ b/lib/pageloader/PageLoader.js @@ -69,4 +69,4 @@ } ); }; -module.exports.PageLoader = PageLoader; +module.exports = PageLoader; diff --git a/lib/routes/v1.js b/lib/routes/v1.js index cfd948e..7506a81 100644 --- a/lib/routes/v1.js +++ b/lib/routes/v1.js @@ -14,8 +14,8 @@ var sourceLanguage = req.params.language, title = req.params.title, revision = req.params.revision, - CXSegmenter = require( __dirname + '/../segmentation/CXSegmenter.js' ).CXSegmenter, - PageLoader = require( __dirname + '/../pageloader/PageLoader.js' ).PageLoader, + CXSegmenter = require( __dirname + '/../segmentation/CXSegmenter.js' ), + PageLoader = require( __dirname + '/../pageloader/PageLoader.js' ), pageloader = new PageLoader( app ); return pageloader.load( title, sourceLanguage, revision ).then( diff --git a/lib/segmentation/CXSegmenter.js b/lib/segmentation/CXSegmenter.js index 30b2eb5..e878e2a 100644 --- a/lib/segmentation/CXSegmenter.js +++ b/lib/segmentation/CXSegmenter.js @@ -40,4 +40,4 @@ return this.segmentedDoc.getHtml(); }; -module.exports.CXSegmenter = CXSegmenter; +module.exports = CXSegmenter; diff --git a/test/segmentation/CXSegmenter.test.js b/test/segmentation/CXSegmenter.test.js index a0b9341..8df4c04 100644 --- a/test/segmentation/CXSegmenter.test.js +++ b/test/segmentation/CXSegmenter.test.js @@ -4,7 +4,7 @@ lang, i, len, lang, test, tests, assert = require( '../utils/assert.js' ), LinearDoc = require( '../../lib/lineardoc' ), - Segmenter = require( '../../lib/segmentation/CXSegmenter' ).CXSegmenter, + Segmenter = require( '../../lib/segmentation/CXSegmenter' ), allTests = require( './SegmentationTests.json' ); function normalize( html ) { -- To view, visit https://gerrit.wikimedia.org/r/372528 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I580e3d17577f068178f76ac1415fd04ca81d1ee6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Refresh MT client modules as classes - ES6 upgrade
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372503 ) Change subject: Refresh MT client modules as classes - ES6 upgrade .. Refresh MT client modules as classes - ES6 upgrade Change-Id: I0a9aaf9b71ee53d093956995cbe3073001f62081 --- M lib/mt/Apertium.js M lib/mt/MTClient.js M lib/mt/Yandex.js M lib/mt/Youdao.js 4 files changed, 547 insertions(+), 589 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/03/372503/1 diff --git a/lib/mt/Apertium.js b/lib/mt/Apertium.js index 89f8575..af9af5d 100644 --- a/lib/mt/Apertium.js +++ b/lib/mt/Apertium.js @@ -1,47 +1,39 @@ 'use strict'; var preq = require( 'preq' ), - util = require( 'util' ), MTClient = require( './MTClient.js' ), - apertiumLangMapping = require( './Apertium.languagenames.json' ), - postData; + apertiumLangMapping = require( './Apertium.languagenames.json' ); -function Apertium( options ) { - this.logger = options.logger; - this.conf = options.conf; +class Apertium extends MTClient { + /** +* Translate plain text with Apertium API +* Apertium is not capable of HTML translation with all annotation +* mapping. For translating HTML, It use CX's annotation mapping on top +* of the plaintext translation. Hence it inherits translateHTML method +* of MTClient. +* +* @param {string} sourceLang Source language code +* @param {string} targetLang Target language code +* @param {string} sourceText Source language text +* @return {BBPromise} promise: Target language text +*/ + translateText( sourceLang, targetLang, sourceText ) { + const postData = { + uri: this.conf.mt.apertium.api + '/translate', + body: { + markUnknown: 0, + langpair: apertiumLangMapping[ sourceLang ] + '|' + apertiumLangMapping[ targetLang ], + format: 'txt', + q: sourceText + } + }; + + return preq.post( postData ) + .then( ( response ) => response.body.responseData.translatedText ) + .catch( function () { + throw new Error( 'Translation with Apertium failed: ' + sourceLang + '-' + targetLang ); + } ); + } } - -util.inherits( Apertium, MTClient ); - -/** - * Translate plain text with Apertium API - * Apertium is not capable of HTML translation with all annotation - * mapping. For translating HTML, It use CX's annotation mapping on top - * of the plaintext translation. Hence it inherits translateHTML method - * of MTClient. - * - * @param {string} sourceLang Source language code - * @param {string} targetLang Target language code - * @param {string} sourceText Source language text - * @return {BBPromise} promise: Target language text - */ -Apertium.prototype.translateText = function ( sourceLang, targetLang, sourceText ) { - postData = { - uri: this.conf.mt.apertium.api + '/translate', - body: { - markUnknown: 0, - langpair: apertiumLangMapping[ sourceLang ] + '|' + apertiumLangMapping[ targetLang ], - format: 'txt', - q: sourceText - } - }; - - return preq.post( postData ).then( function ( response ) { - return response.body.responseData.translatedText; - } ).catch( function () { - throw new Error( 'Translation with Apertium failed: ' + - sourceLang + '-' + targetLang ); - } ); -}; module.exports = Apertium; diff --git a/lib/mt/MTClient.js b/lib/mt/MTClient.js index 1190ff4..1cce712 100644 --- a/lib/mt/MTClient.js +++ b/lib/mt/MTClient.js @@ -1,80 +1,61 @@ 'use strict'; -var LinearDoc = require( __dirname + '/../lineardoc' ), - BBPromise = require( 'bluebird' ), +const LinearDoc = require( __dirname + '/../lineardoc' ), SubSequenceMatcher = require( './annotationmapper/SubsequenceMatcher.js' ), createDOMPurify = require( 'dompurify' ), jsdom = require( 'jsdom' ); /** * MTClient - Generic machine translation client. - * - * @class - * - * @param {Object} options */ -function MTClient( options ) { - this.logger = options.logger; - this.conf = options.conf; - this.sourceDoc = null; - this.sourceHTML = null; -} - -MTClient.prototype.log = function ( level, info ) { - if ( this.logger && this.logger.log ) { - this.logger.log( level, info ); +class MTClient { + /** +* @param {Object} options +*/ + constructor( options ) { +
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Upgrade eslint to 4.1.0 and use latest eslint-config-wikimedia
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372126 ) Change subject: Upgrade eslint to 4.1.0 and use latest eslint-config-wikimedia .. Upgrade eslint to 4.1.0 and use latest eslint-config-wikimedia Latest eslint-config-wikimedia inhertis from eslint:recommended set. So there are a few fixes made to make tests pass. Change-Id: I5c7795332d554a35dd2625f1e9984f9bb5985211 --- M lib/dictionary/dict/DictClient.js M lib/lineardoc/Builder.js M lib/lineardoc/TextBlock.js M lib/mt/annotationmapper/SubsequenceMatcher.js M lib/routes/doc.js M lib/util.js M package.json 7 files changed, 20 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/26/372126/1 diff --git a/lib/dictionary/dict/DictClient.js b/lib/dictionary/dict/DictClient.js index be40e48..0f20a28 100644 --- a/lib/dictionary/dict/DictClient.js +++ b/lib/dictionary/dict/DictClient.js @@ -125,7 +125,7 @@ defs[ word ] = []; for ( dbIdx in words[ word ].db ) { db = words[ word ].db[ dbIdx ]; - req = 'd ' + db + ' "' + word + '"' + '\r\n'; + req = 'd ' + db + ' "' + word + '"\r\n'; reqQueue.push( { request: req, word: word, @@ -264,7 +264,7 @@ // also checking whether db isn't on ignore list if ( ( currentReq.type === 'def' ) && options.suggestions ) { reqQueue.push( { - request: 'match ' + currentReq.db + ' lev "' + currentReq.word + '"' + '\r\n', + request: 'match ' + currentReq.db + ' lev "' + currentReq.word + '"\r\n', type: 'sug', word: currentReq.word } ); diff --git a/lib/lineardoc/Builder.js b/lib/lineardoc/Builder.js index 57d69f8..35c474e 100644 --- a/lib/lineardoc/Builder.js +++ b/lib/lineardoc/Builder.js @@ -99,11 +99,11 @@ whitespace.reverse(); this.addInlineContent( new Doc() - .addItem( 'open', tag ) - .addItem( 'textblock', new TextBlock( - [ new TextChunk( whitespace.join( '' ), [] ) ] - ) ) - .addItem( 'close', tag ) + .addItem( 'open', tag ) + .addItem( 'textblock', new TextBlock( + [ new TextChunk( whitespace.join( '' ), [] ) ] + ) ) + .addItem( 'close', tag ) ); } return tag; diff --git a/lib/lineardoc/TextBlock.js b/lib/lineardoc/TextBlock.js index 5b42171..abf417c 100644 --- a/lib/lineardoc/TextBlock.js +++ b/lib/lineardoc/TextBlock.js @@ -446,7 +446,7 @@ // sub-doc: concatenate dump.push.apply( dump, chunk.inlineContent.dumpXmlArray( pad + ' ' ) ); } else { - dump.push( pad + ' ' + '<' + chunk.inlineContent.name + '/>' ); + dump.push( pad + ' <' + chunk.inlineContent.name + '/>' ); } dump.push( pad + '' ); } diff --git a/lib/mt/annotationmapper/SubsequenceMatcher.js b/lib/mt/annotationmapper/SubsequenceMatcher.js index 1766197..1a9f823 100644 --- a/lib/mt/annotationmapper/SubsequenceMatcher.js +++ b/lib/mt/annotationmapper/SubsequenceMatcher.js @@ -11,11 +11,11 @@ */ function cleanup( str ) { // Beginning - str = str.replace( /^[\,\.\/#!$%\^&\*;:"{}=_`~()]+/g, '' ); + str = str.replace( /^[,./#!$%^&*;:"{}=_`~()]+/g, '' ); // End - str = str.replace( /[\,\.\/#!$%\^&\*;:"{}=_`~()]+$/g, '' ); + str = str.replace( /[,./#!$%^&*;:"{}=_`~()]+$/g, '' ); // In between string - str = str.replace( /[\,\/#!$%\^&\*;:"{}=_`~()]+/g, '' ); + str = str.replace( /[,/#!$%^&*;:"{}=_`~()]+/g, '' ); return str; } diff --git a/lib/routes/doc.js b/lib/routes/doc.js index 01e0476..04de145 100644 --- a/lib/routes/doc.js +++ b/lib/routes/doc.js @@ -23,7 +23,7 @@ '' + app.conf.spec.info.title + ' docs' ) // Replace the default url with ours, switch off validation & // limit the size
[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add a sentence segment binary utility for debugging purposes
Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372120 ) Change subject: Add a sentence segment binary utility for debugging purposes .. Add a sentence segment binary utility for debugging purposes Change-Id: I9cee55f28c219d7026935ae2837fa070c7c77338 --- A bin/segment 1 file changed, 28 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/20/372120/1 diff --git a/bin/segment b/bin/segment new file mode 100755 index 000..72724cc --- /dev/null +++ b/bin/segment @@ -0,0 +1,28 @@ +#!/usr/bin/env node +var script, xhtmlSource, xhtml, result, segmenter, + fs = require( 'fs' ), + Segmenter = require( __dirname + '/../lib/segmentation/CXSegmenter' ).CXSegmenter, + LinearDoc = require( __dirname + '/../lib/lineardoc' ); + +function normalize( html ) { + var normalizer = new LinearDoc.Normalizer(); + normalizer.init(); + normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) ); + return normalizer.getHtml(); +} + +script = process.argv[ 1 ]; +if ( process.argv.length !== 3 ) { + process.stderr.write( + 'Usage: node ' + script + ' xhtmlSource\n' + + 'xhtml must be wrapped in a block element such as ... or ...\n' + ); + process.exit( 1 ); +} + +xhtmlSource = process.argv[ 2 ]; +xhtml = fs.readFileSync( xhtmlSource, 'utf8' ); +segmenter = new Segmenter( xhtml, 'en' ); +segmenter.segment(); +result = normalize( segmenter.getSegmentedContent() ); +process.stdout.write( result + '\n' ); -- To view, visit https://gerrit.wikimedia.org/r/372120 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9cee55f28c219d7026935ae2837fa070c7c77338 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits