r107485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107484‎ | r107485 | r107486 >
Date:12:40, 28 December 2011
Author:amire80
Status:ok
Tags:
Comment:
Follow up to r107387. Renamed functions: workflowStatesColumn -> addWorkflowStatesColumn, workflowStateCell -> getWorkflowStateCell. Changes to function getWorkflowStates: made it non-static; eliminated the parameter, using $this->target instead; selecting language states by group or group states by language, according to targetValueName.
Modified paths:
  • /trunk/extensions/Translate/specials/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMessageGroupStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php
@@ -107,7 +107,7 @@
108108 function getTable() {
109109 $table = $this->table;
110110
111 - $this->workflowStatesColumn();
 111+ $this->addWorkflowStatesColumn();
112112 $out = '';
113113
114114 if ( $this->purge ) {
@@ -173,7 +173,7 @@
174174 $out = "\t" . Html::openElement( 'tr' );
175175 $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra );
176176 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
177 - $out .= $this->workflowStateCell( $code );
 177+ $out .= $this->getWorkflowStateCell( $code );
178178
179179 $out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
180180 return $out;
Index: trunk/extensions/Translate/specials/SpecialLanguageStats.php
@@ -231,10 +231,10 @@
232232 /**
233233 * If workflow states are configured, adds a workflow states column
234234 */
235 - function workflowStatesColumn() {
 235+ function addWorkflowStatesColumn() {
236236 global $wgTranslateWorkflowStates;
237237 if ( $wgTranslateWorkflowStates ) {
238 - $this->states = self::getWorkflowStates( $this->target );
 238+ $this->states = self::getWorkflowStates();
239239 $this->statemap = array_flip( $wgTranslateWorkflowStates );
240240 $this->table->addExtraColumn( wfMessage( 'translate-stats-workflow' ) );
241241 }
@@ -244,13 +244,13 @@
245245
246246 /**
247247 * If workflow states are configured, adds a cell with the workflow state to the row,
248 - * @param $code Language code
 248+ * @param $target Whose workflow state do we want, such as language code or group id.
249249 * @return string
250250 */
251 - function workflowStateCell( $code ) {
 251+ function getWorkflowStateCell( $target ) {
252252 global $wgTranslateWorkflowStates;
253253 if ( $wgTranslateWorkflowStates ) {
254 - $state = isset( $this->states[$code] ) ? $this->states[$code] : '';
 254+ $state = isset( $this->states[$target] ) ? $this->states[$target] : '';
255255 $sort = isset( $this->statemap[$state] ) ? $this->statemap[$state] + 1 : -1;
256256 $stateMessage = wfMessage( "translate-workflow-state-$state" );
257257 $stateText = $stateMessage->isBlank() ? $state : $stateMessage->text();
@@ -271,7 +271,7 @@
272272 function getTable() {
273273 $table = $this->table;
274274
275 - $this->workflowStatesColumn();
 275+ $this->addWorkflowStatesColumn();
276276 $out = '';
277277
278278 if ( $this->purge ) {
@@ -333,7 +333,9 @@
334334 * @return string
335335 */
336336 protected function makeGroupRow( $group, $cache, $parent = false ) {
337 - if ( $this->table->isBlacklisted( $group->getId(), $this->target ) !== null ) {
 337+ $groupId = $group->getId();
 338+
 339+ if ( $this->table->isBlacklisted( $groupId, $this->target ) !== null ) {
338340 return '';
339341 }
340342
@@ -343,7 +345,7 @@
344346 return '';
345347 }
346348
347 - $stats = $cache[$group->getId()];
 349+ $stats = $cache[$groupId];
348350
349351 list( $total, $translated, $fuzzy ) = $stats;
350352 if ( $total === null ) {
@@ -370,7 +372,7 @@
371373 }
372374
373375 $rowParams = array();
374 - $rowParams['data-groupid'] = $group->getId();
 376+ $rowParams['data-groupid'] = $groupId;
375377 if ( is_string( $parent ) ) {
376378 $rowParams['data-parentgroups'] = $parent;
377379 } elseif ( $parent === true ) {
@@ -381,22 +383,35 @@
382384 $out .= "\n\t\t" . Html::rawElement( 'td', array(),
383385 $this->table->makeGroupLink( $group, $this->target, $extra ) );
384386 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
 387+ $out .= $this->getWorkflowStateCell( $groupId );
385388
386389 $out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
387390 return $out;
388391 }
389392
390 - protected static function getWorkflowStates( $group ) {
 393+ protected function getWorkflowStates() {
391394 $db = wfGetDB( DB_SLAVE );
 395+
 396+ switch ( $this->targetValueName ) {
 397+ case 'group':
 398+ $targetCol = 'tgr_group';
 399+ $selectKey = 'tgr_lang';
 400+ break;
 401+ case 'code':
 402+ $targetCol = 'tgr_lang';
 403+ $selectKey = 'tgr_group';
 404+ break;
 405+ }
 406+
392407 $res = $db->select(
393408 'translate_groupreviews',
394 - array( 'tgr_state', 'tgr_lang' ),
395 - array( 'tgr_group' => $group ),
 409+ array( 'tgr_state', $selectKey ),
 410+ array( $targetCol => $this->target ),
396411 __METHOD__
397412 );
398413 $states = array();
399414 foreach ( $res as $row ) {
400 - $states[$row->tgr_lang] = $row->tgr_state;
 415+ $states[$row->$selectKey] = $row->tgr_state;
401416 }
402417 return $states;
403418 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107387Refactored the code for adding workflow states column and cells. Added workfl...amire8015:44, 27 December 2011

Status & tagging log