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

Revision: 113709
Author:   santhosh
Date:     2012-03-13 06:32:41 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
create the groupdId by more better.
While adding a new group, check whether it exists or not.

Modified Paths:
--------------
    trunk/extensions/Translate/api/ApiAggregateGroups.php
    
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js

Modified: trunk/extensions/Translate/api/ApiAggregateGroups.php
===================================================================
--- trunk/extensions/Translate/api/ApiAggregateGroups.php       2012-03-13 
05:08:42 UTC (rev 113708)
+++ trunk/extensions/Translate/api/ApiAggregateGroups.php       2012-03-13 
06:32:41 UTC (rev 113709)
@@ -66,7 +66,10 @@
                        TranslateMetadata::set( $aggregateGroup, 'name', false 
) ;
                        TranslateMetadata::set( $aggregateGroup, 'description', 
false ) ;
                } elseif ( $action === 'add' ) {
-                       // @FIXME: check that the group id unused and valid 
(like, no commas)
+                       if ( TranslateMetadata::get( $aggregateGroup, 
'subgroups') ) {
+                               $this->dieUsage( 'Aggregate Group aleady 
exists', 'duplicateaggregategroup' );
+                       }
+                       // @FIXME: check that the group id is valid (like, no 
commas)
                        TranslateMetadata::set( $aggregateGroup, 'subgroups', 
'' ) ;
                        $name = trim( $params['groupname'] );
                        $desc = trim( $params['groupdescription'] );

Modified: 
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js
===================================================================
--- 
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js   
    2012-03-13 05:08:42 UTC (rev 113708)
+++ 
trunk/extensions/Translate/resources/ext.translate.special.aggregategroups.js   
    2012-03-13 06:32:41 UTC (rev 113709)
@@ -91,6 +91,15 @@
                var params = $.extend( getApiParams( $target ), {'do' : 
'remove' } );
                $.post( mw.util.wikiScript( 'api' ), params, successFunction );
        }
+       
+       /*
+        * Replace some special characters like space, comma, brackets etc to _ 
in a string. Also convert it to lowercase.
+        */
+       function createId( s ){
+               if ( s !== undefined ) {
+                       return s.toLowerCase().replace( 
/[\x00-\x1f\x23\x2c\x3c\x3e\x5b\x5d\x7b\x7c\x7d\x7f\s]+/g, '_' );
+               }
+       }
 
        $( '.tp-aggregate-add-button' ).click( associate );
        $( '.tp-aggregate-remove-button' ).click( dissociate );
@@ -101,7 +110,7 @@
        } );
 
        $( '#tpt-aggregategroups-save' ). on ( "click", function( event ){
-               var aggregateGroup = $( 'input.tp-aggregategroup-add-name' 
).val().toLowerCase().replace( ' ', '_');
+               var aggregateGroup = createId( $( 
'input.tp-aggregategroup-add-name' ).val() );
                var aggregateGroupName = $( 'input.tp-aggregategroup-add-name' 
).val();
                var aggregateGroupDesc = $( 
'input.tp-aggregategroup-add-description' ).val();
                var $select = $( 'select.tp-aggregate-group-chooser' );


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

Reply via email to