https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112668

Revision: 112668
Author:   santhosh
Date:     2012-02-29 05:33:05 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
UI for the language restriction for page translation
Backend logic for saving the language restriction data.

Modified Paths:
--------------
    trunk/extensions/Translate/PageTranslation.i18n.php
    trunk/extensions/Translate/Translate.php
    
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css
    trunk/extensions/Translate/tag/SpecialPageTranslation.php

Added Paths:
-----------
    
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js

Modified: trunk/extensions/Translate/PageTranslation.i18n.php
===================================================================
--- trunk/extensions/Translate/PageTranslation.i18n.php 2012-02-29 05:07:53 UTC 
(rev 112667)
+++ trunk/extensions/Translate/PageTranslation.i18n.php 2012-02-29 05:33:05 UTC 
(rev 112668)
@@ -64,7 +64,11 @@
        'tpt-other-pages' => '{{PLURAL:$1|An old version of this page is|Older 
versions of these pages are}} marked for translation,
 but the latest {{PLURAL:$1|version|versions}} cannot be marked for 
translation.',
        'tpt-discouraged-pages' => '{{PLURAL:$1|This page has|These pages 
have}} been discouraged from further translation.',
-
+       'tpt-select-prioritylangs' => 'Preferred languages(comma seperated 
language codes): ',
+       'tpt-select-prioritylangs-force' => 'Limit translation to these 
languages alone',
+       'tpt-select-prioritylangs-reason' => 'Reason for setting this set of 
preferred languages(optional): ',
+       'tpt-sections-prioritylangs' => 'Preferred Languages',
+       
        'tpt-rev-mark' => 'mark for translation',
        'tpt-rev-unmark' => 'remove from translation',
        'tpt-rev-discourage' => 'discourage',
@@ -249,6 +253,10 @@
        'tpt-translation-restricted' => 'Error message shown to user when 
translation to a language which is restricted by translation admin.',
        'tpt-discouraged-language-force' => 'Warning shown along with group 
description if the language is prevented from translation for the selected 
language',
        'tpt-discouraged-language' => 'Warning shown along with group 
description if the language is discouraged from translation for the selected 
language',
+       'tpt-select-prioritylangs' => 'Label for the input box to enter 
preferred languages',
+       'tpt-select-prioritylangs-force' => 'Label for the checkbox to make the 
translation restriction',
+       'tpt-select-prioritylangs-reason' => 'Label for the textbox to enter 
reason for restriction',
+       'tpt-sections-prioritylangs' => 'Section title in  
[[Special:PageTranslation]]',
        '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.',
        'pt-shake-multiple' => 'Each translation (=section) unit can only 
contain one marker.',
        'pt-shake-empty' => 'Translation unit (=section) is empty except for 
the translation marker (=<nowiki><!--T:1--></nowiki>)',

Modified: trunk/extensions/Translate/Translate.php
===================================================================
--- trunk/extensions/Translate/Translate.php    2012-02-29 05:07:53 UTC (rev 
112667)
+++ trunk/extensions/Translate/Translate.php    2012-02-29 05:33:05 UTC (rev 
112668)
@@ -247,7 +247,11 @@
 ) + $resourcePaths;
 
 $wgResourceModules['ext.translate.special.pagetranslation'] = array(
+       'scripts' => 'resources/ext.translate.special.pagetranslation.js',
        'styles' => 'resources/ext.translate.special.pagetranslation.css',
+       'dependencies' => array(
+               'jquery.ui.autocomplete',
+       ),
        'position' => 'top',
 ) + $resourcePaths;
 

Modified: 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css
===================================================================
--- 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css  
    2012-02-29 05:07:53 UTC (rev 112667)
+++ 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.css  
    2012-02-29 05:33:05 UTC (rev 112668)
@@ -16,3 +16,12 @@
        padding-left: 2em;
        padding-right: 2em;
 }
+
+.ui-autocomplete {
+       max-height: 100px;
+       overflow-y: auto;
+       /* prevent horizontal scrollbar */
+       overflow-x: hidden;
+       /* add padding to account for vertical scrollbar */
+       padding-right: 20px;
+}

Added: 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js
===================================================================
--- 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js   
                            (rev 0)
+++ 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js   
    2012-02-29 05:33:05 UTC (rev 112668)
@@ -0,0 +1,77 @@
+/*
+ * @author Santhosh Thottingal
+ * jquery autocomplete based multiple selector for input box. 
+ * Autocompleted values will be available in input filed as comma seperated 
values.
+ * The values for autocompletion is from the language selector in this case.
+ * The input field is a php created one.
+ * Credits: http://jqueryui.com/demos/autocomplete/#multiple
+ */
+jQuery( function( $ ) {
+       $.widget( "ui.combobox", {
+       _create: function() {
+               var self = this,
+                       select = this.element.hide(),
+                       selected = select.children( ":selected" );
+               function split( val ) {
+                       return val.split( /,\s*/ );
+               }
+               var input = this.input = $( '#tpt-prioritylangs' )
+                       .autocomplete( {
+                       delay: 0,
+                       minLength: 0,
+                       source: function( request, response ) {
+                               var term = split( request.term ).pop();
+                               var matcher = new RegExp( 
$.ui.autocomplete.escapeRegex( term ), "i" );
+                               response( select.children( "option" 
).map(function() {
+                               var text = $( this ).text();
+                               var value = $( this ).val();
+                               var term = split( request.term ).pop();
+                               if ( this.value && ( !request.term || 
matcher.test(text) ) )
+                                       return {
+                                       label: text.replace(
+                                               new RegExp(
+                                               "(?![^&;]+;)(?!<[^<>]*)(" +
+                                               
$.ui.autocomplete.escapeRegex(term) +
+                                               ")(?![^<>]*>)(?![^&;]+;)", "gi"
+                                               ), "<strong>$1</strong>" ),
+                                       value: value,
+                                       option: this
+                                       };
+                               }) );
+                       },
+                       select: function( event, ui ) {
+                               ui.item.option.selected = true;
+                               self._trigger( "selected", event, {
+                                       item: ui.item.option
+                               });
+                               var terms = split( $(this).val() );
+                               // remove the current input
+                               terms.pop();
+                               // add the selected item
+                               terms.push( ui.item.value );
+                               // add placeholder to get the comma-and-space 
at the end
+                               terms.push( "" );
+                               $( this ).val( terms.join( ", " ) );
+                               return false;
+                       }
+                       
+                       });
+
+               input.data( "autocomplete" )._renderItem = function( ul, item ) 
{
+                       return $( "<li></li>" )
+                       .data( "item.autocomplete", item )
+                       .append( "<a>" + item.label + "</a>" )
+                       .appendTo( ul );
+               };
+
+               },
+
+               destroy: function() {
+                       this.input.remove();
+                       this.element.show();
+                       $.Widget.prototype.destroy.call( this );
+               }
+       });
+
+       $( "#wpUserLanguage" ).combobox();
+} );


Property changes on: 
trunk/extensions/Translate/resources/ext.translate.special.pagetranslation.js
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/extensions/Translate/tag/SpecialPageTranslation.php
===================================================================
--- trunk/extensions/Translate/tag/SpecialPageTranslation.php   2012-02-29 
05:07:53 UTC (rev 112667)
+++ trunk/extensions/Translate/tag/SpecialPageTranslation.php   2012-02-29 
05:33:05 UTC (rev 112668)
@@ -70,6 +70,7 @@
                        $wgOut->addWikiMsg( 'tpt-nosuchpage', 
$title->getPrefixedText() );
                        return;
                }
+               $wgOut->addModules( 'ext.translate.special.pagetranslation' );
 
                if ( $action === 'discourage' || $action === 'encourage' ) {
                        $id = TranslatablePage::getMessageGroupIdFromTitle( 
$title );
@@ -528,6 +529,22 @@
                        }
                }
 
+               $priorityLangs = TranslateMetadata::get( 
$page->getMessageGroupId(), 'prioritylangs' );
+               $priorityForce = TranslateMetadata::get( 
$page->getMessageGroupId(), 'priorityforce' );
+               $priorityReason = TranslateMetadata::get( 
$page->getMessageGroupId(), 'priorityreason' );
+               $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-prioritylangs' );
+               $langSelector = Xml::languageSelector( $wgContLang-> getCode() 
);
+               $priorityLangsInput = Html::element( 'input', array( 'id' => 
'tpt-prioritylangs', 'size' => '50', 'name' => 'prioritylangs', 'value' => 
$priorityLangs , ) );
+               if ( $priorityForce === 'on' ) {
+                       $forceLimit = Html::element( 'input', array( 'id' => 
'tpt-priority-forcelimit', 'type' => 'checkbox', 'name' => 'forcelimit', 
'checked' => 'checked' )  );
+               } else {
+               $forceLimit = Html::element( 'input', array( 'id' => 
'tpt-priority-forcelimit', 'type' => 'checkbox', 'name' => 'forcelimit' ) );
+               }
+               $priorityReasonTextArea = Html::element( 'textarea', array( 
'id' => 'tpt-priority-reason', 'name' => 'priorityreason' ), $priorityReason  );
+               $forceLimitLabel = Html::element( 'label', array( 'id' => 
'tpt-priority-forcelimit-label', 'for' => 'tpt-priority-forcelimit' ), 
wfMsgHtml( 'tpt-select-prioritylangs-force' ) );
+               $wgOut->addHTML( wfMsgHtml( 'tpt-select-prioritylangs' ) . 
$langSelector[1] . $priorityLangsInput );
+               $wgOut->addHTML( '<br/>' . $forceLimit . $forceLimitLabel . 
'<br/>' . wfMsgHtml( 'tpt-select-prioritylangs-reason' ) . 
$priorityReasonTextArea . '<br/>' );
+
                $wgOut->addHTML(
                        Xml::submitButton( wfMsg( 'tpt-submit' ) ) .
                        Xml::closeElement( 'form' )
@@ -619,6 +636,11 @@
                $page->addMarkedTag( $newrevision, $changed );
                $this->addFuzzyTags( $page, $changed );
 
+               // Save the priority languages if any
+               $priorityLangs = trim( $wgRequest->getVal( 'prioritylangs' ) );
+               $priorityForce = $wgRequest->getVal( 'forcelimit' );
+               $priorityReason = $wgRequest->getVal( 'priorityreason' );
+
                global $wgUser;
                $logger = new LogPage( 'pagetranslation' );
                $params = array(
@@ -627,6 +649,24 @@
                        'changed' => count( $changed ),
                );
                $logger->addEntry( 'mark', $page->getTitle(), null, array( 
serialize( $params ) ) );
+               if (  $priorityLangs ) {
+                       $groupId = $page->getMessageGroupId();
+                       TranslateMetadata::set( $groupId, 'prioritylangs', 
trim( $priorityLangs, ',' ) );
+                       if ( $priorityForce ) {
+                               TranslateMetadata::set( $groupId, 
'priorityforce', $priorityForce );
+                       } else {
+                               TranslateMetadata::set( $groupId, 
'priorityforce', 'off' );
+                       }
+                       if ( trim( $priorityReason ) ) {
+                               TranslateMetadata::set( $groupId, 
'priorityreason', $priorityReason );
+                       }
+                       $params = array(
+                               'user' => $wgUser->getName(),
+                               'languages' => $priorityLangs,
+                               'force' => $priorityForce,
+                       );
+                       $logger->addEntry( 'prioritylanguages', 
$page->getTitle(), null, array( serialize( $params ) ) );
+               }
 
                $page->getTitle()->invalidateCache();
                $this->setupRenderJobs( $page );


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

Reply via email to