r67832 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67831‎ | r67832 | r67833 >
Date:19:17, 10 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Use same code for preprocessing both source and translation pages
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPParse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/TPParse.php
@@ -116,14 +116,16 @@
117117 return $text;
118118 }
119119
120 - public function getTranslationPageText( MessageCollection $collection ) {
 120+ public function getTranslationPageText( /*MessageCollection*/ $collection ) {
121121 $text = $this->template; // The source
122122
123123 // For finding the messages
124124 $prefix = $this->title->getPrefixedDBKey() . '/';
125125
126 - $collection->filter( 'hastranslation', false );
127 - $collection->loadTranslations();
 126+ if ( $collection instanceOf MessageCollection ) {
 127+ $collection->filter( 'hastranslation', false );
 128+ $collection->loadTranslations();
 129+ }
128130
129131 foreach ( $this->sections as $ph => $s ) {
130132 $sectiontext = null;
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -8,14 +8,8 @@
99 $title = $parser->getTitle();
1010
1111 if ( strpos( $text, '<translate>' ) !== false ) {
12 - $nowiki = array();
13 - $text = TranslatablePage::armourNowiki( $nowiki, $text );
14 - $cb = array( __CLASS__, 'replaceTagCb' );
15 - # Remove the tags nicely, trying to not leave excess whitespace lying around
16 - $text = preg_replace_callback( '~(<translate>\n??)(.*)(\n??</translate>)~sU', $cb, $text );
17 - # Replace variable markers
18 - $text = preg_replace_callback( '~(<tvar[^<>]+>)(.*)(</>)~s', $cb, $text );
19 - $text = TranslatablePage::unArmourNowiki( $nowiki, $text );
 12+ $parse = TranslatablePage::newFromText( $parser->getTitle(), $text )->getParse();
 13+ $text = $parse->getTranslationPageText( null );
2014 }
2115
2216 // For translation pages, parse plural, grammar etc with correct language

Status & tagging log