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

Revision: 113615
Author:   santhosh
Date:     2012-03-12 11:00:34 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
Use the aggregate groups in translate_metadata table for showing the group 
structure in Translate special pages.
-Add the aggregate groups to the groups information cache
-clear cache when group structure changed using Special:AggregateGroups
-minor code cleanup

Modified Paths:
--------------
    trunk/extensions/Translate/MessageGroups.php
    trunk/extensions/Translate/api/ApiAggregateGroups.php
    trunk/extensions/Translate/specials/SpecialAggregateGroups.php

Modified: trunk/extensions/Translate/MessageGroups.php
===================================================================
--- trunk/extensions/Translate/MessageGroups.php        2012-03-12 09:06:30 UTC 
(rev 113614)
+++ trunk/extensions/Translate/MessageGroups.php        2012-03-12 11:00:34 UTC 
(rev 113615)
@@ -1167,6 +1167,21 @@
                        }
                }
 
+               $aggregategroups = self::getAggregateGroups( );
+               foreach ( $aggregategroups as $id => $group ) {
+                       $conf = array();
+                       $conf['BASIC'] = array();
+                       $conf['BASIC']['id'] =   $id;
+                       $conf['BASIC']['label'] =  $group['name'];
+                       $conf['BASIC']['meta'] = 1;
+                       $conf['BASIC']['class'] = 'AggregateMessageGroup';
+                       $conf['BASIC']['description'] = $group['description'];
+                       $conf['BASIC']['namespace'] = 'NS_TRANSLATIONS';
+                       $subgroups = explode( ',', TranslateMetadata::get( $id, 
'subgroups' ) ) ;
+                       $conf['GROUPS'] = $subgroups;
+                       $group = MessageGroupBase::factory( $conf );
+                       $wgTranslateCC[$id] = $group;
+               }
                $key = wfMemckey( 'translate-groups' );
                $value = array(
                        'ac' => $wgTranslateAC,
@@ -1497,6 +1512,37 @@
                array_unshift( $tree, $parent );
                return $tree;
        }
+       
+       /*
+        * Get all the aggregate groups defined in translate_metadata table, 
along with
+        * subgroups as MessageGroup objects.
+        */
+       public static function getAggregateGroups() {
+               $dbr = wfGetDB( DB_MASTER );
+               $tables = array( 'translate_metadata' );
+               $vars = array( 'tmd_group', 'tmd_value' );
+               $conds = array(
+                       'tmd_key' => 'subgroups',
+               );
+               $options = array(
+                       'ORDER BY' => 'tmd_group',
+               );
+               $res = $dbr->select( $tables, $vars, $conds, __METHOD__, 
$options );
+               $aggregateGroups = array();
+               foreach ( $res as $r ) {
+                       $aggregateGroups[$r->tmd_group] = array();
+                       $aggregateGroups[$r->tmd_group]['id'] = $r->tmd_group;
+                       $aggregateGroups[$r->tmd_group]['name'] = 
TranslateMetadata::get( $r->tmd_group, 'name' );
+                       $aggregateGroups[$r->tmd_group]['description'] = 
TranslateMetadata::get( $r->tmd_group, 'description' );
+                       $subGroupsArray = explode( ',', $r->tmd_value ) ;
+                       $subGroups = array();
+                       foreach ( $subGroupsArray as $subGroup ) {
+                               $subGroups[$subGroup] = 
MessageGroups::getGroup( trim( $subGroup ) );
+                       }
+                       $aggregateGroups[$r->tmd_group]['subgroups'] = 
$subGroups ;
+               }
+               return $aggregateGroups;
+       }
 
 }
 

Modified: trunk/extensions/Translate/api/ApiAggregateGroups.php
===================================================================
--- trunk/extensions/Translate/api/ApiAggregateGroups.php       2012-03-12 
09:06:30 UTC (rev 113614)
+++ trunk/extensions/Translate/api/ApiAggregateGroups.php       2012-03-12 
11:00:34 UTC (rev 113615)
@@ -38,6 +38,7 @@
                        $aggregateGroups = array_unique( $aggregateGroups );
                        $newSubGroups =  implode( ',', $aggregateGroups );
                        TranslateMetadata::set( $aggregateGroup, 'subgroups' , 
$newSubGroups ) ;
+                       MessageGroups::clearCache();
                }
                if ( $requestParams['do'] === 'dissociate' ) {
                        $group = $requestParams['group'];
@@ -48,11 +49,13 @@
                        }
                        $aggregateGroups = array_flip( $aggregateGroups );
                        TranslateMetadata::set( $aggregateGroup, 'subgroups' , 
implode( ',', $aggregateGroups ) ) ;
+                       MessageGroups::clearCache();
                }
                if ( $requestParams['do'] === 'remove' ) {
                        TranslateMetadata::set( $aggregateGroup, 'subgroups', 
false ) ;
                        TranslateMetadata::set( $aggregateGroup, 'name', false 
) ;
                        TranslateMetadata::set( $aggregateGroup, 'description', 
false ) ;
+                       MessageGroups::clearCache();
                }
                if ( $requestParams['do'] === 'add' ) {
                        TranslateMetadata::set( $aggregateGroup, 'subgroups' , 
'' ) ;
@@ -62,6 +65,7 @@
                        if ( trim( $requestParams['groupdescription'] ) ) {
                                TranslateMetadata::set( $aggregateGroup, 
'description' , trim( $requestParams['groupdescription'] ) ) ;
                        }
+                       MessageGroups::clearCache();
                }
                $output = array( 'result' => 'ok' );
                $this->getResult()->addValue( null, $this->getModuleName(), 
$output );
@@ -79,7 +83,6 @@
        }
 
        public function getAllowedParams() {
-               global $wgTranslateWorkflowStates;
                return array(
                        'do' => array(
                                ApiBase::PARAM_TYPE => array( 'associate', 
'dissociate', 'remove' , 'add' ),
@@ -116,32 +119,6 @@
                );
        }
 
-       public static function getAggregateGroups() {
-               $dbr = wfGetDB( DB_MASTER );
-               $tables = array( 'translate_metadata' );
-               $vars = array( 'tmd_group', 'tmd_value' );
-               $conds = array(
-                       'tmd_key' => 'subgroups',
-               );
-               $options = array(
-                       'ORDER BY' => 'tmd_group',
-               );
-               $res = $dbr->select( $tables, $vars, $conds, __METHOD__, 
$options );
-               $aggregateGroups = array();
-               foreach ( $res as $r ) {
-                       $aggregateGroups[$r->tmd_group] = array();
-                       $aggregateGroups[$r->tmd_group]['id'] = $r->tmd_group;
-                       $aggregateGroups[$r->tmd_group]['name'] = 
TranslateMetadata::get( $r->tmd_group, 'name' );
-                       $aggregateGroups[$r->tmd_group]['description'] = 
TranslateMetadata::get( $r->tmd_group, 'description' );
-                       $subGroupsArray = explode( ',', $r->tmd_value ) ;
-                       $subGroups = array();
-                       foreach ( $subGroupsArray as $subGroup ) {
-                               $subGroups[$subGroup] = 
MessageGroups::getGroup( trim( $subGroup ) );
-                       }
-                       $aggregateGroups[$r->tmd_group]['subgroups'] = 
$subGroups ;
-               }
-               return $aggregateGroups;
-       }
 
        public function getDescription() {
                return 'Manage aggregate groups';

Modified: trunk/extensions/Translate/specials/SpecialAggregateGroups.php
===================================================================
--- trunk/extensions/Translate/specials/SpecialAggregateGroups.php      
2012-03-12 09:06:30 UTC (rev 113614)
+++ trunk/extensions/Translate/specials/SpecialAggregateGroups.php      
2012-03-12 11:00:34 UTC (rev 113615)
@@ -81,7 +81,7 @@
                global $wgOut;
                $wgOut->addModules( 'ext.translate.special.aggregategroups' );
 
-               $aggregategroups = ApiAggregateGroups::getAggregateGroups( );
+               $aggregategroups = MessageGroups::getAggregateGroups( );
                $res = $this->loadPagesFromDB();
                $pages = $this->buildPageArray( $res );
                foreach ( $aggregategroups as $id => $group ) {


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

Reply via email to