r79976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79975‎ | r79976 | r79977 >
Date:23:51, 10 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Create a single TM if there are none yet
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.hooks.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate_Settings.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php (modified) (history)
  • /trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php
@@ -18,9 +18,6 @@
1919 die( 'Not an entry point.' );
2020 }
2121
22 -# The name of the page on which the special words translations dirctionary is defined.
23 -$egLiveTranslateDirPage = 'Live Translate Dictionary';
24 -
2522 # https://code.google.com/apis/console
2623 $egGoogleApiKey = '';
2724
@@ -35,3 +32,7 @@
3633 # Default translation memory type.
3734 # TMT_LTF, TMT_TMX, TMT_GCSV
3835 $egLiveTranslateTMT = TMT_LTF;
 36+
 37+# The name of the page on which the special words translations dirctionary is defined.
 38+# NOTICE: This is only used for the initial setup. Use Special:LiveTranslate to modify after installation.
 39+$egLiveTranslateDirPage = 'Live Translate Dictionary';
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php
@@ -62,9 +62,14 @@
6363 return;
6464 }
6565
66 - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
67 - $this->handleSubmission();
 66+ if ( $wgRequest->wasPosted() ) {
 67+ if ( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 68+ $this->handleSubmission();
 69+ }
6870 }
 71+ else {
 72+ LiveTranslateFunctions::createInitialMemoryIfNeeded();
 73+ }
6974
7075 $tms = $this->getTMConfigItems();
7176
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php
@@ -31,6 +31,8 @@
3232 $currentLang = LiveTranslateFunctions::getCurrentLang( $title );
3333
3434 if ( $title->getFullText() == $egLiveTranslateDirPage ) {
 35+ LiveTranslateFunctions::createInitialMemoryIfNeeded();
 36+
3537 $parser = new LTLTFParser();
3638 $tm = $parser->parse( $article->getContent() );
3739 $tus = $tm->getTranslationUnits();
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php
@@ -314,4 +314,36 @@
315315 }
316316 }
317317
 318+ /**
 319+ * Creates the initial translation memory if there is none yet.
 320+ *
 321+ * @since 0.4
 322+ */
 323+ public static function createInitialMemoryIfNeeded() {
 324+ $dbw = wfGetDb( DB_MASTER );
 325+
 326+ $res = $dbw->select(
 327+ 'live_translate_memories',
 328+ array( 'memory_id' ),
 329+ array(),
 330+ __METHOD__,
 331+ array( 'LIMIT' => '1' )
 332+ );
 333+
 334+ $hasTms = false;
 335+
 336+ foreach ( $res as $tm ) {
 337+ $hasTms = true;
 338+ break;
 339+ }
 340+
 341+ if ( !$hasTms ) {
 342+ global $egLiveTranslateDirPage;
 343+ $dbw->insert(
 344+ 'live_translate_memories',
 345+ array( 'memory_location' => $egLiveTranslateDirPage, 'memory_type' => 0 )
 346+ );
 347+ }
 348+ }
 349+
318350 }
\ No newline at end of file

Status & tagging log