Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -447,15 +447,17 @@ |
448 | 448 | * @param string $langcode Code of the language to get the message for, or |
449 | 449 | * behaves as a content language switch if it is a |
450 | 450 | * boolean. |
| 451 | + * @param bool $fallback Whether or not to fallback to a different language if |
| 452 | + * it is not found in the selected one. |
451 | 453 | * @return string |
452 | 454 | * @private |
453 | 455 | */ |
454 | | -function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) { |
| 456 | +function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true, $fallback = true ) { |
455 | 457 | global $wgParser, $wgContLang, $wgMessageCache, $wgLang; |
456 | 458 | |
457 | 459 | # If $wgMessageCache isn't initialised yet, try to return something sensible. |
458 | 460 | if( is_object( $wgMessageCache ) ) { |
459 | | - $message = $wgMessageCache->get( $key, $useDB, $langCode ); |
| 461 | + $message = $wgMessageCache->get( $key, $useDB, $langCode, false, $fallback ); |
460 | 462 | if ( $transform ) { |
461 | 463 | $message = $wgMessageCache->transform( $message ); |
462 | 464 | } |
— | — | @@ -564,6 +566,7 @@ |
565 | 567 | * <i>replaceafter</i>: parameters are substituted after parsing or escaping |
566 | 568 | * <i>parsemag</i>: transform the message using magic phrases |
567 | 569 | * <i>content</i>: fetch message for content language instead of interface |
| 570 | + * <i>nofallback</i>: do not fallback to a different language |
568 | 571 | * <i>language</i>: language code to fetch message for (overriden by <i>content</i>), its behaviour |
569 | 572 | * with parser, parseinline and parsemag is undefined. |
570 | 573 | * Behavior for conflicting options (e.g., parse+parseinline) is undefined. |
— | — | @@ -594,8 +597,10 @@ |
595 | 598 | $langCode = false; |
596 | 599 | } |
597 | 600 | |
598 | | - $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false ); |
| 601 | + $fallback = !in_array('nofallback', $options); |
599 | 602 | |
| 603 | + $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false, /*Fallback*/$fallback ); |
| 604 | + |
600 | 605 | if( !in_array('replaceafter', $options) ) { |
601 | 606 | $string = wfMsgReplaceArgs( $string, $args ); |
602 | 607 | } |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -407,8 +407,10 @@ |
408 | 408 | * use the wikis content language (also as a |
409 | 409 | * fallback). |
410 | 410 | * @param bool $isFullKey Specifies whether $key is a two part key "lang/msg". |
| 411 | + * @param bool $fallback Whether or not to fallback to a different language if |
| 412 | + * it is not found in the selected one. |
411 | 413 | */ |
412 | | - function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) { |
| 414 | + function get( $key, $useDB = true, $langcode = true, $isFullKey = false, $fallback = true ) { |
413 | 415 | global $wgContLanguageCode, $wgContLang, $wgLang; |
414 | 416 | |
415 | 417 | # Identify which language to get or create a language object for. |
— | — | @@ -476,6 +478,11 @@ |
477 | 479 | } |
478 | 480 | } |
479 | 481 | |
| 482 | + # Don't fall back if asked not to. |
| 483 | + if( !$fallback ) { |
| 484 | + return '<' . htmlspecialchars($key) . '>'; |
| 485 | + } |
| 486 | + |
480 | 487 | # Try the array of another language |
481 | 488 | $pos = strrpos( $lckey, '/' ); |
482 | 489 | if( $message === false && $pos !== false) { |