Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -20,12 +20,8 @@ |
21 | 21 | /** |
22 | 22 | * Add some tabs for navigation for users who do not use Ajax interface. |
23 | 23 | * Hooks: SkinTemplateNavigation, SkinTemplateTabs |
24 | | - * @param $skin Skin |
25 | | - * @param $tabs Array |
26 | | - * |
27 | | - * @return bool |
28 | 24 | */ |
29 | | - static function addNavigationTabs( $skin, &$tabs ) { |
| 25 | + static function addNavigationTabs( Skin $skin, array &$tabs ) { |
30 | 26 | global $wgRequest; |
31 | 27 | |
32 | 28 | $title = $skin->getTitle(); |
— | — | @@ -47,20 +43,20 @@ |
48 | 44 | |
49 | 45 | $next = $prev = null; |
50 | 46 | |
| 47 | + $match = -100; |
| 48 | + |
51 | 49 | foreach ( $keys as $index => $tkey ) { |
52 | 50 | if ( $key === strtolower( strtr( $tkey, ' ', '_' ) ) ) { |
| 51 | + $match = $index; |
53 | 52 | break; |
54 | 53 | } |
55 | | - if ( $index === $count -1 ) { |
56 | | - $index = -666; |
57 | | - } |
58 | 54 | } |
59 | 55 | |
60 | | - if ( isset( $keys[$index -1] ) ) { |
61 | | - $prev = $keys[$index -1]; |
| 56 | + if ( isset( $keys[$match -1] ) ) { |
| 57 | + $prev = $keys[$match -1]; |
62 | 58 | } |
63 | | - if ( isset( $keys[$index + 1] ) ) { |
64 | | - $next = $keys[$index + 1]; |
| 59 | + if ( isset( $keys[$match + 1] ) ) { |
| 60 | + $next = $keys[$match + 1]; |
65 | 61 | } |
66 | 62 | |
67 | 63 | $id = $group->getId(); |
— | — | @@ -122,10 +118,8 @@ |
123 | 119 | /** |
124 | 120 | * Keep the usual diiba daaba hidden from translators. |
125 | 121 | * Hook: AlternateEdit |
126 | | - * @param $editpage EditPage |
127 | | - * @return bool |
128 | 122 | */ |
129 | | - public static function intro( $editpage ) { |
| 123 | + public static function intro( EditPage $editpage ) { |
130 | 124 | $editpage->suppressIntro = true; |
131 | 125 | |
132 | 126 | $msg = wfMsgForContent( 'translate-edit-tag-warning' ); |
— | — | @@ -139,10 +133,8 @@ |
140 | 134 | /** |
141 | 135 | * Adds the translation aids and navigation to the normal edit page. |
142 | 136 | * Hook: EditPage::showEditForm:initial |
143 | | - * @param $object |
144 | | - * @return bool |
145 | 137 | */ |
146 | | - static function addTools( $object ) { |
| 138 | + static function addTools( EditPage $object ) { |
147 | 139 | $handle = new MessageHandle( $object->mTitle ); |
148 | 140 | if ( !$handle->isValid() ) { |
149 | 141 | return true; |
— | — | @@ -156,23 +148,17 @@ |
157 | 149 | * Replace the normal save button with one that says if you are editing |
158 | 150 | * message documentation to try to avoid accidents. |
159 | 151 | * Hook: EditPageBeforeEditButtons |
160 | | - * @param $editpage EditPage |
161 | | - * @param $buttons |
162 | | - * @param $tabindex |
163 | | - * @return bool |
164 | 152 | */ |
165 | | - static function buttonHack( $editpage, &$buttons, $tabindex ) { |
166 | | - global $wgTranslateDocumentationLanguageCode, $wgLang; |
| 153 | + static function buttonHack( EditPage $editpage, &$buttons, $tabindex ) { |
| 154 | + global $wgLang; |
167 | 155 | |
168 | 156 | $handle = new MessageHandle( $editpage->mTitle ); |
169 | 157 | if ( !$handle->isValid() ) { |
170 | 158 | return true; |
171 | 159 | } |
172 | 160 | |
173 | | - $code = $handle->getCode(); |
174 | | - |
175 | | - if ( $code === $wgTranslateDocumentationLanguageCode ) { |
176 | | - $name = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() ); |
| 161 | + if ( $handle->isDoc() ) { |
| 162 | + $name = TranslateUtils::getLanguageName( $handle->getCode(), false, $wgLang->getCode() ); |
177 | 163 | $temp = array( |
178 | 164 | 'id' => 'wpSave', |
179 | 165 | 'name' => 'wpSave', |
— | — | @@ -270,7 +256,7 @@ |
271 | 257 | * @param $object |
272 | 258 | * @return String |
273 | 259 | */ |
274 | | - private static function editBoxes( $object ) { |
| 260 | + private static function editBoxes( EditPage $object ) { |
275 | 261 | global $wgOut, $wgRequest; |
276 | 262 | |
277 | 263 | $th = new TranslationHelpers( $object->mTitle ); |
— | — | @@ -310,28 +296,20 @@ |
311 | 297 | /** |
312 | 298 | * Removes protection tab for message namespaces - not useful. |
313 | 299 | * Hook: SkinTemplateTabs |
314 | | - * @param $skin Skin |
315 | | - * @param $tabs |
316 | | - * @return bool |
317 | 300 | */ |
318 | | - public static function tabs( $skin, &$tabs ) { |
| 301 | + public static function tabs( Skin $skin, &$tabs ) { |
319 | 302 | $handle = new MessageHandle( $skin->getTitle() ); |
320 | | - if ( !$handle->isMessageNamespace() ) { |
321 | | - return true; |
| 303 | + if ( $handle->isMessageNamespace() ) { |
| 304 | + unset( $tabs['protect'] ); |
322 | 305 | } |
323 | 306 | |
324 | | - unset( $tabs['protect'] ); |
325 | | - |
326 | 307 | return true; |
327 | 308 | } |
328 | 309 | |
329 | 310 | /** |
330 | 311 | * Hook: EditPage::showEditForm:fields |
331 | | - * @param $edit |
332 | | - * @param $out OutputPage |
333 | | - * @return bool |
334 | 312 | */ |
335 | | - public static function keepFields( $edit, $out ) { |
| 313 | + public static function keepFields( EditPage $edit, OutputPage $out ) { |
336 | 314 | global $wgRequest; |
337 | 315 | |
338 | 316 | $out->addHTML( "\n" . |
— | — | @@ -344,17 +322,8 @@ |
345 | 323 | } |
346 | 324 | |
347 | 325 | /** |
| 326 | + * Runs message checks, adds tp:transver tags and updates statistics. |
348 | 327 | * Hook: ArticleSaveComplete |
349 | | - * @param $article Article |
350 | | - * @param $user User |
351 | | - * @param $text string |
352 | | - * @param $summary string |
353 | | - * @param $minor bool |
354 | | - * @param $_ |
355 | | - * @param $_ |
356 | | - * @param $flags |
357 | | - * @param $revision Revision |
358 | | - * @return bool |
359 | 328 | */ |
360 | 329 | public static function onSave( $article, $user, $text, $summary, |
361 | 330 | $minor, $_, $_, $flags, $revision |
— | — | @@ -385,18 +354,14 @@ |
386 | 355 | } |
387 | 356 | |
388 | 357 | /** |
389 | | - * @param $handle MessageHandle |
390 | | - * @param $text |
391 | 358 | * @return bool |
392 | 359 | */ |
393 | | - protected static function checkNeedsFuzzy( MessageHandle $handle, $text ) { |
| 360 | + protected static function checkNeedsFuzzy( MessageHandle $handle, /*string*/$text ) { |
394 | 361 | // Check for explicit tag. |
395 | 362 | $fuzzy = self::hasFuzzyString( $text ); |
396 | 363 | |
397 | 364 | // Docs are exempt for checks |
398 | | - global $wgTranslateDocumentationLanguageCode; |
399 | | - $code = $handle->getCode(); |
400 | | - if ( $code === $wgTranslateDocumentationLanguageCode ) { |
| 365 | + if ( $handle->isDoc() ) { |
401 | 366 | return $fuzzy; |
402 | 367 | } |
403 | 368 | |
— | — | @@ -407,6 +372,7 @@ |
408 | 373 | return $fuzzy; |
409 | 374 | } |
410 | 375 | |
| 376 | + $code = $handle->getCode(); |
411 | 377 | $key = $handle->getKey(); |
412 | 378 | $en = $group->getMessage( $key, $group->getSourceLanguage() ); |
413 | 379 | $message = new FatMessage( $key, $en ); |
— | — | @@ -422,8 +388,8 @@ |
423 | 389 | |
424 | 390 | /** |
425 | 391 | * @param $title Title |
426 | | - * @param $revision |
427 | | - * @param $fuzzy |
| 392 | + * @param $revision int |
| 393 | + * @param $fuzzy bool |
428 | 394 | */ |
429 | 395 | protected static function updateFuzzyTag( Title $title, $revision, $fuzzy ) { |
430 | 396 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -485,47 +451,11 @@ |
486 | 452 | } |
487 | 453 | |
488 | 454 | /** |
489 | | - * @param $text string |
490 | | - * @return string |
491 | | - */ |
492 | | - public static function preserveWhitespaces( $text ) { |
493 | | - $text = wfEscapeWikiText( $text ); |
494 | | - $text = preg_replace( '/^ /m', ' ', $text ); |
495 | | - $text = preg_replace( '/ $/m', ' ', $text ); |
496 | | - $text = preg_replace( '/ /', '  ', $text ); |
497 | | - $text = str_replace( "\n", '<br />', $text ); |
498 | | - return $text; |
499 | | - } |
500 | | - |
501 | | - /** |
502 | | - * Hook: LanguageGetTranslatedLanguageNames |
503 | | - * @param $names |
504 | | - * @param $code |
505 | | - * @return bool |
506 | | - */ |
507 | | - public static function translateMessageDocumentationLanguage( &$names, $code ) { |
508 | | - global $wgTranslateDocumentationLanguageCode; |
509 | | - if ( $wgTranslateDocumentationLanguageCode ) { |
510 | | - $names[$wgTranslateDocumentationLanguageCode] = |
511 | | - wfMessage( 'translate-documentation-language' )->inLanguage( $code )->plain(); |
512 | | - } |
513 | | - return true; |
514 | | - } |
515 | | - |
516 | | - /** |
517 | 455 | * Hook: ArticlePrepareTextForEdit |
518 | | - * @param $article Article |
519 | | - * @param $popts ParserOptions |
520 | | - * @return bool |
521 | 456 | */ |
522 | | - public static function disablePreSaveTransform( $article, $popts ) { |
523 | | - global $wgTranslateDocumentationLanguageCode; |
524 | | - |
| 457 | + public static function disablePreSaveTransform( $article, ParserOptions $popts ) { |
525 | 458 | $handle = new MessageHandle( $article->getTitle() ); |
526 | | - $code = $handle->getCode(); |
527 | | - if ( $handle->isMessageNamespace() |
528 | | - && $code !== $wgTranslateDocumentationLanguageCode ) { |
529 | | - |
| 459 | + if ( $handle->isMessageNamespace() && !$handle->isDoc() ) { |
530 | 460 | $popts->setPreSaveTransform( false ); |
531 | 461 | } |
532 | 462 | return true; |
— | — | @@ -533,11 +463,8 @@ |
534 | 464 | |
535 | 465 | /** |
536 | 466 | * Hook: ArticleContentOnDiff |
537 | | - * @param $de DifferenceEngine |
538 | | - * @param $out OutputPage |
539 | | - * @return bool |
540 | 467 | */ |
541 | | - public static function displayOnDiff( $de, $out ) { |
| 468 | + public static function displayOnDiff( DifferenceEngine $de, OutputPage $out ) { |
542 | 469 | $title = $de->getTitle(); |
543 | 470 | $handle = new MessageHandle( $title ); |
544 | 471 | |
— | — | @@ -562,98 +489,4 @@ |
563 | 490 | return false; |
564 | 491 | } |
565 | 492 | |
566 | | - /** |
567 | | - * Hook: SpecialSearchProfiles |
568 | | - * @param $profiles array |
569 | | - * @return bool |
570 | | - */ |
571 | | - public static function searchProfile( &$profiles ) { |
572 | | - global $wgTranslateMessageNamespaces; |
573 | | - $insert = array(); |
574 | | - $insert['translation'] = array( |
575 | | - 'message' => 'translate-searchprofile', |
576 | | - 'tooltip' => 'translate-searchprofile-tooltip', |
577 | | - 'namespaces' => $wgTranslateMessageNamespaces, |
578 | | - ); |
579 | | - |
580 | | - $profiles = wfArrayInsertAfter( $profiles, $insert, 'help' ); |
581 | | - return true; |
582 | | - } |
583 | | - |
584 | | - /** |
585 | | - * Hook: SpecialSearchProfileForm |
586 | | - * @param $search |
587 | | - * @param $form |
588 | | - * @param $profile |
589 | | - * @param $term |
590 | | - * @param $opts |
591 | | - * @return bool |
592 | | - */ |
593 | | - public static function searchProfileForm( $search, &$form, $profile, $term, $opts ) { |
594 | | - if ( $profile !== 'translation' ) { |
595 | | - return true; |
596 | | - } |
597 | | - |
598 | | - if ( !$search->getSearchEngine()->supports( 'title-suffix-filter' ) ) { |
599 | | - return false; |
600 | | - } |
601 | | - |
602 | | - $hidden = ''; |
603 | | - foreach ( $opts as $key => $value ) { |
604 | | - $hidden .= Html::hidden( $key, $value ); |
605 | | - } |
606 | | - |
607 | | - $context = $search->getContext(); |
608 | | - $code = $context->getLang()->getCode(); |
609 | | - $selected = $context->getRequest()->getVal( 'languagefilter' ); |
610 | | - |
611 | | - if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
612 | | - $languages = LanguageNames::getNames( $code, |
613 | | - LanguageNames::FALLBACK_NORMAL, |
614 | | - LanguageNames::LIST_MW |
615 | | - ); |
616 | | - } else { |
617 | | - $languages = Language::getLanguageNames( false ); |
618 | | - } |
619 | | - |
620 | | - ksort( $languages ); |
621 | | - |
622 | | - $selector = new HTMLSelector( 'languagefilter', 'languagefilter', $selected ); |
623 | | - $selector->addOption( wfMessage( 'translate-search-nofilter' ), '-' ); |
624 | | - foreach ( $languages as $code => $name ) { |
625 | | - $selector->addOption( "$code - $name", $code ); |
626 | | - } |
627 | | - |
628 | | - $selector = $selector->getHTML(); |
629 | | - |
630 | | - $label = Xml::label( wfMessage( 'translate-search-languagefilter' ), 'languagefilter' ) . ' '; |
631 | | - $params = array( 'id' => 'mw-searchoptions' ); |
632 | | - |
633 | | - $form = Xml::fieldset( false, false, $params ) . |
634 | | - $hidden . $label . $selector . |
635 | | - Html::closeElement( 'fieldset' ); |
636 | | - return false; |
637 | | - } |
638 | | - |
639 | | - /** |
640 | | - * Hook: SpecialSearchSetupEngine |
641 | | - * @param $search |
642 | | - * @param $profile |
643 | | - * @param $engine |
644 | | - * @return bool |
645 | | - */ |
646 | | - public static function searchProfileSetupEngine( $search, $profile, $engine ) { |
647 | | - if ( $profile !== 'translation' ) { |
648 | | - return true; |
649 | | - } |
650 | | - |
651 | | - $context = $search->getContext(); |
652 | | - $selected = $context->getRequest()->getVal( 'languagefilter' ); |
653 | | - if ( $selected !== '-' && $selected ) { |
654 | | - $engine->setFeatureData( 'title-suffix-filter', "/$selected" ); |
655 | | - $search->setExtraParam( 'languagefilter', $selected ); |
656 | | - } |
657 | | - return true; |
658 | | - } |
659 | | - |
660 | 493 | } |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | $wgHooks['EditPageBeforeEditButtons'][] = 'TranslateEditAddons::buttonHack'; |
96 | 96 | $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields'; |
97 | 97 | $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs'; |
98 | | -$wgHooks['LanguageGetTranslatedLanguageNames'][] = 'TranslateEditAddons::translateMessageDocumentationLanguage'; |
| 98 | +$wgHooks['LanguageGetTranslatedLanguageNames'][] = 'TranslateHooks::translateMessageDocumentationLanguage'; |
99 | 99 | $wgHooks['ArticlePrepareTextForEdit'][] = 'TranslateEditAddons::disablePreSaveTransform'; |
100 | 100 | // Fuzzy tags for speed. |
101 | 101 | $wgHooks['ArticleSaveComplete'][] = 'TranslateEditAddons::onSave'; |
— | — | @@ -120,9 +120,9 @@ |
121 | 121 | $wgHooks['ArticleContentOnDiff'][] = 'TranslateEditAddons::displayOnDiff'; |
122 | 122 | |
123 | 123 | // Search profile |
124 | | -$wgHooks['SpecialSearchProfiles'][] = 'TranslateEditAddons::searchProfile'; |
125 | | -$wgHooks['SpecialSearchProfileForm'][] = 'TranslateEditAddons::searchProfileForm'; |
126 | | -$wgHooks['SpecialSearchSetupEngine'][] = 'TranslateEditAddons::searchProfileSetupEngine'; |
| 124 | +$wgHooks['SpecialSearchProfiles'][] = 'TranslateHooks::searchProfile'; |
| 125 | +$wgHooks['SpecialSearchProfileForm'][] = 'TranslateHooks::searchProfileForm'; |
| 126 | +$wgHooks['SpecialSearchSetupEngine'][] = 'TranslateHooks::searchProfileSetupEngine'; |
127 | 127 | |
128 | 128 | $wgHooks['LinkBegin'][] = 'SpecialMyLanguage::linkfix'; |
129 | 129 | |
Index: trunk/extensions/Translate/TranslateHooks.php |
— | — | @@ -215,4 +215,97 @@ |
216 | 216 | return true; |
217 | 217 | } |
218 | 218 | |
| 219 | + /** |
| 220 | + * Hook: LanguageGetTranslatedLanguageNames |
| 221 | + */ |
| 222 | + public static function translateMessageDocumentationLanguage( &$names, $code ) { |
| 223 | + global $wgTranslateDocumentationLanguageCode; |
| 224 | + if ( $wgTranslateDocumentationLanguageCode ) { |
| 225 | + $names[$wgTranslateDocumentationLanguageCode] = |
| 226 | + wfMessage( 'translate-documentation-language' )->inLanguage( $code )->plain(); |
| 227 | + } |
| 228 | + return true; |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Hook: SpecialSearchProfiles |
| 233 | + */ |
| 234 | + public static function searchProfile( array &$profiles ) { |
| 235 | + global $wgTranslateMessageNamespaces; |
| 236 | + $insert = array(); |
| 237 | + $insert['translation'] = array( |
| 238 | + 'message' => 'translate-searchprofile', |
| 239 | + 'tooltip' => 'translate-searchprofile-tooltip', |
| 240 | + 'namespaces' => $wgTranslateMessageNamespaces, |
| 241 | + ); |
| 242 | + |
| 243 | + $profiles = wfArrayInsertAfter( $profiles, $insert, 'help' ); |
| 244 | + return true; |
| 245 | + } |
| 246 | + |
| 247 | + /** |
| 248 | + * Hook: SpecialSearchProfileForm |
| 249 | + */ |
| 250 | + public static function searchProfileForm( $search, &$form, /*string*/ $profile, $term, $opts ) { |
| 251 | + if ( $profile !== 'translation' ) { |
| 252 | + return true; |
| 253 | + } |
| 254 | + |
| 255 | + if ( !$search->getSearchEngine()->supports( 'title-suffix-filter' ) ) { |
| 256 | + return false; |
| 257 | + } |
| 258 | + |
| 259 | + $hidden = ''; |
| 260 | + foreach ( $opts as $key => $value ) { |
| 261 | + $hidden .= Html::hidden( $key, $value ); |
| 262 | + } |
| 263 | + |
| 264 | + $context = $search->getContext(); |
| 265 | + $code = $context->getLang()->getCode(); |
| 266 | + $selected = $context->getRequest()->getVal( 'languagefilter' ); |
| 267 | + |
| 268 | + if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
| 269 | + $languages = LanguageNames::getNames( $code, |
| 270 | + LanguageNames::FALLBACK_NORMAL, |
| 271 | + LanguageNames::LIST_MW |
| 272 | + ); |
| 273 | + } else { |
| 274 | + $languages = Language::getLanguageNames( false ); |
| 275 | + } |
| 276 | + |
| 277 | + ksort( $languages ); |
| 278 | + |
| 279 | + $selector = new HTMLSelector( 'languagefilter', 'languagefilter', $selected ); |
| 280 | + $selector->addOption( wfMessage( 'translate-search-nofilter' ), '-' ); |
| 281 | + foreach ( $languages as $code => $name ) { |
| 282 | + $selector->addOption( "$code - $name", $code ); |
| 283 | + } |
| 284 | + |
| 285 | + $selector = $selector->getHTML(); |
| 286 | + |
| 287 | + $label = Xml::label( wfMessage( 'translate-search-languagefilter' ), 'languagefilter' ) . ' '; |
| 288 | + $params = array( 'id' => 'mw-searchoptions' ); |
| 289 | + |
| 290 | + $form = Xml::fieldset( false, false, $params ) . |
| 291 | + $hidden . $label . $selector . |
| 292 | + Html::closeElement( 'fieldset' ); |
| 293 | + return false; |
| 294 | + } |
| 295 | + |
| 296 | + /// Hook: SpecialSearchSetupEngine |
| 297 | + public static function searchProfileSetupEngine( $search, /*string*/ $profile, SearchEngine $engine ) { |
| 298 | + if ( $profile !== 'translation' ) { |
| 299 | + return true; |
| 300 | + } |
| 301 | + |
| 302 | + $context = $search->getContext(); |
| 303 | + $selected = $context->getRequest()->getVal( 'languagefilter' ); |
| 304 | + if ( $selected !== '-' && $selected ) { |
| 305 | + $engine->setFeatureData( 'title-suffix-filter', "/$selected" ); |
| 306 | + $search->setExtraParam( 'languagefilter', $selected ); |
| 307 | + } |
| 308 | + return true; |
| 309 | + } |
| 310 | + |
| 311 | + |
219 | 312 | } |