Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/106661
Change subject: Add modules for each components, define plugins ...................................................................... Add modules for each components, define plugins UI is completely moved to javascript Change-Id: I8c2fb29d437a82919bf83e77659d8e20caa979a8 --- M Resources.php M modules/base/ext.ct.base.js A modules/base/ext.ct.header.js A modules/base/images/wikipedia-logo-landscape.png M modules/base/styles/ext.ct.base.less A modules/base/styles/ext.ct.header.less A modules/source/ext.ct.source.js A modules/tools/ext.ct.tools.js A modules/translation/ext.ct.translation.js M specials/SpecialContentTranslation.php 10 files changed, 356 insertions(+), 75 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/61/106661/1 diff --git a/Resources.php b/Resources.php index 773f81f..85a6dec 100644 --- a/Resources.php +++ b/Resources.php @@ -21,5 +21,28 @@ ), 'dependencies' => array( 'mediawiki.ui', + 'ext.ct.header', + 'ext.ct.source', + 'ext.ct.translation', + 'ext.ct.tool', ), ) + $resourcePaths; + +$wgResourceModules['ext.ct.header'] = array( + 'scripts' => 'base/ext.ct.header.js', + 'styles' => array( + 'base/styles/ext.ct.header.less', + ), +) + $resourcePaths; + +$wgResourceModules['ext.ct.source'] = array( + 'scripts' => 'source/ext.ct.source.js', +) + $resourcePaths; + +$wgResourceModules['ext.ct.translation'] = array( + 'scripts' => 'translation/ext.ct.translation.js', +) + $resourcePaths; + +$wgResourceModules['ext.ct.tool'] = array( + 'scripts' => 'tools/ext.ct.tools.js', +) + $resourcePaths; diff --git a/modules/base/ext.ct.base.js b/modules/base/ext.ct.base.js index df54ecf..fc70229 100644 --- a/modules/base/ext.ct.base.js +++ b/modules/base/ext.ct.base.js @@ -8,7 +8,73 @@ * @copyright See AUTHORS.txt * @license GPL-2.0+ */ -//( function ( $, mw ) { -// 'use strict'; -// -//}( jQuery, mediaWiki ) ); \ No newline at end of file +( function ( $ ) { + 'use strict'; + + /** + * ContentTranslation + * + * @class + */ + function ContentTranslation( element, options ) { + this.$container = $( element ); + this.$translation = null; + this.$header = null; + this.$source = null; + this.$tools = null; + this.options = $.extend( true, {}, $.fn.ct.defaults, options ); + this.init(); + } + + ContentTranslation.prototype.init = function () { + this.render(); + this.initComponents(); + }; + + ContentTranslation.prototype.initComponents = function () { + // Initialize the components + this.$header.ctHeader(); + this.$source.ctSource(); + this.$translation.ctTranslation(); + this.$tools.ctTools(); + }; + + ContentTranslation.prototype.render = function () { + var $content; + + $content = $( '<div>' ).addClass( 'content' ) + .append( + $( '<div>' ).addClass( 'header' ), + $( '<div>' ).addClass( 'source' ), + $( '<div>' ).addClass( 'translation' ), + $( '<div>' ).addClass( 'tools' ) + ); + this.$container.append( $content ); + this.$header = this.$container.find( '.header' ); + this.$source = this.$container.find( '.source' ); + this.$translation = this.$container.find( '.translation' ); + this.$tools = this.$container.find( '.tools' ); + }; + + $.fn.ct = function ( options ) { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'ct' ); + + if ( !data ) { + $this.data( 'ct', + ( data = new ContentTranslation( this, options ) ) + ); + } + + if ( typeof options === 'string' ) { + data[options].call( $this ); + } + } ); + }; + $.fn.ct.defaults = {}; + + $( document ).ready( function () { + $( 'body' ).ct(); + } ); +}( jQuery ) ); diff --git a/modules/base/ext.ct.header.js b/modules/base/ext.ct.header.js new file mode 100644 index 0000000..7d9eb73 --- /dev/null +++ b/modules/base/ext.ct.header.js @@ -0,0 +1,52 @@ +/** + * ContentTranslation Tools + * A tool that allows editors to translate pages from one language + * to another with the help of machine translation and other translation aids + * + * @file + * @ingroup Extensions + * @copyright See AUTHORS.txt + * @license GPL-2.0+ + */ +( function ( $ ) { + 'use strict'; + + /** + * ContentTranslationHeader + * + * @class + */ + function ContentTranslationHeader( element, options ) { + this.$container = $( element ); + this.options = $.extend( true, {}, $.fn.ctHeader.defaults, options ); + this.init(); + } + + ContentTranslationHeader.prototype.init = function () { + this.render(); + }; + + ContentTranslationHeader.prototype.render = function () { + this.$container.append( $( '<div>' ) + .addClass( 'logo') + ); + }; + + $.fn.ctHeader = function ( options ) { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'ctHeader' ); + + if ( !data ) { + $this.data( 'ctHeader', + ( data = new ContentTranslationHeader( this, options ) ) + ); + } + + if ( typeof options === 'string' ) { + data[options].call( $this ); + } + } ); + }; + $.fn.ctHeader.defaults = {}; +}( jQuery ) ); diff --git a/modules/base/images/wikipedia-logo-landscape.png b/modules/base/images/wikipedia-logo-landscape.png new file mode 100644 index 0000000..2d18f68 --- /dev/null +++ b/modules/base/images/wikipedia-logo-landscape.png Binary files differ diff --git a/modules/base/styles/ext.ct.base.less b/modules/base/styles/ext.ct.base.less index 4288076..f280eb6 100644 --- a/modules/base/styles/ext.ct.base.less +++ b/modules/base/styles/ext.ct.base.less @@ -16,11 +16,6 @@ .mw-ui-one-whole; .mw-ui-palm-one-whole; border-bottom: 1px solid @grey; - #p-logo { - height: 100px; - background-repeat: no-repeat; - background-position: center center; - } } .source { diff --git a/modules/base/styles/ext.ct.header.less b/modules/base/styles/ext.ct.header.less new file mode 100644 index 0000000..e2cf04d --- /dev/null +++ b/modules/base/styles/ext.ct.header.less @@ -0,0 +1,12 @@ +@import "grid/agora-grid"; + +.header { + .logo { + .mw-ui-one-third; + height: 100px; + background-size: 50%; + background-image: url(../images/wikipedia-logo-landscape.png); + background-repeat: no-repeat; + background-position: left top; + } +} diff --git a/modules/source/ext.ct.source.js b/modules/source/ext.ct.source.js new file mode 100644 index 0000000..1c88ff4 --- /dev/null +++ b/modules/source/ext.ct.source.js @@ -0,0 +1,55 @@ +/** + * ContentTranslation Tools + * A tool that allows editors to translate pages from one language + * to another with the help of machine translation and other translation aids + * + * @file + * @ingroup Extensions + * @copyright See AUTHORS.txt + * @license GPL-2.0+ + */ +( function ( $ ) { + 'use strict'; + + /** + * ContentTranslationSource + * + * @class + */ + function ContentTranslationSource( element, options ) { + this.$container = $( element ); + this.options = $.extend( true, {}, $.fn.ctSource.defaults, options ); + this.init(); + } + + ContentTranslationSource.prototype.init = function () { + this.render(); + }; + + ContentTranslationSource.prototype.render = function () { + this.$container.append( $( '<h2>' ) + .text( 'Article title' ) + ); + + this.$container.append( $( '<div>' ) + .text( 'Article text' ) ); + }; + + $.fn.ctSource = function ( options ) { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'ctSource' ); + + if ( !data ) { + $this.data( 'ctSource', + ( data = new ContentTranslationSource( this, options ) ) + ); + } + + if ( typeof options === 'string' ) { + data[options].call( $this ); + } + } ); + }; + $.fn.ctSource.defaults = {}; +}( jQuery ) ); diff --git a/modules/tools/ext.ct.tools.js b/modules/tools/ext.ct.tools.js new file mode 100644 index 0000000..84e8f45 --- /dev/null +++ b/modules/tools/ext.ct.tools.js @@ -0,0 +1,84 @@ +/** + * ContentTranslation Tools + * A tool that allows editors to translate pages from one language + * to another with the help of machine translation and other translation aids + * + * @file + * @ingroup Extensions + * @copyright See AUTHORS.txt + * @license GPL-2.0+ + */ +( function ( $ ) { + 'use strict'; + + /** + * ContentTranslationTools + * + * @class + */ + function ContentTranslationTools( element, options ) { + this.$container = $( element ); + this.options = $.extend( true, {}, $.fn.ctTools.defaults, options ); + this.init(); + } + + ContentTranslationTools.prototype.init = function () { + this.render(); + }; + + ContentTranslationTools.prototype.render = function () { + this.$container.append( this.helpMessage() ); + }; + + ContentTranslationTools.prototype.helpMessage = function () { + var $content; + + $content = $( '<h2>' ) + .text( 'Create a translation' ) + .after( $( '<ol>' ) + .append( + $( '<li>' ) + .text( 'Add some paragraphs to the translation.' ), + $( '<li>' ) + .text( 'Adjust the automatic translations ' + + ' provided to ensure quality' ) + .append( $( '<ul>') + .append( + $( '<li>' ) + .text( 'Machine translation is a useful starting point for' + + 'translations, but translators must revise errors as' + + 'necessary and confirm that the translation is accurate.' ), + $( '<li>' ) + .text( 'o not translate text that appears unreliable' + + 'or low-quality. If possible, verify the text with' + + 'references provided in the source article.' ) + ) + ), + $( '<div>' ) + .text( 'When you are happy with the result,' + + 'select \"Publish Translation\" ' + + 'to create a new article.' ) + ) + ); + + return $content; + }; + + $.fn.ctTools = function ( options ) { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'ctTools' ); + + if ( !data ) { + $this.data( 'ctTools', + ( data = new ContentTranslationTools( this, options ) ) + ); + } + + if ( typeof options === 'string' ) { + data[options].call( $this ); + } + } ); + }; + $.fn.ctTools.defaults = {}; +}( jQuery ) ); diff --git a/modules/translation/ext.ct.translation.js b/modules/translation/ext.ct.translation.js new file mode 100644 index 0000000..5e86773 --- /dev/null +++ b/modules/translation/ext.ct.translation.js @@ -0,0 +1,60 @@ +/** + * ContentTranslation Tools + * A tool that allows editors to translate pages from one language + * to another with the help of machine translation and other translation aids + * + * @file + * @ingroup Extensions + * @copyright See AUTHORS.txt + * @license GPL-2.0+ + */ +( function ( $ ) { + 'use strict'; + + /** + * ContentTranslationEditor + * + * @class + */ + function ContentTranslationEditor( element, options ) { + this.$container = $( element ); + this.options = $.extend( true, {}, $.fn.ctTranslation.defaults, options ); + this.init(); + } + + ContentTranslationEditor.prototype.init = function () { + this.render(); + }; + + ContentTranslationEditor.prototype.render = function () { + var $content; + + this.$container.append( $( '<h2>' ) + .attr( 'contenteditable', true ) + .text( 'Translated title' ) + ); + + $content = $( '<div>' ) + .attr( 'contenteditable', true ) + .text( 'Translated text' ); + this.$container.append( $content ); + }; + + $.fn.ctTranslation = function ( options ) { + return this.each( function () { + var $this = $( this ), + data = $this.data( 'ctTranslation' ); + + if ( !data ) { + $this.data( 'ctTranslation', + ( data = new ContentTranslationEditor( this, options ) ) + ); + } + + if ( typeof options === 'string' ) { + data[options].call( $this ); + } + } ); + }; + $.fn.ctTranslation.defaults = {}; +}( jQuery ) ); diff --git a/specials/SpecialContentTranslation.php b/specials/SpecialContentTranslation.php index 8fd89cc..f3ce78b 100644 --- a/specials/SpecialContentTranslation.php +++ b/specials/SpecialContentTranslation.php @@ -35,8 +35,6 @@ $out->addHTML( $out->headElement( $skin ) ); - $out->addHTML( $this->makeContent() ); - // Enable this if you need useful debugging information $out->addHtml( MWDebug::getDebugHTML( $this->getContext() ) ); wfRunHooks( 'BeforePageDisplay', array( &$out, &$skin ) ); @@ -44,68 +42,4 @@ $out->addHTML( '</body></html>' ); } - private function makeContent() { - $header = $this->makeHeader(); - $source = $this->makeSourceContent(); - $translation = $this->makeTranslationContent(); - $tools = $this->makeToolsContent(); - - $html = <<<HTML -<div class="content"> - <div class="header">$header</div> - <div class="source">$source</div> - <div class="translation" contenteditable>$translation</div> - <div class="tools">$tools</div> -</div> -HTML; - - return $html; - } - - private function makeHeader() { - global $wgLogo; - return <<<HTML -<img src=$wgLogo></img> -HTML; - } - - private function makeSourceContent() { - $html = <<<HTML -<h2>Article title</h2> -<p>Article content</p> -HTML; - return $html; - } - - private function makeTranslationContent() { - $html = <<<HTML -<h2>Article title</h2> -<p>Your translation</p> -HTML; - - return $html; - } - - private function makeToolsContent() { - $html = <<<HTML - <h2>Create a translation</h2> - <ol> - <li>Add some paragraphs to the translation.</li> - <li>Adjust the automatic translations provided to ensure quality. - <ul> - <li>Machine translation is a useful starting point for - translations, but translators must revise errors as - necessary and confirm that the translation is accurate.</li> - <li>Do not translate text that appears unreliable - or low-quality. If possible, verify the text with - references provided in the source article.</li> - </ul> - </li> - <li>When you are happy with the result, select "Publish Translation" - to create a new article.</li> - </ol> -HTML; - - return $html; - } } -- To view, visit https://gerrit.wikimedia.org/r/106661 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8c2fb29d437a82919bf83e77659d8e20caa979a8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits