r113615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113614‎ | r113615 | r113616 >
Date:11:00, 12 March 2012
Author:santhosh
Status:resolved
Tags:i18nreview 
Comment:
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 (modified) (history)
  • /trunk/extensions/Translate/api/ApiAggregateGroups.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialAggregateGroups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/api/ApiAggregateGroups.php
@@ -38,6 +38,7 @@
3939 $aggregateGroups = array_unique( $aggregateGroups );
4040 $newSubGroups = implode( ',', $aggregateGroups );
4141 TranslateMetadata::set( $aggregateGroup, 'subgroups' , $newSubGroups ) ;
 42+ MessageGroups::clearCache();
4243 }
4344 if ( $requestParams['do'] === 'dissociate' ) {
4445 $group = $requestParams['group'];
@@ -48,11 +49,13 @@
4950 }
5051 $aggregateGroups = array_flip( $aggregateGroups );
5152 TranslateMetadata::set( $aggregateGroup, 'subgroups' , implode( ',', $aggregateGroups ) ) ;
 53+ MessageGroups::clearCache();
5254 }
5355 if ( $requestParams['do'] === 'remove' ) {
5456 TranslateMetadata::set( $aggregateGroup, 'subgroups', false ) ;
5557 TranslateMetadata::set( $aggregateGroup, 'name', false ) ;
5658 TranslateMetadata::set( $aggregateGroup, 'description', false ) ;
 59+ MessageGroups::clearCache();
5760 }
5861 if ( $requestParams['do'] === 'add' ) {
5962 TranslateMetadata::set( $aggregateGroup, 'subgroups' , '' ) ;
@@ -62,6 +65,7 @@
6366 if ( trim( $requestParams['groupdescription'] ) ) {
6467 TranslateMetadata::set( $aggregateGroup, 'description' , trim( $requestParams['groupdescription'] ) ) ;
6568 }
 69+ MessageGroups::clearCache();
6670 }
6771 $output = array( 'result' => 'ok' );
6872 $this->getResult()->addValue( null, $this->getModuleName(), $output );
@@ -79,7 +83,6 @@
8084 }
8185
8286 public function getAllowedParams() {
83 - global $wgTranslateWorkflowStates;
8487 return array(
8588 'do' => array(
8689 ApiBase::PARAM_TYPE => array( 'associate', 'dissociate', 'remove' , 'add' ),
@@ -116,32 +119,6 @@
117120 );
118121 }
119122
120 - public static function getAggregateGroups() {
121 - $dbr = wfGetDB( DB_MASTER );
122 - $tables = array( 'translate_metadata' );
123 - $vars = array( 'tmd_group', 'tmd_value' );
124 - $conds = array(
125 - 'tmd_key' => 'subgroups',
126 - );
127 - $options = array(
128 - 'ORDER BY' => 'tmd_group',
129 - );
130 - $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
131 - $aggregateGroups = array();
132 - foreach ( $res as $r ) {
133 - $aggregateGroups[$r->tmd_group] = array();
134 - $aggregateGroups[$r->tmd_group]['id'] = $r->tmd_group;
135 - $aggregateGroups[$r->tmd_group]['name'] = TranslateMetadata::get( $r->tmd_group, 'name' );
136 - $aggregateGroups[$r->tmd_group]['description'] = TranslateMetadata::get( $r->tmd_group, 'description' );
137 - $subGroupsArray = explode( ',', $r->tmd_value ) ;
138 - $subGroups = array();
139 - foreach ( $subGroupsArray as $subGroup ) {
140 - $subGroups[$subGroup] = MessageGroups::getGroup( trim( $subGroup ) );
141 - }
142 - $aggregateGroups[$r->tmd_group]['subgroups'] = $subGroups ;
143 - }
144 - return $aggregateGroups;
145 - }
146123
147124 public function getDescription() {
148125 return 'Manage aggregate groups';
Index: trunk/extensions/Translate/specials/SpecialAggregateGroups.php
@@ -81,7 +81,7 @@
8282 global $wgOut;
8383 $wgOut->addModules( 'ext.translate.special.aggregategroups' );
8484
85 - $aggregategroups = ApiAggregateGroups::getAggregateGroups( );
 85+ $aggregategroups = MessageGroups::getAggregateGroups( );
8686 $res = $this->loadPagesFromDB();
8787 $pages = $this->buildPageArray( $res );
8888 foreach ( $aggregategroups as $id => $group ) {
Index: trunk/extensions/Translate/MessageGroups.php
@@ -1167,6 +1167,21 @@
11681168 }
11691169 }
11701170
 1171+ $aggregategroups = self::getAggregateGroups( );
 1172+ foreach ( $aggregategroups as $id => $group ) {
 1173+ $conf = array();
 1174+ $conf['BASIC'] = array();
 1175+ $conf['BASIC']['id'] = $id;
 1176+ $conf['BASIC']['label'] = $group['name'];
 1177+ $conf['BASIC']['meta'] = 1;
 1178+ $conf['BASIC']['class'] = 'AggregateMessageGroup';
 1179+ $conf['BASIC']['description'] = $group['description'];
 1180+ $conf['BASIC']['namespace'] = 'NS_TRANSLATIONS';
 1181+ $subgroups = explode( ',', TranslateMetadata::get( $id, 'subgroups' ) ) ;
 1182+ $conf['GROUPS'] = $subgroups;
 1183+ $group = MessageGroupBase::factory( $conf );
 1184+ $wgTranslateCC[$id] = $group;
 1185+ }
11711186 $key = wfMemckey( 'translate-groups' );
11721187 $value = array(
11731188 'ac' => $wgTranslateAC,
@@ -1497,6 +1512,37 @@
14981513 array_unshift( $tree, $parent );
14991514 return $tree;
15001515 }
 1516+
 1517+ /*
 1518+ * Get all the aggregate groups defined in translate_metadata table, along with
 1519+ * subgroups as MessageGroup objects.
 1520+ */
 1521+ public static function getAggregateGroups() {
 1522+ $dbr = wfGetDB( DB_MASTER );
 1523+ $tables = array( 'translate_metadata' );
 1524+ $vars = array( 'tmd_group', 'tmd_value' );
 1525+ $conds = array(
 1526+ 'tmd_key' => 'subgroups',
 1527+ );
 1528+ $options = array(
 1529+ 'ORDER BY' => 'tmd_group',
 1530+ );
 1531+ $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
 1532+ $aggregateGroups = array();
 1533+ foreach ( $res as $r ) {
 1534+ $aggregateGroups[$r->tmd_group] = array();
 1535+ $aggregateGroups[$r->tmd_group]['id'] = $r->tmd_group;
 1536+ $aggregateGroups[$r->tmd_group]['name'] = TranslateMetadata::get( $r->tmd_group, 'name' );
 1537+ $aggregateGroups[$r->tmd_group]['description'] = TranslateMetadata::get( $r->tmd_group, 'description' );
 1538+ $subGroupsArray = explode( ',', $r->tmd_value ) ;
 1539+ $subGroups = array();
 1540+ foreach ( $subGroupsArray as $subGroup ) {
 1541+ $subGroups[$subGroup] = MessageGroups::getGroup( trim( $subGroup ) );
 1542+ }
 1543+ $aggregateGroups[$r->tmd_group]['subgroups'] = $subGroups ;
 1544+ }
 1545+ return $aggregateGroups;
 1546+ }
15011547
15021548 }
15031549

Follow-up revisions

RevisionCommit summaryAuthorDate
r113622Cleanup pass for my pedantic mind :)...nikerabbit13:12, 12 March 2012

Status & tagging log