Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -27,16 +27,15 @@ |
28 | 28 | global $wgRequest; |
29 | 29 | |
30 | 30 | $title = $skin->getTitle(); |
| 31 | + $handle = new MessageHandle( $title ); |
31 | 32 | |
32 | | - if ( !self::isMessageNamespace( $title ) ) { |
| 33 | + if ( !$handle->isValid() ) { |
33 | 34 | return true; |
34 | 35 | } |
35 | 36 | |
36 | | - list( $key, $code, $group ) = self::getKeyCodeGroup( $title ); |
37 | | - if ( !$group || !$code ) { |
38 | | - return true; |
39 | | - } |
40 | | - |
| 37 | + $group = $handle->getGroup(); |
| 38 | + $key = $handle->getKey(); |
| 39 | + $code = $handle->getCode(); |
41 | 40 | $collection = $group->initCollection( $group->getSourceLanguage() ); |
42 | 41 | $collection->filter( 'optional' ); |
43 | 42 | $keys = array_keys( $collection->keys() ); |
— | — | @@ -138,12 +137,12 @@ |
139 | 138 | * Hook: EditPage::showEditForm:initial |
140 | 139 | */ |
141 | 140 | static function addTools( $object ) { |
142 | | - if ( !self::isMessageNamespace( $object->mTitle ) ) { |
| 141 | + $handle = new MessageHandle( $object->mTitle ); |
| 142 | + if ( !$handle->isValid() ) { |
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | 146 | $object->editFormTextTop .= self::editBoxes( $object ); |
147 | | - |
148 | 147 | return true; |
149 | 148 | } |
150 | 149 | |
— | — | @@ -290,24 +289,12 @@ |
291 | 290 | } |
292 | 291 | |
293 | 292 | /** |
294 | | - * Check if a title is in a message namespace. |
295 | | - * @param $title Title |
296 | | - * @return \bool If title is in a message namespace. |
297 | | - */ |
298 | | - public static function isMessageNamespace( Title $title ) { |
299 | | - global $wgTranslateMessageNamespaces; |
300 | | - |
301 | | - $namespace = $title->getNamespace(); |
302 | | - |
303 | | - return in_array( $namespace, $wgTranslateMessageNamespaces, true ); |
304 | | - } |
305 | | - |
306 | | - /** |
307 | 293 | * Removes protection tab for message namespaces - not useful. |
308 | 294 | * Hook: SkinTemplateTabs |
309 | 295 | */ |
310 | 296 | public static function tabs( $skin, &$tabs ) { |
311 | | - if ( !self::isMessageNamespace( $skin->getTitle() ) ) { |
| 297 | + $handle = new MessageHandle( $skin->getTitle() ); |
| 298 | + if ( !$handle->isMessageNamespace() ) { |
312 | 299 | return true; |
313 | 300 | } |
314 | 301 | |
— | — | @@ -352,8 +339,7 @@ |
353 | 340 | MessageGroupStats::clear( $handle ); |
354 | 341 | |
355 | 342 | if ( $fuzzy === false ) { |
356 | | - // Fuzzy versions are not real translations |
357 | | - self::updateTransverTag( $handle, $rev ); |
| 343 | + wfRunHooks( 'Translate:newTranslation', array( $handle, $revision, $text, $user ) ); |
358 | 344 | } |
359 | 345 | |
360 | 346 | return true; |
— | — | @@ -365,6 +351,7 @@ |
366 | 352 | |
367 | 353 | // Docs are exempt for checks |
368 | 354 | global $wgTranslateDocumentationLanguageCode; |
| 355 | + $code = $handle->getCode(); |
369 | 356 | if ( $code === $wgTranslateDocumentationLanguageCode ) { |
370 | 357 | return $fuzzy; |
371 | 358 | } |
— | — | @@ -376,6 +363,7 @@ |
377 | 364 | return $fuzzy; |
378 | 365 | } |
379 | 366 | |
| 367 | + $key = $handle->getKey(); |
380 | 368 | $en = $group->getMessage( $key, $group->getSourceLanguage() ); |
381 | 369 | $message = new FatMessage( $key, $en ); |
382 | 370 | // Take the contents from edit field as a translation. |
— | — | @@ -411,8 +399,9 @@ |
412 | 400 | * Adds tag which identifies the revision of source message at that time. |
413 | 401 | * This is used to show diff against current version of source message |
414 | 402 | * when updating a translation. |
| 403 | + * Hook: Translate:newTranslation |
415 | 404 | */ |
416 | | - protected static function updateTransverTag( MessageHandle $handle, $revision ) { |
| 405 | + public static function updateTransverTag( MessageHandle $handle, $revision, $text, User $user ) { |
417 | 406 | $group = $handle->getGroup(); |
418 | 407 | if ( $group instanceof WikiPageMessageGroup ) { |
419 | 408 | // WikiPageMessageGroup has different method |
— | — | @@ -420,8 +409,8 @@ |
421 | 410 | } |
422 | 411 | |
423 | 412 | $title = $handle->getTitle(); |
424 | | - $fullKey = $handle->getKey() . '/' . $group->getSourceLanguage(); |
425 | | - $definitionTitle = Title::makeTitleSafe( $title->getNamespace(), $fullkey ); |
| 413 | + $name = $handle->getKey() . '/' . $group->getSourceLanguage(); |
| 414 | + $definitionTitle = Title::makeTitleSafe( $title->getNamespace(), $name ); |
426 | 415 | if ( !$definitionTitle || !$definitionTitle->exists() ) { |
427 | 416 | return; |
428 | 417 | } |
— | — | @@ -462,9 +451,12 @@ |
463 | 452 | /// Hook: ArticlePrepareTextForEdit |
464 | 453 | public static function disablePreSaveTransform( $article, $popts ) { |
465 | 454 | global $wgTranslateDocumentationLanguageCode; |
466 | | - $keycodegroup = self::getKeyCodeGroup( $article->getTitle() ); |
467 | | - if ( self::isMessageNamespace( $article->getTitle() ) |
468 | | - && $keycodegroup[1] !== $wgTranslateDocumentationLanguageCode ) { |
| 455 | + |
| 456 | + $handle = new MessageHandle( $article->getTitle() ); |
| 457 | + $code = $handle->getCode(); |
| 458 | + if ( $handle->isMessageNamespace() |
| 459 | + && $code !== $wgTranslateDocumentationLanguageCode ) { |
| 460 | + |
469 | 461 | $popts->setPreSaveTransform( false ); |
470 | 462 | } |
471 | 463 | return true; |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -96,6 +96,7 @@ |
97 | 97 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
98 | 98 | // Fuzzy tags for speed. |
99 | 99 | $wgHooks['ArticleSaveComplete'][] = 'TranslateEditAddons::onSave'; |
| 100 | +$wgHooks['Translate:newTranslation'][] = 'TranslateEditAddons::updateTransverTag'; |
100 | 101 | |
101 | 102 | // Custom preferences |
102 | 103 | $wgDefaultUserOptions['translate'] = 0; |
— | — | @@ -111,7 +112,7 @@ |
112 | 113 | $wgHooks['SkinTemplateToolboxEnd'][] = 'TranslateToolbox::toolboxAllTranslations'; |
113 | 114 | |
114 | 115 | // Translation memory updates |
115 | | -$wgHooks['ArticleSaveComplete'][] = 'TranslationMemoryUpdater::update'; |
| 116 | +$wgHooks['Translate:newTranslation'][] = 'TranslationMemoryUpdater::update'; |
116 | 117 | |
117 | 118 | // Translation display related |
118 | 119 | $wgHooks['ArticleContentOnDiff'][] = 'TranslateEditAddons::displayOnDiff'; |
Index: trunk/extensions/Translate/utils/TranslationMemoryUpdater.php |
— | — | @@ -13,19 +13,10 @@ |
14 | 14 | */ |
15 | 15 | class TranslationMemoryUpdater { |
16 | 16 | /** |
17 | | - * @static |
18 | | - * @param $article Article |
19 | | - * @param $user User |
20 | | - * @param $text |
21 | | - * @param $summary |
22 | | - * @param $minor |
23 | | - * @param $_ |
24 | | - * @param $_ |
25 | | - * @param $flags |
26 | | - * @param $revision |
27 | | - * @return bool |
| 17 | + * Shovels the new translation into translation memory. |
| 18 | + * Hook: Translate:newTranslation |
28 | 19 | */ |
29 | | - public static function update( $article, $user, $text, $summary, $minor, $_, $_, $flags, $revision ) { |
| 20 | + public static function update( MessageHandle $handle, $revision, $text, User $user ) { |
30 | 21 | global $wgContLang; |
31 | 22 | |
32 | 23 | $dbw = self::getDatabaseHandle(); |
— | — | @@ -34,29 +25,15 @@ |
35 | 26 | return true; |
36 | 27 | } |
37 | 28 | |
38 | | - $title = $article->getTitle(); |
39 | | - // Something we are not interested in at all |
40 | | - if ( !TranslateEditAddons::isMessageNamespace( $title ) ) { |
41 | | - return true; |
42 | | - } |
43 | | - |
44 | | - list( $key, $code, $group ) = TranslateEditAddons::getKeyCodeGroup( $title ); |
45 | | - // Unknown message, we cannot handle. We need definition. |
46 | | - if ( !$group || !$code ) { |
47 | | - return true; |
48 | | - } |
49 | | - |
50 | 29 | // Skip definitions to not slow down mass imports etc. |
51 | 30 | // These will be added when first translation is made |
52 | | - if ( $code === 'en' ) { |
| 31 | + if ( $handle->getCode() === 'en' ) { |
53 | 32 | return true; |
54 | 33 | } |
55 | 34 | |
56 | | - // Skip fuzzy messages |
57 | | - if ( TranslateEditAddons::hasFuzzyString( $text ) ) { |
58 | | - return true; |
59 | | - } |
60 | | - |
| 35 | + $group = $handle->getGroup(); |
| 36 | + $key = $handle->getKey(); |
| 37 | + $code = $handle->getCode(); |
61 | 38 | $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
62 | 39 | $definition = $group->getMessage( $key, 'en' ); |
63 | 40 | if ( !is_string( $definition ) || !strlen( $definition ) ) { |