r112588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112587‎ | r112588 | r112589 >
Date:11:55, 28 February 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Fix statistics tables for aggregate group numbers.
Use hooks to consolidate the logic in one place.
Remaining problem is the number of queries done.
We need some kind of batch queries here.
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateHooks.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageGroupStats.php (modified) (history)
  • /trunk/extensions/Translate/utils/StatsTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -1240,7 +1240,7 @@
12411241 * @return string
12421242 * @since 2011-12-12
12431243 */
1244 - public static function getPriority( MessageGroup $group ) {
 1244+ public static function getPriority( $group ) {
12451245 static $groups = null;
12461246 if ( $groups === null ) {
12471247 $groups = array();
@@ -1255,7 +1255,11 @@
12561256 }
12571257 }
12581258
1259 - $id = $group->getId();
 1259+ if ( $group instanceof MessageGroup ) {
 1260+ $id = $group->getId();
 1261+ } else {
 1262+ $id = $group;
 1263+ }
12601264 return isset( $groups[$id] ) ? $groups[$id] : '';
12611265 }
12621266
Index: trunk/extensions/Translate/Translate.php
@@ -137,6 +137,10 @@
138138
139139 $wgHooks['LinkBegin'][] = 'SpecialMyLanguage::linkfix';
140140
 141+// Stats table manipulation
 142+$wgHooks['Translate:MessageGroupStats:isIncluded'][] = 'TranslateHooks::hideDiscouragedFromStats';
 143+$wgHooks['Translate:MessageGroupStats:isIncluded'][] = 'TranslateHooks::hideRestrictedFromStats';
 144+
141145 // New rights
142146 $wgAvailableRights[] = 'translate';
143147 $wgAvailableRights[] = 'translate-import';
Index: trunk/extensions/Translate/TranslateHooks.php
@@ -390,5 +390,24 @@
391391 return true;
392392 }
393393
 394+ /// Hook: Translate:MessageGroupStats:isIncluded
 395+ public static function hideDiscouragedFromStats( $id, $code ) {
 396+ // Return true to keep, false to exlude
 397+ return MessageGroups::getPriority( $id ) !== 'discouraged';
 398+ }
 399+
 400+ /// Hook: Translate:MessageGroupStats:isIncluded
 401+ public static function hideRestrictedFromStats( $id, $code ) {
 402+ $filterLangs = TranslateMetadata::get( $id, 'prioritylangs' );
 403+ if ( strlen( $filterLangs ) === 0 ) {
 404+ // No restrictions, keep everything
 405+ return true;
 406+ }
 407+
 408+ $filter = array_flip( explode( ',', $filterLangs ) );
 409+ // If the language is in the list, return true to not hide it
 410+ return isset( $filter[$code] );
 411+ }
 412+
394413 }
395414
Index: trunk/extensions/Translate/utils/StatsTable.php
@@ -299,13 +299,11 @@
300300 }
301301 }
302302
303 - $filterLangs = TranslateMetadata::get( $groupId , 'prioritylangs' );
304 - if ( strlen( $filterLangs ) > 0 ) {
305 - $filter = array_flip( explode( ',', $filterLangs ) );
306 - if ( count( $filter ) > 0 && !isset( $filter[$code] ) ) {
307 - $blacklisted = true;
308 - }
 303+ $include = wfRunHooks( 'Translate:MessageGroupStats:isIncluded', array( $groupId, $code ) );
 304+ if ( !$include ) {
 305+ $blacklisted = true;
309306 }
 307+
310308 return $blacklisted;
311309 }
312310
Index: trunk/extensions/Translate/utils/MessageGroupStats.php
@@ -257,7 +257,9 @@
258258 if ( !isset( $stats[$sid][$code] ) ) {
259259 $stats[$sid][$code] = self::forItemInternal( $stats, $subgroup, $code );
260260 }
261 - if ( MessageGroups::getPriority( $subgroup ) !== 'discouraged' ) {
 261+
 262+ $include = wfRunHooks( 'Translate:MessageGroupStats:isIncluded', array( $sid, $code ) );
 263+ if ( $include ) {
262264 $aggregates = self::multiAdd( $aggregates, $stats[$sid][$code] );
263265 }
264266 }
Index: trunk/extensions/Translate/specials/SpecialLanguageStats.php
@@ -362,12 +362,6 @@
363363 return '';
364364 }
365365
366 - # These are hidden, and the code in MessageGroupStats makes sure that
367 - # these are not counted in the aggregate groups they may belong.
368 - if ( MessageGroups::getPriority( $group ) === 'discouraged' ) {
369 - return '';
370 - }
371 -
372366 $stats = $cache[$groupId];
373367
374368 list( $total, $translated, $fuzzy ) = $stats;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112574If priority languages are defined for a group, do not show other languages in...santhosh04:28, 28 February 2012

Status & tagging log