r79955 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79954‎ | r79955 | r79956 >
Date:20:25, 10 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on the LiveTranslate special page
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.i18n.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate_Settings.php (modified) (history)
  • /trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php
@@ -35,7 +35,7 @@
3636 'livetranslate-tmtype-tmx' => 'Translation Memory eXchange',
3737 'livetranslate-tmtype-gcsv' => 'Google CSV',
3838 'livetranslate-special-no-tms-yet' => 'There are no translation memories yet.',
39 - 'livetranslate-special-button' => 'Save',
 39+ 'livetranslate-special-button' => 'Save and update',
4040 'livetranslate-special-type' => 'Type',
4141 'livetranslate-special-location' => 'Location',
4242 'livetranslate-special-remove' => 'Remove',
Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php
@@ -29,15 +29,9 @@
3030 $wgLanguageCode,
3131 );
3232
33 -# A list of translation memory exchange (TMX) files.
34 -$egLiveTranslateTXMFiles = array(
35 -
36 -);
37 -
38 -# A list of translation memory files in the Google CSV format.
39 -$egLiveTranslateGCVSFiles = array(
40 -
41 -);
42 -
4333 # Permission to mannage translation memories.
4434 $wgGroupPermissions['sysop']['managetms'] = true;
 35+
 36+# Default translation memory type.
 37+# TMT_LTF, TMT_TMX, TMT_GCSV
 38+$egLiveTranslateTMT = SpecialLiveTranslate::TMT_LTF;
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php
@@ -14,18 +14,13 @@
1515 class SpecialLiveTranslate extends SpecialPage {
1616
1717 /**
18 - * Map type numbers to messages.
19 - * Messages are build by prepending "livetranslate-tmtype-" and then passing it to wfMsg or similar.
 18+ * Enum for translation memory types.
2019 *
2120 * @since 0.4
22 - *
23 - * @var array
2421 */
25 - protected static $tmTypes = array(
26 - 0 => 'ltf',
27 - 1 => 'tmx',
28 - 2 => 'gcsv',
29 - );
 22+ const TMT_LTF = 0;
 23+ const TMT_TMX = 1;
 24+ const TMT_GCSV = 2;
3025
3126 /**
3227 * Constructor.
@@ -91,18 +86,45 @@
9287 protected function handleSubmission() {
9388 global $wgRequest;
9489
 90+ $tms = $this->getTMConfigItems();
 91+
9592 $dbw = wfGetDB( DB_MASTER );
9693
 94+ // Loop over the existing translation memories and update/delete them if requested.
 95+ foreach ( $tms as $tm ) {
 96+ // If a delete has been requested, remove the item.
 97+ if ( $wgRequest->getCheck( 'tmdel-' . $tm->memory_id ) ) {
 98+ $dbw->delete(
 99+ 'live_translate_memories',
 100+ array( 'memory_id' => $tm->memory_id )
 101+ );
 102+ }
 103+ // If changes where made, apply them in the db.
 104+ elseif (
 105+ $wgRequest->getText( 'tmlocation-' . $tm->memory_id ) != $tm->memory_location
 106+ || $wgRequest->getInt( 'wptmtype-' . $tm->memory_id ) != $tm->memory_type
 107+ ) {
 108+ $dbw->update(
 109+ 'live_translate_memories',
 110+ array(
 111+ 'memory_location' => $wgRequest->getText( 'tmlocation-' . $tm->memory_id ),
 112+ 'memory_type' => $wgRequest->getInt( 'wptmtype-' . $tm->memory_id )
 113+ ),
 114+ array( 'memory_id' => $tm->memory_id )
 115+ );
 116+ }
 117+ }
 118+
 119+ // If there is a new item, insert it.
97120 if ( $wgRequest->getText( 'newtm-location' ) != '' ) {
98121 $dbw->insert(
99122 'live_translate_memories',
100123 array(
101 - 'memory_type' => $wgRequest->getVal( 'wpnewtm-type' ),
 124+ 'memory_type' => $wgRequest->getInt( 'wpnewtm-type' ),
102125 'memory_location' => $wgRequest->getText( 'newtm-location' )
103126 )
104127 );
105128 }
106 -
107129 }
108130
109131 /**
@@ -126,6 +148,7 @@
127149 ) );
128150
129151 if ( count( $tms ) > 0 ) {
 152+ /*
130153 $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-tms-update' ) ) . '</h3>' );
131154
132155 $wgOut->addHTML(
@@ -136,6 +159,7 @@
137160 array( 'id' => 'tmform-updatesubmit' )
138161 )
139162 );
 163+ */
140164
141165 $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-current-tms' ) ) . '</h3>' );
142166
@@ -242,14 +266,14 @@
243267 * @since 0.4
244268 */
245269 protected function displayAddNewTM() {
246 - global $wgOut;
 270+ global $wgOut, $egLiveTranslateTMT;
247271
248272 $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-add-tm' ) ) . '</h3>' );
249273
250274 $wgOut->addHTML(
251275 '<table><tr>' .
252276 '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-type' ) ) . ': </b></td>' .
253 - '<td>' . $this->getTypeSelector( 'newtm-type', '' ) . '</td>' . // TODO
 277+ '<td>' . $this->getTypeSelector( 'newtm-type', $egLiveTranslateTMT ) . '</td>' .
254278 '</tr><tr>' .
255279 '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-location' ) ) . ': </b></td>' .
256280 '<td>' . Html::input( 'newtm-location', '', 'text', array( 'size' => 75 ) ) . '</td>' .
@@ -257,6 +281,17 @@
258282 );
259283 }
260284
 285+ /**
 286+ * Builds up an HTML select for translation memory types with the provided name.
 287+ * The value parameter allows setting which item should be selected.
 288+ *
 289+ * @since 0.4
 290+ *
 291+ * @param string $name
 292+ * @param string $value
 293+ *
 294+ * @return string
 295+ */
261296 protected function getTypeSelector( $name, $value ) {
262297 $typeSelector = new HTMLSelectField( array(
263298 'fieldname' => $name,
@@ -266,13 +301,27 @@
267302 return $typeSelector->getInputHTML( $value );
268303 }
269304
 305+ /**
 306+ * Returns an array with the translation memory type names (keys)
 307+ * and their database values (values).
 308+ *
 309+ * @since 0.4
 310+ *
 311+ * @return array
 312+ */
270313 protected function getTypeOptions() {
271314 static $options = false;
272315
273316 if ( $options === false ) {
274317 $options = array();
275318
276 - foreach ( self::$tmTypes as $dbValue => $msgKey ) {
 319+ $tmTypes = array(
 320+ self::TMT_LTF => 'ltf',
 321+ self::TMT_TMX => 'tmx',
 322+ self::TMT_GCSV => 'gcsv',
 323+ );
 324+
 325+ foreach ( $tmTypes as $dbValue => $msgKey ) {
277326 $options[wfMsg( 'livetranslate-tmtype-' . $msgKey )] = $dbValue;
278327 }
279328 }

Status & tagging log