r80193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80192‎ | r80193 | r80194 >
Date:22:00, 13 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Store directory size and language count in db table
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.sql (modified) (history)
  • /trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LT_TMUnit.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LT_TranslationMemory.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/LT_TMUnit.php
@@ -129,4 +129,15 @@
130130 return false;
131131 }
132132
 133+ /**
 134+ * Returns the amount of languages (variants).
 135+ *
 136+ * @since 0.4
 137+ *
 138+ * @return integer
 139+ */
 140+ public function getLanguageAmount() {
 141+ return count( $this->variants );
 142+ }
 143+
133144 }
Index: trunk/extensions/LiveTranslate/includes/LT_TranslationMemory.php
@@ -51,4 +51,26 @@
5252 return $this->translationUnits;
5353 }
5454
 55+ /**
 56+ * Returns the max amount of languages (variants) in a single translation unit.
 57+ * Note: this might not be the total amount of unique languages!
 58+ *
 59+ * @since 0.4
 60+ *
 61+ * @return integer
 62+ */
 63+ public function getLanguageAmount() {
 64+ $maxAmount = 0;
 65+
 66+ foreach ( $this->translationUnits as $tu ) {
 67+ $amount = $tu->getLanguageAmount();
 68+
 69+ if ( $amount > $maxAmount ) {
 70+ $maxAmount = $amount;
 71+ }
 72+ }
 73+
 74+ return $maxAmount;
 75+ }
 76+
5577 }
Index: trunk/extensions/LiveTranslate/api/ApiImportTranslationMemories.php
@@ -28,10 +28,6 @@
2929 $this->dieUsageMsg( array( 'missingparam', $requiredParam ) );
3030 }
3131 }
32 -
33 - //if ( !$wgUser->isAllowed( 'managetms' ) ) {
34 - // $this->dieUsageMsg( array( 'permissiondenied' ) );
35 - //}
3632
3733 foreach ( $params['source'] as $location ) {
3834 $text = false;
@@ -89,7 +85,8 @@
9086 array( 'memory_id' => $memoryId )
9187 );
9288
93 - $wordId = ( $memoryId - 1 ) * 100000;
 89+ $idOffset = ( $memoryId - 1 ) * 100000;
 90+ $wordId = 0;
9491
9592 $dbw->begin();
9693
@@ -106,7 +103,7 @@
107104 $dbw->insert(
108105 'live_translate',
109106 array(
110 - 'word_id' => $wordId,
 107+ 'word_id' => $idOffset + $wordId,
111108 'word_language' => $this->cleanLanguage( $language ),
112109 'word_translation' => $translation,
113110 'word_primary' => $primary,
@@ -125,6 +122,15 @@
126123 $dbw->begin();
127124 }
128125 }
 126+
 127+ $dbw->update(
 128+ 'live_translate_memories',
 129+ array(
 130+ 'memory_lang_count' => $tm->getLanguageAmount(),
 131+ 'memory_tu_count' => $wordId
 132+ ),
 133+ array( 'memory_id' => $memoryId )
 134+ );
129135
130136 $dbw->commit();
131137 }
Index: trunk/extensions/LiveTranslate/LiveTranslate.sql
@@ -14,7 +14,9 @@
1515 memory_id INT(4) unsigned NOT NULL auto_increment PRIMARY KEY,
1616 memory_type INT(2) unsigned NOT NULL,
1717 memory_location VARCHAR(255) NOT NULL,
18 - memory_local INT(1) unsigned NOT NULL
 18+ memory_local INT(1) unsigned NOT NULL,
 19+ memory_lang_count INT(2) unsigned NOT NULL,
 20+ memory_tu_count INT(8) unsigned NOT NULL
1921 ) /*$wgDBTableOptions*/;
2022
21 -INSERT INTO /*$wgDBprefix*/live_translate_memories VALUES (NULL, 0, "Live Translate Dictionary", 1);
\ No newline at end of file
 23+INSERT INTO /*$wgDBprefix*/live_translate_memories VALUES (NULL, 0, "Live Translate Dictionary", 1, 0, 0);
\ No newline at end of file

Status & tagging log