r79642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79641‎ | r79642 | r79643 >
Date:12:24, 5 January 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Allow OutputPage::parse() to parse in any langauge, modified wfMsgExt() and wfMessage() accordingly
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Message.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -756,12 +756,15 @@
757757 if( in_array( 'content', $options, true ) ) {
758758 $forContent = true;
759759 $langCode = true;
 760+ $langCodeObj = null;
760761 } elseif( array_key_exists( 'language', $options ) ) {
761762 $forContent = false;
762763 $langCode = wfGetLangObj( $options['language'] );
 764+ $langCodeObj = $langCode;
763765 } else {
764766 $forContent = false;
765767 $langCode = false;
 768+ $langCodeObj = null;
766769 }
767770
768771 $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false );
@@ -771,9 +774,9 @@
772775 }
773776
774777 if( in_array( 'parse', $options, true ) ) {
775 - $string = $wgOut->parse( $string, true, !$forContent );
 778+ $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
776779 } elseif ( in_array( 'parseinline', $options, true ) ) {
777 - $string = $wgOut->parse( $string, true, !$forContent );
 780+ $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
778781 $m = array();
779782 if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
780783 $string = $m[1];
@@ -782,8 +785,7 @@
783786 global $wgMessageCache;
784787 if ( isset( $wgMessageCache ) ) {
785788 $string = $wgMessageCache->transform( $string,
786 - !$forContent,
787 - is_object( $langCode ) ? $langCode : null );
 789+ !$forContent, $langCodeObj );
788790 }
789791 }
790792
Index: trunk/phase3/includes/OutputPage.php
@@ -1227,24 +1227,37 @@
12281228 * @param $interface Boolean: use interface language ($wgLang instead of
12291229 * $wgContLang) while parsing language sensitive magic
12301230 * words like GRAMMAR and PLURAL
 1231+ * @param $language Language object: target language object, will override
 1232+ * $interface
12311233 * @return String: HTML
12321234 */
1233 - public function parse( $text, $linestart = true, $interface = false ) {
 1235+ public function parse( $text, $linestart = true, $interface = false, $language = null ) {
12341236 global $wgParser;
 1237+
12351238 if( is_null( $this->getTitle() ) ) {
12361239 throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
12371240 }
 1241+
12381242 $popts = $this->parserOptions();
12391243 if ( $interface ) {
12401244 $popts->setInterfaceMessage( true );
12411245 }
 1246+ if ( $language !== null ) {
 1247+ $oldLang = $popts->setTargetLanguage( $language );
 1248+ }
 1249+
12421250 $parserOutput = $wgParser->parse(
12431251 $text, $this->getTitle(), $popts,
12441252 $linestart, true, $this->mRevisionId
12451253 );
 1254+
12461255 if ( $interface ) {
12471256 $popts->setInterfaceMessage( false );
12481257 }
 1258+ if ( $language !== null ) {
 1259+ $popts->setTargetLanguage( $oldLang );
 1260+ }
 1261+
12491262 return $parserOutput->getText();
12501263 }
12511264
Index: trunk/phase3/includes/Message.php
@@ -315,12 +315,8 @@
316316 * @return Wikitext parsed into HTML
317317 */
318318 protected function parseText( $string ) {
319 - global $wgOut, $wgLang, $wgContLang;
320 - if ( $this->language !== $wgLang && $this->language !== $wgContLang ) {
321 - # FIXME: remove this limitation
322 - throw new MWException( 'Can only parse in interface or content language' );
323 - }
324 - return $wgOut->parse( $string, /*linestart*/true, $this->interface );
 319+ global $wgOut;
 320+ return $wgOut->parse( $string, /*linestart*/true, $this->interface, $this->language );
325321 }
326322
327323 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r86828Fix comment, language is handled correctly with parse and parseinline since r...ialex18:47, 24 April 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   22:39, 14 June 2011

- # FIXME: remove this limitation

Why *was* it there?

Status & tagging log