r107387 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107386‎ | r107387 | r107388 >
Date:15:44, 27 December 2011
Author:amire80
Status:resolved
Tags:
Comment:
Refactored the code for adding workflow states column and cells. Added workflow states column to Special:LanguagesStats, but without data yet.
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,13 +107,7 @@
108108 function getTable() {
109109 $table = $this->table;
110110
111 - global $wgTranslateWorkflowStates;
112 - if ( $wgTranslateWorkflowStates ) {
113 - $this->states = self::getWorkflowStates( $this->target );
114 - $this->statemap = array_flip( $wgTranslateWorkflowStates );
115 - $table->addExtraColumn( wfMessage( 'translate-stats-workflow' ) );
116 - }
117 -
 111+ $this->workflowStatesColumn();
118112 $out = '';
119113
120114 if ( $this->purge ) {
@@ -179,19 +173,8 @@
180174 $out = "\t" . Html::openElement( 'tr' );
181175 $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra );
182176 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
 177+ $out .= $this->workflowStateCell( $code );
183178
184 - global $wgTranslateWorkflowStates;
185 - if ( $wgTranslateWorkflowStates ) {
186 - $state = isset( $this->states[$code] ) ? $this->states[$code] : '';
187 - $sort = isset( $this->statemap[$state] ) ? $this->statemap[$state] + 1 : -1;
188 - $stateMessage = wfMessage( "translate-workflow-state-$state" );
189 - $stateText = $stateMessage->isBlank() ? $state : $stateMessage->text();
190 - $out .= "\n\t\t" . $this->table->element(
191 - $stateText,
192 - isset( $wgTranslateWorkflowStates[$state] ) ? $wgTranslateWorkflowStates[$state] : '',
193 - $sort
194 - );
195 - }
196179 $out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
197180 return $out;
198181 }
@@ -218,19 +201,4 @@
219202 $link = $linker->link( $this->translate, $text, array(), $queryParameters );
220203 return Html::rawElement( 'td', array(), $link );
221204 }
222 -
223 - protected static function getWorkflowStates( $group ) {
224 - $db = wfGetDB( DB_SLAVE );
225 - $res = $db->select(
226 - 'translate_groupreviews',
227 - array( 'tgr_state', 'tgr_lang' ),
228 - array( 'tgr_group' => $group ),
229 - __METHOD__
230 - );
231 - $states = array();
232 - foreach ( $res as $row ) {
233 - $states[$row->tgr_lang] = $row->tgr_state;
234 - }
235 - return $states;
236 - }
237205 }
Index: trunk/extensions/Translate/specials/SpecialLanguageStats.php
@@ -229,12 +229,49 @@
230230 }
231231
232232 /**
 233+ * If workflow states are configured, adds a workflow states column
 234+ */
 235+ function workflowStatesColumn() {
 236+ global $wgTranslateWorkflowStates;
 237+ if ( $wgTranslateWorkflowStates ) {
 238+ $this->states = self::getWorkflowStates( $this->target );
 239+ $this->statemap = array_flip( $wgTranslateWorkflowStates );
 240+ $this->table->addExtraColumn( wfMessage( 'translate-stats-workflow' ) );
 241+ }
 242+
 243+ return;
 244+ }
 245+
 246+ /**
 247+ * If workflow states are configured, adds a cell with the workflow state to the row,
 248+ * @param $code Language code
 249+ * @return string
 250+ */
 251+ function workflowStateCell( $code ) {
 252+ global $wgTranslateWorkflowStates;
 253+ if ( $wgTranslateWorkflowStates ) {
 254+ $state = isset( $this->states[$code] ) ? $this->states[$code] : '';
 255+ $sort = isset( $this->statemap[$state] ) ? $this->statemap[$state] + 1 : -1;
 256+ $stateMessage = wfMessage( "translate-workflow-state-$state" );
 257+ $stateText = $stateMessage->isBlank() ? $state : $stateMessage->text();
 258+ return "\n\t\t" . $this->table->element(
 259+ $stateText,
 260+ isset( $wgTranslateWorkflowStates[$state] ) ? $wgTranslateWorkflowStates[$state] : '',
 261+ $sort
 262+ );
 263+ }
 264+
 265+ return '';
 266+ }
 267+
 268+ /**
233269 * Returns the table itself.
234270 * @return \string HTML
235271 */
236272 function getTable() {
237273 $table = $this->table;
238274
 275+ $this->workflowStatesColumn();
239276 $out = '';
240277
241278 if ( $this->purge ) {
@@ -344,7 +381,23 @@
345382 $out .= "\n\t\t" . Html::rawElement( 'td', array(),
346383 $this->table->makeGroupLink( $group, $this->target, $extra ) );
347384 $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total );
 385+
348386 $out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
349387 return $out;
350388 }
 389+
 390+ protected static function getWorkflowStates( $group ) {
 391+ $db = wfGetDB( DB_SLAVE );
 392+ $res = $db->select(
 393+ 'translate_groupreviews',
 394+ array( 'tgr_state', 'tgr_lang' ),
 395+ array( 'tgr_group' => $group ),
 396+ __METHOD__
 397+ );
 398+ $states = array();
 399+ foreach ( $res as $row ) {
 400+ $states[$row->tgr_lang] = $row->tgr_state;
 401+ }
 402+ return $states;
 403+ }
351404 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r107485Follow up to r107387. Renamed functions: workflowStatesColumn -> addWorkflowS...amire8012:40, 28 December 2011

Status & tagging log