r112668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112667‎ | r112668 | r112669 >
Date:05:33, 29 February 2012
Author:santhosh
Status:resolved (Comments)
Tags:i18nreview 
Comment:
UI for the language restriction for page translation
Backend logic for saving the language restriction data.
Modified paths:
  • /trunk/extensions/Translate/PageTranslation.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js (added) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -70,6 +70,7 @@
7171 $wgOut->addWikiMsg( 'tpt-nosuchpage', $title->getPrefixedText() );
7272 return;
7373 }
 74+ $wgOut->addModules( 'ext.translate.special.pagetranslation' );
7475
7576 if ( $action === 'discourage' || $action === 'encourage' ) {
7677 $id = TranslatablePage::getMessageGroupIdFromTitle( $title );
@@ -528,6 +529,22 @@
529530 }
530531 }
531532
 533+ $priorityLangs = TranslateMetadata::get( $page->getMessageGroupId(), 'prioritylangs' );
 534+ $priorityForce = TranslateMetadata::get( $page->getMessageGroupId(), 'priorityforce' );
 535+ $priorityReason = TranslateMetadata::get( $page->getMessageGroupId(), 'priorityreason' );
 536+ $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-prioritylangs' );
 537+ $langSelector = Xml::languageSelector( $wgContLang-> getCode() );
 538+ $priorityLangsInput = Html::element( 'input', array( 'id' => 'tpt-prioritylangs', 'size' => '50', 'name' => 'prioritylangs', 'value' => $priorityLangs , ) );
 539+ if ( $priorityForce === 'on' ) {
 540+ $forceLimit = Html::element( 'input', array( 'id' => 'tpt-priority-forcelimit', 'type' => 'checkbox', 'name' => 'forcelimit', 'checked' => 'checked' ) );
 541+ } else {
 542+ $forceLimit = Html::element( 'input', array( 'id' => 'tpt-priority-forcelimit', 'type' => 'checkbox', 'name' => 'forcelimit' ) );
 543+ }
 544+ $priorityReasonTextArea = Html::element( 'textarea', array( 'id' => 'tpt-priority-reason', 'name' => 'priorityreason' ), $priorityReason );
 545+ $forceLimitLabel = Html::element( 'label', array( 'id' => 'tpt-priority-forcelimit-label', 'for' => 'tpt-priority-forcelimit' ), wfMsgHtml( 'tpt-select-prioritylangs-force' ) );
 546+ $wgOut->addHTML( wfMsgHtml( 'tpt-select-prioritylangs' ) . $langSelector[1] . $priorityLangsInput );
 547+ $wgOut->addHTML( '<br/>' . $forceLimit . $forceLimitLabel . '<br/>' . wfMsgHtml( 'tpt-select-prioritylangs-reason' ) . $priorityReasonTextArea . '<br/>' );
 548+
532549 $wgOut->addHTML(
533550 Xml::submitButton( wfMsg( 'tpt-submit' ) ) .
534551 Xml::closeElement( 'form' )
@@ -619,6 +636,11 @@
620637 $page->addMarkedTag( $newrevision, $changed );
621638 $this->addFuzzyTags( $page, $changed );
622639
 640+ // Save the priority languages if any
 641+ $priorityLangs = trim( $wgRequest->getVal( 'prioritylangs' ) );
 642+ $priorityForce = $wgRequest->getVal( 'forcelimit' );
 643+ $priorityReason = $wgRequest->getVal( 'priorityreason' );
 644+
623645 global $wgUser;
624646 $logger = new LogPage( 'pagetranslation' );
625647 $params = array(
@@ -627,6 +649,24 @@
628650 'changed' => count( $changed ),
629651 );
630652 $logger->addEntry( 'mark', $page->getTitle(), null, array( serialize( $params ) ) );
 653+ if ( $priorityLangs ) {
 654+ $groupId = $page->getMessageGroupId();
 655+ TranslateMetadata::set( $groupId, 'prioritylangs', trim( $priorityLangs, ',' ) );
 656+ if ( $priorityForce ) {
 657+ TranslateMetadata::set( $groupId, 'priorityforce', $priorityForce );
 658+ } else {
 659+ TranslateMetadata::set( $groupId, 'priorityforce', 'off' );
 660+ }
 661+ if ( trim( $priorityReason ) ) {
 662+ TranslateMetadata::set( $groupId, 'priorityreason', $priorityReason );
 663+ }
 664+ $params = array(
 665+ 'user' => $wgUser->getName(),
 666+ 'languages' => $priorityLangs,
 667+ 'force' => $priorityForce,
 668+ );
 669+ $logger->addEntry( 'prioritylanguages', $page->getTitle(), null, array( serialize( $params ) ) );
 670+ }
631671
632672 $page->getTitle()->invalidateCache();
633673 $this->setupRenderJobs( $page );
Index: trunk/extensions/Translate/Translate.php
@@ -247,7 +247,11 @@
248248 ) + $resourcePaths;
249249
250250 $wgResourceModules['ext.translate.special.pagetranslation'] = array(
 251+ 'scripts' => 'resources/ext.translate.special.pagetranslation.js',
251252 'styles' => 'resources/ext.translate.special.pagetranslation.css',
 253+ 'dependencies' => array(
 254+ 'jquery.ui.autocomplete',
 255+ ),
252256 'position' => 'top',
253257 ) + $resourcePaths;
254258
Index: trunk/extensions/Translate/PageTranslation.i18n.php
@@ -64,7 +64,11 @@
6565 'tpt-other-pages' => '{{PLURAL:$1|An old version of this page is|Older versions of these pages are}} marked for translation,
6666 but the latest {{PLURAL:$1|version|versions}} cannot be marked for translation.',
6767 'tpt-discouraged-pages' => '{{PLURAL:$1|This page has|These pages have}} been discouraged from further translation.',
68 -
 68+ 'tpt-select-prioritylangs' => 'Preferred languages(comma seperated language codes): ',
 69+ 'tpt-select-prioritylangs-force' => 'Limit translation to these languages alone',
 70+ 'tpt-select-prioritylangs-reason' => 'Reason for setting this set of preferred languages(optional): ',
 71+ 'tpt-sections-prioritylangs' => 'Preferred Languages',
 72+
6973 'tpt-rev-mark' => 'mark for translation',
7074 'tpt-rev-unmark' => 'remove from translation',
7175 'tpt-rev-discourage' => 'discourage',
@@ -249,6 +253,10 @@
250254 'tpt-translation-restricted' => 'Error message shown to user when translation to a language which is restricted by translation admin.',
251255 'tpt-discouraged-language-force' => 'Warning shown along with group description if the language is prevented from translation for the selected language',
252256 'tpt-discouraged-language' => 'Warning shown along with group description if the language is discouraged from translation for the selected language',
 257+ 'tpt-select-prioritylangs' => 'Label for the input box to enter preferred languages',
 258+ 'tpt-select-prioritylangs-force' => 'Label for the checkbox to make the translation restriction',
 259+ 'tpt-select-prioritylangs-reason' => 'Label for the textbox to enter reason for restriction',
 260+ 'tpt-sections-prioritylangs' => 'Section title in [[Special:PageTranslation]]',
253261 'pt-parse-open' => '"Translation template" is the structure of a translation page, where the place for the translations of each section is marked with a placeholder.',
254262 'pt-shake-multiple' => 'Each translation (=section) unit can only contain one marker.',
255263 'pt-shake-empty' => 'Translation unit (=section) is empty except for the translation marker (=<nowiki><!--T:1--></nowiki>)',
Index: trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js
@@ -0,0 +1,77 @@
 2+/*
 3+ * @author Santhosh Thottingal
 4+ * jquery autocomplete based multiple selector for input box.
 5+ * Autocompleted values will be available in input filed as comma seperated values.
 6+ * The values for autocompletion is from the language selector in this case.
 7+ * The input field is a php created one.
 8+ * Credits: http://jqueryui.com/demos/autocomplete/#multiple
 9+ */
 10+jQuery( function( $ ) {
 11+ $.widget( "ui.combobox", {
 12+ _create: function() {
 13+ var self = this,
 14+ select = this.element.hide(),
 15+ selected = select.children( ":selected" );
 16+ function split( val ) {
 17+ return val.split( /,\s*/ );
 18+ }
 19+ var input = this.input = $( '#tpt-prioritylangs' )
 20+ .autocomplete( {
 21+ delay: 0,
 22+ minLength: 0,
 23+ source: function( request, response ) {
 24+ var term = split( request.term ).pop();
 25+ var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" );
 26+ response( select.children( "option" ).map(function() {
 27+ var text = $( this ).text();
 28+ var value = $( this ).val();
 29+ var term = split( request.term ).pop();
 30+ if ( this.value && ( !request.term || matcher.test(text) ) )
 31+ return {
 32+ label: text.replace(
 33+ new RegExp(
 34+ "(?![^&;]+;)(?!<[^<>]*)(" +
 35+ $.ui.autocomplete.escapeRegex(term) +
 36+ ")(?![^<>]*>)(?![^&;]+;)", "gi"
 37+ ), "<strong>$1</strong>" ),
 38+ value: value,
 39+ option: this
 40+ };
 41+ }) );
 42+ },
 43+ select: function( event, ui ) {
 44+ ui.item.option.selected = true;
 45+ self._trigger( "selected", event, {
 46+ item: ui.item.option
 47+ });
 48+ var terms = split( $(this).val() );
 49+ // remove the current input
 50+ terms.pop();
 51+ // add the selected item
 52+ terms.push( ui.item.value );
 53+ // add placeholder to get the comma-and-space at the end
 54+ terms.push( "" );
 55+ $( this ).val( terms.join( ", " ) );
 56+ return false;
 57+ }
 58+
 59+ });
 60+
 61+ input.data( "autocomplete" )._renderItem = function( ul, item ) {
 62+ return $( "<li></li>" )
 63+ .data( "item.autocomplete", item )
 64+ .append( "<a>" + item.label + "</a>" )
 65+ .appendTo( ul );
 66+ };
 67+
 68+ },
 69+
 70+ destroy: function() {
 71+ this.input.remove();
 72+ this.element.show();
 73+ $.Widget.prototype.destroy.call( this );
 74+ }
 75+ });
 76+
 77+ $( "#wpUserLanguage" ).combobox();
 78+} );
Property changes on: trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js
___________________________________________________________________
Added: svn:eol-style
179 + native
Index: trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css
@@ -16,3 +16,12 @@
1717 padding-left: 2em;
1818 padding-right: 2em;
1919 }
 20+
 21+.ui-autocomplete {
 22+ max-height: 100px;
 23+ overflow-y: auto;
 24+ /* prevent horizontal scrollbar */
 25+ overflow-x: hidden;
 26+ /* add padding to account for vertical scrollbar */
 27+ padding-right: 20px;
 28+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r112699Cleanups to r112668nikerabbit16:03, 29 February 2012
r112782* Improve logging...nikerabbit08:52, 1 March 2012

Comments

#Comment by Siebrand (talk | contribs)   07:40, 29 February 2012

There's trailing whitespace in two added messages, and there should be a space before ( twice

#Comment by Nikerabbit (talk | contribs)   15:06, 29 February 2012

The fact that term is used twice in JS is a bit confusing.

#Comment by Nikerabbit (talk | contribs)   16:04, 29 February 2012

Does not log if languages are removed.

Does not normalize list of languages input. Other code expects it to be 'a,b,c' not 'a, b, c'.

Status & tagging log