r101816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101815‎ | r101816 | r101817 >
Date:14:44, 3 November 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Display workflow status in Special:MessageGroupStats if enabled
Internationalization/#187 Internationalization/#189
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.special.languagestats.js (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMessageGroupStats.php (modified) (history)
  • /trunk/extensions/Translate/utils/StatsTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/StatsTable.php
@@ -27,6 +27,8 @@
2828 protected $translate;
2929 /// @var string
3030 protected $mainColumnHeader;
 31+ /// @var array
 32+ protected $extraColumns = array();
3133
3234 public function __construct() {
3335 global $wgLang;
@@ -45,7 +47,10 @@
4648 public function element( $in, $bgcolor = '', $sort = '' ) {
4749 $attributes = array();
4850 if ( $sort ) $attributes['data-sort-value'] = $sort;
49 - if ( $bgcolor ) $attributes['style'] = "background-color: #" . $bgcolor;
 51+ if ( $bgcolor ) {
 52+ $attributes['style'] = "background-color: #" . $bgcolor;
 53+ $attributes['class'] = 'hover-color';
 54+ }
5055
5156 $element = Html::element( 'td', $attributes, $in );
5257 return $element;
@@ -87,6 +92,19 @@
8893 return Html::element( 'th', array(), $msg->text() );
8994 }
9095
 96+ public function addExtraColumn( Message $column ) {
 97+ $this->extraColumns[] = $column;
 98+ }
 99+
 100+ public function getOtherColumnHeaders() {
 101+ return array_merge( array(
 102+ wfMessage( 'translate-total' ),
 103+ wfMessage( 'translate-untranslated' ),
 104+ wfMessage( 'translate-percentage-complete' ),
 105+ wfMessage( 'translate-percentage-fuzzy' ),
 106+ ), $this->extraColumns );
 107+ }
 108+
91109 public function createHeader() {
92110 // Create table header
93111 $out = Html::openElement(
@@ -98,14 +116,9 @@
99117 $out .= "\n\t" . Html::openElement( 'tr' );
100118
101119 $out .= "\n\t\t" . $this->getMainColumnHeader();
102 - $out .= "\n\t\t" . $this->createColumnHeader(
103 - wfMessage( 'translate-total' ) );
104 - $out .= "\n\t\t" . $this->createColumnHeader(
105 - wfMessage( 'translate-untranslated' ) );
106 - $out .= "\n\t\t" . $this->createColumnHeader(
107 - wfMessage( 'translate-percentage-complete' ) );
108 - $out .= "\n\t\t" . $this->createColumnHeader(
109 - wfMessage( 'translate-percentage-fuzzy' ) );
 120+ foreach ( $this->getOtherColumnHeaders() as $label ) {
 121+ $out .= "\n\t\t" . $this->createColumnHeader( $label );
 122+ }
110123 $out .= "\n\t" . Html::closeElement( 'tr' );
111124 $out .= "\n\t" . Html::closeElement( 'thead' );
112125 $out .= "\n\t" . Html::openElement( 'tbody' );
@@ -124,6 +137,7 @@
125138 $out = "\t" . Html::openElement( 'tr' );
126139 $out .= "\n\t\t" . Html::element( 'td', array(), $message->text() );
127140 $out .= $this->makeNumberColumns( $fuzzy, $translated, $total );
 141+ $out .= "\n\t" . Xml::closeElement( 'tr' ) . "\n";
128142 return $out;
129143 }
130144
@@ -139,7 +153,6 @@
140154 $na = "\n\t\t" . Html::element( 'td', array( 'data-sort-value' => -1 ), '...' );
141155 $nap = "\n\t\t" . $this->element( '...', 'AFAFAF', -1 );
142156 $out = $na . $na . $nap . $nap;
143 - $out .= "\n\t" . Xml::closeElement( 'tr' ) . "\n";
144157 return $out;
145158 }
146159
@@ -158,8 +171,6 @@
159172 $out .= "\n\t\t" . $this->element( $this->formatPercentage( $fuzzy / $total ),
160173 $this->getBackgroundColour( $fuzzy, $total, true ),
161174 sprintf( '%1.5f', $fuzzy / $total ) );
162 -
163 - $out .= "\n\t" . Xml::closeElement( 'tr' ) . "\n";
164175 return $out;
165176 }
166177
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -402,7 +402,7 @@
403403 'translate-workflow-set-do' => 'Set',
404404 'translate-workflow-set-doing' => 'Setting...',
405405 'translate-workflow-set-done' => 'Set!',
406 -
 406+ 'translate-stats-workflow' => 'Status',
407407 );
408408
409409 /** Message documentation (Message documentation)
@@ -631,6 +631,7 @@
632632 'translate-workflow-set-do' => 'Submit button text when active',
633633 'translate-workflow-set-doing' => 'Submit button text when waiting for reply from server',
634634 'translate-workflow-set-done' => 'Submit button text when submission completed succesfully',
 635+ 'translate-stats-workflow' => 'Column header on Special:LanguageStats and Special:MessageGroupStats',
635636 );
636637
637638 /** Faeag Rotuma (Faeag Rotuma)
Index: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php
@@ -106,6 +106,13 @@
107107 */
108108 function getTable() {
109109 $table = $this->table;
 110+
 111+ global $wgTranslateWorkflowStates;
 112+ if ( $wgTranslateWorkflowStates !== false ) {
 113+ $this->states = self::getWorkflowStates( $this->target );
 114+ $this->statemap = array_flip( $wgTranslateWorkflowStates );
 115+ $table->addExtraColumn( wfMessage( 'translate-stats-workflow' ) );
 116+ }
110117 $out = '';
111118
112119 if ( $this->purge ) {
@@ -171,6 +178,13 @@
172179 $out = "\t" . Html::openElement( 'tr' );
173180 $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra );
174181 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
 182+ global $wgTranslateWorkflowStates;
 183+ if ( $wgTranslateWorkflowStates !== false ) {
 184+ $state = isset( $this->states[$code] ) ? $this->states[$code] : '';
 185+ $sort = isset( $this->statemap[$state] ) ? $this->statemap[$state] + 1 : -1;
 186+ $out .= "\n\t\t" . $this->table->element( $state, false, $sort );
 187+ }
 188+ $out .= "\n\t" . Xml::closeElement( 'tr' ) . "\n";
175189 return $out;
176190 }
177191
@@ -197,4 +211,14 @@
198212 return Html::rawElement( 'td', array(), $link );
199213 }
200214
201 -}
\ No newline at end of file
 215+ protected static function getWorkflowStates( $group ) {
 216+ $db = wfGetDB( DB_SLAVE );
 217+ $res = $db->select( 'translate_groupreviews', array( 'tgr_state', 'tgr_lang' ), array( 'tgr_group' => $group ), __METHOD__ );
 218+ $states = array();
 219+ foreach ( $res as $row ) {
 220+ $states[$row->tgr_lang] = $row->tgr_state;
 221+ }
 222+ return $states;
 223+ }
 224+
 225+}
Index: trunk/extensions/Translate/specials/SpecialLanguageStats.php
@@ -337,6 +337,7 @@
338338 $out .= "\n\t\t" . Html::rawElement( 'td', array(),
339339 $this->table->makeGroupLink( $group, $this->target, $extra ) );
340340 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
 341+ $out .= "\n\t" . Xml::closeElement( 'tr' ) . "\n";
341342 return $out;
342343 }
343344 }
Index: trunk/extensions/Translate/resources/ext.translate.special.languagestats.js
@@ -73,24 +73,17 @@
7474 // When hovering a row, adjust brightness of the last two custom-colored cells as well
7575 // See also translate.langstats.css for the highlighting for the other normal rows
7676 mw.loader.using( 'jquery.colorUtil' , function() {
77 -
7877 $( '.mw-sp-translate-table.wikitable tr' ).hover( function() {
79 -
80 - $( '> td:last', this )
81 - // Get last two cells
82 - .prev( 'td' ).andSelf()
83 - // 30% more brightness
84 - .css( 'background-color', function( i, val ) {
85 - return $.colorUtil.getColorBrightness( val, +0.3 );
86 - } );
 78+ $( '> td.hover-color', this )
 79+ // 30% more brightness
 80+ .css( 'background-color', function( i, val ) {
 81+ return $.colorUtil.getColorBrightness( val, +0.3 );
 82+ } );
8783 }, function() {
88 - $( '> td:last', this )
89 - // Get last two cells
90 - .prev( 'td' ).andSelf()
91 - // 30% less brightness
92 - .css( 'background-color', function( i, val ) {
93 - return $.colorUtil.getColorBrightness( val, -0.3 );
94 - } );
 84+ $( '> td.hover-color', this )
 85+ // 30% less brightness
 86+ .css( 'background-color', function( i, val ) {
 87+ return $.colorUtil.getColorBrightness( val, -0.3 );
 88+ } );
9589 } );
96 -
97 -} );
\ No newline at end of file
 90+} );

Follow-up revisions

RevisionCommit summaryAuthorDate
r101987Followup r101816: use Html over Xml when possiblenikerabbit12:42, 4 November 2011

Comments

#Comment by Amire80 (talk | contribs)   21:57, 3 November 2011

Why Html::openElement( 'tr' ), but Xml::closeElement( 'tr' )?

#Comment by Dantman (talk | contribs)   22:06, 3 November 2011

1.16 compat holdover? 1.16 didn't have Html::closeElement, that didn't make it in till 1.17.

#Comment by Nikerabbit (talk | contribs)   06:13, 4 November 2011

I didn't notice. I just copy pasted the closing line from another file which didn't yet use Html class.

Status & tagging log