Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -238,6 +238,8 @@ |
239 | 239 | * UtfNormal::cleanUp on an invalid utf-8 sequence no longer returns false if intl installed. |
240 | 240 | * (bug 28561) The css class small will no longer make nested elements even smaller. |
241 | 241 | * (bug 13172) Array type exif data (like GPS) was not being extracted from images. |
| 242 | +* (bug 28532) wfMsgExt() and wfMsgWikiHtml() use $wgOut->parse() |
| 243 | +* (bug 16129) Transcluded special pages expose strip markers when they output parsed messages |
242 | 244 | |
243 | 245 | === API changes in 1.18 === |
244 | 246 | * (bug 26339) Throw warning when truncating an overlarge API result |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -68,6 +68,11 @@ |
69 | 69 | private static $instance; |
70 | 70 | |
71 | 71 | /** |
| 72 | + * @var bool |
| 73 | + */ |
| 74 | + protected $mInParser = false; |
| 75 | + |
| 76 | + /** |
72 | 77 | * Get the signleton instance of this class |
73 | 78 | * |
74 | 79 | * @since 1.18 |
— | — | @@ -102,6 +107,8 @@ |
103 | 108 | |
104 | 109 | /** |
105 | 110 | * ParserOptions is lazy initialised. |
| 111 | + * |
| 112 | + * @return ParserOptions |
106 | 113 | */ |
107 | 114 | function getParserOptions() { |
108 | 115 | if ( !$this->mParserOptions ) { |
— | — | @@ -220,6 +227,8 @@ |
221 | 228 | |
222 | 229 | /** |
223 | 230 | * Set the cache to $cache, if it is valid. Otherwise set the cache to false. |
| 231 | + * |
| 232 | + * @return bool |
224 | 233 | */ |
225 | 234 | function setCache( $cache, $code ) { |
226 | 235 | if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION ) { |
— | — | @@ -728,12 +737,41 @@ |
729 | 738 | return $message; |
730 | 739 | } |
731 | 740 | |
| 741 | + /** |
| 742 | + * @param $message string |
| 743 | + * @param $interface bool |
| 744 | + * @param $language |
| 745 | + * @param $title Title |
| 746 | + * @return string |
| 747 | + */ |
732 | 748 | function transform( $message, $interface = false, $language = null, $title = null ) { |
733 | 749 | // Avoid creating parser if nothing to transform |
734 | 750 | if( strpos( $message, '{{' ) === false ) { |
735 | 751 | return $message; |
736 | 752 | } |
737 | 753 | |
| 754 | + if ( $this->mInParser ) { |
| 755 | + return $message; |
| 756 | + } |
| 757 | + |
| 758 | + $parser = $this->getParser(); |
| 759 | + if ( $parser ) { |
| 760 | + $popts = $this->getParserOptions(); |
| 761 | + $popts->setInterfaceMessage( $interface ); |
| 762 | + $popts->setTargetLanguage( $language ); |
| 763 | + $popts->setUserLang( $language ); |
| 764 | + |
| 765 | + $this->mInParser = true; |
| 766 | + $message = $parser->transformMsg( $message, $popts, $title ); |
| 767 | + $this->mInParser = false; |
| 768 | + } |
| 769 | + return $message; |
| 770 | + } |
| 771 | + |
| 772 | + /** |
| 773 | + * @return Parser |
| 774 | + */ |
| 775 | + function getParser() { |
738 | 776 | global $wgParser, $wgParserConf; |
739 | 777 | if ( !$this->mParser && isset( $wgParser ) ) { |
740 | 778 | # Do some initialisation so that we don't have to do it twice |
— | — | @@ -746,16 +784,38 @@ |
747 | 785 | } else { |
748 | 786 | $this->mParser = clone $wgParser; |
749 | 787 | } |
750 | | - #wfDebug( __METHOD__ . ": following contents triggered transform: $message\n" ); |
751 | 788 | } |
752 | | - if ( $this->mParser ) { |
753 | | - $popts = $this->getParserOptions(); |
754 | | - $popts->setInterfaceMessage( $interface ); |
| 789 | + return $this->mParser; |
| 790 | + } |
| 791 | + |
| 792 | + /** |
| 793 | + * @param $text string |
| 794 | + * @param $title Title |
| 795 | + * @param $interface bool |
| 796 | + * @param $linestart bool |
| 797 | + * @param $language |
| 798 | + * @return ParserOutput |
| 799 | + */ |
| 800 | + public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null ) { |
| 801 | + if ( $this->mInParser ) { |
| 802 | + return htmlspecialchars( $text ); |
| 803 | + } |
| 804 | + |
| 805 | + $parser = $this->getParser(); |
| 806 | + $popts = $this->getParserOptions(); |
| 807 | + |
| 808 | + if ( $interface ) { |
| 809 | + $popts->setInterfaceMessage( true ); |
| 810 | + } |
| 811 | + if ( $language !== null ) { |
755 | 812 | $popts->setTargetLanguage( $language ); |
756 | | - $popts->setUserLang( $language ); |
757 | | - $message = $this->mParser->transformMsg( $message, $popts, $title ); |
758 | 813 | } |
759 | | - return $message; |
| 814 | + |
| 815 | + $this->mInParser = true; |
| 816 | + $res = $parser->parse( $text, $title, $popts, $linestart ); |
| 817 | + $this->mInParser = false; |
| 818 | + |
| 819 | + return $res; |
760 | 820 | } |
761 | 821 | |
762 | 822 | function disable() { |
Index: trunk/phase3/includes/Message.php |
— | — | @@ -65,6 +65,8 @@ |
66 | 66 | /** |
67 | 67 | * In which language to get this message. Overrides the $interface |
68 | 68 | * variable. |
| 69 | + * |
| 70 | + * @var Language |
69 | 71 | */ |
70 | 72 | protected $language = null; |
71 | 73 | |
— | — | @@ -370,10 +372,18 @@ |
371 | 373 | return $message === false || $message === '' || $message === '-'; |
372 | 374 | } |
373 | 375 | |
| 376 | + /** |
| 377 | + * @param $value |
| 378 | + * @return array |
| 379 | + */ |
374 | 380 | public static function rawParam( $value ) { |
375 | 381 | return array( 'raw' => $value ); |
376 | 382 | } |
377 | | - |
| 383 | + |
| 384 | + /** |
| 385 | + * @param $value |
| 386 | + * @return array |
| 387 | + */ |
378 | 388 | public static function numParam( $value ) { |
379 | 389 | return array( 'num' => $value ); |
380 | 390 | } |
— | — | @@ -419,17 +429,16 @@ |
420 | 430 | /** |
421 | 431 | * Wrapper for what ever method we use to parse wikitext. |
422 | 432 | * @param $string String: Wikitext message contents |
423 | | - * @return Wikitext parsed into HTML |
| 433 | + * @return string Wikitext parsed into HTML |
424 | 434 | */ |
425 | 435 | protected function parseText( $string ) { |
426 | | - global $wgOut; |
427 | | - return $wgOut->parse( $string, /*linestart*/true, $this->interface, $this->language ); |
| 436 | + return MessageCache::singleton()->parse( $string, /*linestart*/true, $this->interface, $this->language ); |
428 | 437 | } |
429 | 438 | |
430 | 439 | /** |
431 | 440 | * Wrapper for what ever method we use to {{-transform wikitext. |
432 | 441 | * @param $string String: Wikitext message contents |
433 | | - * @return Wikitext with {{-constructs replaced with their values. |
| 442 | + * @return string Wikitext with {{-constructs replaced with their values. |
434 | 443 | */ |
435 | 444 | protected function transformText( $string ) { |
436 | 445 | return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title ); |
— | — | @@ -450,6 +459,8 @@ |
451 | 460 | |
452 | 461 | /** |
453 | 462 | * Wrapper for what ever method we use to get message contents |
| 463 | + * |
| 464 | + * @return string |
454 | 465 | */ |
455 | 466 | protected function fetchMessage() { |
456 | 467 | if ( !isset( $this->message ) ) { |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | * Do not call this function recursively. |
280 | 280 | * |
281 | 281 | * @param $text String: text we want to parse |
282 | | - * @param $title A title object |
| 282 | + * @param $title Title object |
283 | 283 | * @param $options ParserOptions |
284 | 284 | * @param $linestart boolean |
285 | 285 | * @param $clearState boolean |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -792,7 +792,7 @@ |
793 | 793 | * @param $t Title object |
794 | 794 | */ |
795 | 795 | public function setTitle( $t ) { |
796 | | - $this->getContext()->setTitle($t); |
| 796 | + $this->getContext()->setTitle( $t ); |
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -716,10 +716,12 @@ |
717 | 717 | * @return string |
718 | 718 | */ |
719 | 719 | function wfMsgWikiHtml( $key ) { |
720 | | - global $wgOut; |
| 720 | + global $wgMessageCache; |
721 | 721 | $args = func_get_args(); |
722 | 722 | array_shift( $args ); |
723 | | - return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args ); |
| 723 | + return wfMsgReplaceArgs( |
| 724 | + $wgMessageCache->parse( wfMsgGetKey( $key, true ), null, /* can't be set to false */ true ), |
| 725 | + $args ); |
724 | 726 | } |
725 | 727 | |
726 | 728 | /** |
— | — | @@ -741,7 +743,7 @@ |
742 | 744 | * Behavior for conflicting options (e.g., parse+parseinline) is undefined. |
743 | 745 | */ |
744 | 746 | function wfMsgExt( $key, $options ) { |
745 | | - global $wgOut; |
| 747 | + global $wgMessageCache; |
746 | 748 | |
747 | 749 | $args = func_get_args(); |
748 | 750 | array_shift( $args ); |
— | — | @@ -781,9 +783,9 @@ |
782 | 784 | } |
783 | 785 | |
784 | 786 | if( in_array( 'parse', $options, true ) ) { |
785 | | - $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
| 787 | + $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj ); |
786 | 788 | } elseif ( in_array( 'parseinline', $options, true ) ) { |
787 | | - $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
| 789 | + $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj ); |
788 | 790 | $m = array(); |
789 | 791 | if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { |
790 | 792 | $string = $m[1]; |