Index: trunk/extensions/Translate/scripts/cli.inc |
— | — | @@ -69,8 +69,6 @@ |
70 | 70 | /** |
71 | 71 | * Output a warning message to command line (if available). |
72 | 72 | * @see STDOUT |
73 | | - * @param $message |
74 | | - * @param null $channel |
75 | 73 | */ |
76 | 74 | function STDERR( $message, $channel = null ) { |
77 | 75 | STDOUT( $message, $channel, true ); |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -10,21 +10,13 @@ |
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Hooks for page translation. |
14 | | - * |
15 | | - * @todo Methods need documentation. |
16 | 14 | * @ingroup PageTranslation |
17 | 15 | */ |
18 | 16 | class PageTranslationHooks { |
19 | 17 | // Uuugly hack |
20 | 18 | static $allowTargetEdit = false; |
21 | 19 | |
22 | | - /** |
23 | | - * @static |
24 | | - * @param $parser Parser |
25 | | - * @param $text String |
26 | | - * @param $state |
27 | | - * @return bool |
28 | | - */ |
| 20 | + /// Hook: ParserBeforeStrip |
29 | 21 | public static function renderTagPage( $parser, &$text, $state ) { |
30 | 22 | $title = $parser->getTitle(); |
31 | 23 | |
— | — | @@ -61,11 +53,8 @@ |
62 | 54 | /** |
63 | 55 | * Set the right page content language for translated pages ("Page/xx"). |
64 | 56 | * Hook: PageContentLanguage |
65 | | - * @param $title Title |
66 | | - * @param $pageLang |
67 | | - * @return bool |
68 | 57 | */ |
69 | | - public static function onPageContentLanguage( $title, &$pageLang ) { |
| 58 | + public static function onPageContentLanguage( Title $title, /*string*/ &$pageLang ) { |
70 | 59 | // For translation pages, parse plural, grammar etc with correct language, and set the right direction |
71 | 60 | if ( TranslatablePage::isTranslationPage( $title ) ) { |
72 | 61 | list( , $code ) = TranslateUtils::figureMessage( $title->getText() ); |
— | — | @@ -74,51 +63,22 @@ |
75 | 64 | return true; |
76 | 65 | } |
77 | 66 | |
78 | | - /** |
79 | | - * Only called from hook |
80 | | - * |
81 | | - * @param $outputpage |
82 | | - * @param $text |
83 | | - * @return bool |
84 | | - */ |
85 | | - public static function injectCss( $outputpage, $text ) { |
| 67 | + /// Hook: OutputPageBeforeHTML |
| 68 | + public static function injectCss( OutputPage $outputpage, /*string*/ $text ) { |
86 | 69 | $outputpage->addModules( 'ext.translate' ); |
87 | | - |
88 | 70 | return true; |
89 | 71 | } |
90 | 72 | |
91 | | - /** |
92 | | - * @param Title $title |
93 | | - * @return types |
94 | | - */ |
95 | | - public static function titleToGroup( Title $title ) { |
96 | | - $namespace = $title->getNamespace(); |
97 | | - $text = $title->getDBkey(); |
98 | | - list( $key, ) = TranslateUtils::figureMessage( $text ); |
99 | | - |
100 | | - return TranslateUtils::messageKeyToGroup( $namespace, $key ); |
101 | | - } |
102 | | - |
103 | | - /** |
104 | | - * @param $article Article |
105 | | - * @param $user User |
106 | | - * @param $text |
107 | | - * @param $summary |
108 | | - * @param $minor |
109 | | - * @param $_ |
110 | | - * @param $_ |
111 | | - * @param $flags |
112 | | - * @param $revision |
113 | | - * @return bool |
114 | | - */ |
115 | | - public static function onSectionSave( $article, $user, $text, $summary, $minor, |
116 | | - $_, $_, $flags, $revision ) { |
| 73 | + /// Hook: ArticleSaveComplete |
| 74 | + public static function onSectionSave( $article, User $user, $text, $summary, |
| 75 | + $minor, $_, $_, $flags, $revision ) { |
117 | 76 | $title = $article->getTitle(); |
118 | 77 | |
119 | 78 | // Some checks |
| 79 | + $handle = new MessageHandle( $title ); |
120 | 80 | |
121 | 81 | // We are only interested in the translations namespace |
122 | | - if ( $title->getNamespace() != NS_TRANSLATIONS ) { |
| 82 | + if ( !$handle->isPageTranslation() || !$handle->isValid() ) { |
123 | 83 | return true; |
124 | 84 | } |
125 | 85 | |
— | — | @@ -127,11 +87,8 @@ |
128 | 88 | return true; |
129 | 89 | } |
130 | 90 | |
131 | | - // Figure out the group |
132 | | - $groupKey = self::titleToGroup( $title ); |
133 | | - $group = MessageGroups::getGroup( $groupKey ); |
| 91 | + $group = $handle->getGroup(); |
134 | 92 | if ( !$group instanceof WikiPageMessageGroup ) { |
135 | | - SpecialPageTranslation::superDebug( __METHOD__, 'not wp-group', $title, $user, $groupKey ); |
136 | 93 | return true; |
137 | 94 | } |
138 | 95 | |
— | — | @@ -144,10 +101,8 @@ |
145 | 102 | } |
146 | 103 | |
147 | 104 | // Update the target translation page |
148 | | - list( , $code ) = TranslateUtils::figureMessage( $title->getDBkey() ); |
149 | | - global $wgTranslateDocumentationLanguageCode; |
150 | | - if ( $code !== $wgTranslateDocumentationLanguageCode ) { |
151 | | - SpecialPageTranslation::superDebug( __METHOD__, 'ok', $title, $user ); |
| 105 | + if ( !$handle->isDoc() ) { |
| 106 | + $code = $handle->getCode(); |
152 | 107 | self::updateTranslationPage( $page, $code, $user, $flags, $summary ); |
153 | 108 | } |
154 | 109 | |
— | — | @@ -291,7 +246,10 @@ |
292 | 247 | FOO; |
293 | 248 | } |
294 | 249 | |
295 | | - // To display nice error for editpage |
| 250 | + /** |
| 251 | + * Display nice error for editpage. |
| 252 | + * Hook: EditFilterMerged |
| 253 | + */ |
296 | 254 | public static function tpSyntaxCheckForEditPage( $editpage, $text, &$error, $summary ) { |
297 | 255 | if ( strpos( $text, '<translate>' ) === false ) { |
298 | 256 | return true; |
— | — | @@ -310,16 +268,7 @@ |
311 | 269 | /** |
312 | 270 | * When attempting to save, last resort. Edit page would only display |
313 | 271 | * edit conflict if there wasn't tpSyntaxCheckForEditPage |
314 | | - * @param $article Article |
315 | | - * @param $user User |
316 | | - * @param $text |
317 | | - * @param $summary string |
318 | | - * @param $minor bool |
319 | | - * @param $_ |
320 | | - * @param $_ |
321 | | - * @param $flags |
322 | | - * @param $status |
323 | | - * @return bool |
| 272 | + * Hook: ArticleSave |
324 | 273 | */ |
325 | 274 | public static function tpSyntaxCheck( $article, $user, $text, $summary, |
326 | 275 | $minor, $_, $_, $flags, $status ) { |
— | — | @@ -339,6 +288,7 @@ |
340 | 289 | return true; |
341 | 290 | } |
342 | 291 | |
| 292 | + /// Hook: ArticleSaveComplete |
343 | 293 | public static function addTranstag( $article, $user, $text, $summary, |
344 | 294 | $minor, $_, $_, $flags, $revision ) { |
345 | 295 | // We are not interested in null revisions |
— | — | @@ -360,23 +310,25 @@ |
361 | 311 | return true; |
362 | 312 | } |
363 | 313 | |
364 | | - /// Prevent editing of unknown pages in Translations namespace |
365 | | - public static function preventUnknownTranslations( $title, $user, $action, &$result ) { |
366 | | - if ( $title->getNamespace() == NS_TRANSLATIONS && $action === 'edit' ) { |
367 | | - $group = self::titleToGroup( $title ); |
368 | | - if ( $group === null ) { |
369 | | - // No group means that the page is currently not |
370 | | - // registered to any page translation message groups |
371 | | - $result = array( 'tpt-unknown-page' ); |
372 | | - return false; |
373 | | - } |
| 314 | + /** |
| 315 | + * Prevent editing of unknown pages in Translations namespace. |
| 316 | + * Hook: getUserPermissionsErrorsExpensive |
| 317 | + */ |
| 318 | + public static function preventUnknownTranslations( Title $title, User $user, $action, &$result ) { |
| 319 | + $handle = new MessageHandle( $title ); |
| 320 | + if ( $handle->isPageTranslation() && $action === 'edit' && !$handle->isValid() ) { |
| 321 | + $result = array( 'tpt-unknown-page' ); |
| 322 | + return false; |
374 | 323 | } |
375 | 324 | |
376 | 325 | return true; |
377 | 326 | } |
378 | 327 | |
379 | | - /// Prevent editing of translation pages directly |
380 | | - public static function preventDirectEditing( $title, $user, $action, &$result ) { |
| 328 | + /** |
| 329 | + * Prevent editing of translation pages directly. |
| 330 | + * Hook: getUserPermissionsErrorsExpensive |
| 331 | + */ |
| 332 | + public static function preventDirectEditing( Title $title, User $user, $action, &$result ) { |
381 | 333 | $page = TranslatablePage::isTranslationPage( $title ); |
382 | 334 | if ( $page !== false && $action !== 'delete' ) { |
383 | 335 | if ( self::$allowTargetEdit ) { |
— | — | @@ -398,30 +350,35 @@ |
399 | 351 | return true; |
400 | 352 | } |
401 | 353 | |
402 | | - public static function disableDelete( $article, $wgOut, &$reason ) { |
403 | | - if ( TranslatablePage::isSourcePage( $article->mTitle ) || TranslatablePage::isTranslationPage( $article->mTitle ) ) { |
404 | | - $new = SpecialPage::getTitleFor( 'PageTranslationDeletePage', $article->mTitle->getPrefixedText() ); |
405 | | - $wgOut->redirect( $new->getFullUrl() ); |
| 354 | + /** |
| 355 | + * Redirects the delete action to our own for translatable pages. |
| 356 | + * Hook: ArticleConfirmDelete |
| 357 | + */ |
| 358 | + public static function disableDelete( $article, $out, &$reason ) { |
| 359 | + $title = $article->getTitle(); |
| 360 | + if ( TranslatablePage::isSourcePage( $title ) || TranslatablePage::isTranslationPage( $title ) ) { |
| 361 | + $new = SpecialPage::getTitleFor( 'PageTranslationDeletePage', $title->getPrefixedText() ); |
| 362 | + $out->redirect( $new->getFullUrl() ); |
406 | 363 | } |
407 | 364 | return true; |
408 | 365 | } |
409 | 366 | |
410 | | - /// @todo: fix method name. |
411 | | - public static function test( &$article, &$outputDone, &$pcache ) { |
412 | | - if ( !$article->getOldID() ) { |
413 | | - self::header( $article->getTitle() ); |
| 367 | + /// Hook: ArticleViewHeader |
| 368 | + public static function translatablePageHeader( &$article, &$outputDone, &$pcache ) { |
| 369 | + if ( $article->getOldID() ) { |
| 370 | + return true; |
414 | 371 | } |
415 | 372 | |
416 | | - return true; |
417 | | - } |
| 373 | + $title = $article->getTitle(); |
418 | 374 | |
419 | | - public static function header( Title $title ) { |
420 | 375 | if ( TranslatablePage::isTranslationPage( $title ) ) { |
421 | 376 | self::translationPageHeader( $title ); |
422 | 377 | } else { |
423 | 378 | // Check for pages that are tagged or marked |
424 | 379 | self::sourcePageHeader( $title ); |
425 | 380 | } |
| 381 | + |
| 382 | + return true; |
426 | 383 | } |
427 | 384 | |
428 | 385 | protected static function sourcePageHeader( Title $title ) { |
— | — | @@ -527,24 +484,17 @@ |
528 | 485 | $wgOut->addHTML( '<hr />' ); |
529 | 486 | } |
530 | 487 | |
| 488 | + /// Hook: LinksUpdate |
531 | 489 | public static function preventCategorization( $updater ) { |
532 | | - global $wgTranslateDocumentationLanguageCode; |
533 | | - $title = $updater->getTitle(); |
534 | | - list( , $code ) = TranslateUtils::figureMessage( $title ); |
535 | | - if ( $title->getNamespace() == NS_TRANSLATIONS && $code !== $wgTranslateDocumentationLanguageCode ) { |
| 490 | + $handle = new MessageHandle( $updater->getTitle() ); |
| 491 | + if ( $handle->isPageTranslation() && !$handle->isDoc() ) { |
536 | 492 | $updater->mCategories = array(); |
537 | 493 | } |
538 | 494 | return true; |
539 | 495 | } |
540 | 496 | |
541 | 497 | /** |
542 | | - * @static |
543 | | - * @param $type |
544 | | - * @param $action |
545 | | - * @param $title Title |
546 | | - * @param $forUI |
547 | | - * @param $params |
548 | | - * @return String |
| 498 | + * @return string |
549 | 499 | */ |
550 | 500 | public static function formatLogEntry( $type, $action, $title, $forUI, $params ) { |
551 | 501 | global $wgLang, $wgContLang; |
— | — | @@ -580,13 +530,15 @@ |
581 | 531 | return ''; |
582 | 532 | } |
583 | 533 | |
| 534 | + /// Hook: SpecialPage_initList |
584 | 535 | public static function replaceMovePage( &$list ) { |
585 | 536 | $old = is_array( $list['Movepage'] ); |
586 | 537 | $list['Movepage'] = array( 'SpecialPageTranslationMovePage', $old ); |
587 | 538 | return true; |
588 | 539 | } |
589 | 540 | |
590 | | - public static function lockedPagesCheck( $title, $user, $action, &$result ) { |
| 541 | + /// Hook: getUserPermissionsErrorsExpensive |
| 542 | + public static function lockedPagesCheck( Title $title, User $user, $action, &$result ) { |
591 | 543 | global $wgMemc; |
592 | 544 | $key = wfMemcKey( 'pt-lock', $title->getPrefixedText() ); |
593 | 545 | if ( $wgMemc->get( $key ) === true ) { |
— | — | @@ -597,6 +549,7 @@ |
598 | 550 | return true; |
599 | 551 | } |
600 | 552 | |
| 553 | + /// Hook: SkinSubPageSubtitle |
601 | 554 | public static function replaceSubtitle( &$subpages, $skin = null , $out = null ) { |
602 | 555 | global $wgOut; |
603 | 556 | // $out was only added in some MW version |
Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -344,7 +344,7 @@ |
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
348 | | - * @Hook: ArticleSaveComplete |
| 348 | + * Hook: ArticleSaveComplete |
349 | 349 | * @param $article Article |
350 | 350 | * @param $user User |
351 | 351 | * @param $text string |
Index: trunk/extensions/Translate/TranslateHooks.php |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::lockedPagesCheck'; |
130 | 130 | |
131 | 131 | // Our custom header for translation pages |
132 | | - $wgHooks['ArticleViewHeader'][] = 'PageTranslationHooks::test'; |
| 132 | + $wgHooks['ArticleViewHeader'][] = 'PageTranslationHooks::translatablePageHeader'; |
133 | 133 | |
134 | 134 | // Prevent section pages appearing in categories |
135 | 135 | $wgHooks['LinksUpdate'][] = 'PageTranslationHooks::preventCategorization'; |
Index: trunk/extensions/Translate/utils/MessageHandle.php |
— | — | @@ -65,6 +65,23 @@ |
66 | 66 | return $this->code; |
67 | 67 | } |
68 | 68 | |
| 69 | + /** |
| 70 | + * Determine whether the current handle is for message documentation. |
| 71 | + * @return bool |
| 72 | + */ |
| 73 | + public function isDoc() { |
| 74 | + global $wgTranslateDocumentationLanguageCode; |
| 75 | + return $this->getCode() === $wgTranslateDocumentationLanguageCode; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Determine whether the current handle is for page translation feature. |
| 80 | + * @return bool |
| 81 | + */ |
| 82 | + public function isPageTranslation() { |
| 83 | + return $this->getTitle()->getNamespace() == NS_TRANSLATIONS; |
| 84 | + } |
| 85 | + |
69 | 86 | public function getGroupIds() { |
70 | 87 | if ( $this->groupIds === null ) { |
71 | 88 | $this->groupIds = TranslateUtils::messageKeyToGroups( $this->getTitle()->getNamespace(), $this->getKey() ); |
Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -638,9 +638,8 @@ |
639 | 639 | return null; |
640 | 640 | } |
641 | 641 | |
642 | | - global $wgUser; |
643 | | - |
644 | | - $title = $wgUser->getSkin()->link( |
| 642 | + $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker; |
| 643 | + $title = $linker->link( |
645 | 644 | SpecialPage::getTitleFor( 'Translate' ), |
646 | 645 | htmlspecialchars( $this->group->getLabel() ), |
647 | 646 | array(), |
Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -106,7 +106,6 @@ |
107 | 107 | /** |
108 | 108 | * Returns message tags. If type is given, only messages keys with that |
109 | 109 | * tag is returnted. Otherwise an array[tag => keys] is returnted. |
110 | | - * @param null $type |
111 | 110 | * @return array |
112 | 111 | */ |
113 | 112 | public function getTags( $type = null ); |
— | — | @@ -114,10 +113,9 @@ |
115 | 114 | /** |
116 | 115 | * Returns the definition or translation for given message key in given |
117 | 116 | * language code. |
118 | | - * @todo Is this needed in the interface? |
119 | | - * @param $key |
120 | | - * @param $code |
121 | | - * @return string or null |
| 117 | + * @param $key string |
| 118 | + * @param $code string |
| 119 | + * @return string|null |
122 | 120 | */ |
123 | 121 | public function getMessage( $key, $code ); |
124 | 122 | |