Index: trunk/extensions/Translate/tests/pagetranslation/Nowiki.ptfile |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +I just want to speak about <nowiki><translate></nowiki>. |
| 3 | + |
| 4 | +<translate>Yes!</translate> |
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiOnly.ptfile |
— | — | @@ -0,0 +1 @@ |
| 2 | +<nowiki><translate></nowiki> |
\ No newline at end of file |
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiOnly.pttest |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 5 | + |
| 6 | +if ( $parse->countSections() !== 0 ) { |
| 7 | + $this->output( "Testfile $filename failed misc tests... number of sections should be zero" ); |
| 8 | +} |
\ No newline at end of file |
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiInside.pttarget |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +I just want to speak about <nowiki><translate></nowiki>. |
| 3 | + |
| 4 | +Yes! |
Index: trunk/extensions/Translate/tests/pagetranslation/Nowiki.pttarget |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +I just want to speak about <nowiki><translate></nowiki>. |
| 3 | + |
| 4 | +Yes! |
Index: trunk/extensions/Translate/tests/pagetranslation/FailDoubleOpen.ptfile |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +<translate> |
| 3 | +<translate> |
| 4 | +</translate> |
\ No newline at end of file |
Index: trunk/extensions/Translate/tests/pagetranslation/NowikiInside.ptfile |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +<translate> |
| 3 | +I just want to speak about <nowiki><translate></nowiki>. |
| 4 | + |
| 5 | +Yes!</translate> |
Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -139,6 +139,9 @@ |
140 | 140 | |
141 | 141 | $text = $this->getText(); |
142 | 142 | |
| 143 | + $nowiki = array(); |
| 144 | + $text = self::armourNowiki( $nowiki, $text ); |
| 145 | + |
143 | 146 | $sections = array(); |
144 | 147 | $tagPlaceHolders = array(); |
145 | 148 | |
— | — | @@ -149,7 +152,7 @@ |
150 | 153 | if ( $ok === 0 ) break; // No matches |
151 | 154 | |
152 | 155 | // Do-placehold for the whole stuff |
153 | | - $ph = $this->getUniq(); |
| 156 | + $ph = self::getUniq(); |
154 | 157 | $start = $matches[0][0][1]; |
155 | 158 | $len = strlen( $matches[0][0][0] ); |
156 | 159 | $end = $start + $len; |
— | — | @@ -168,6 +171,8 @@ |
169 | 172 | throw new TPException( array( 'pt-parse-nested', $sectiontext ) ); |
170 | 173 | } |
171 | 174 | |
| 175 | + $sectiontext = self::unArmourNowiki( $nowiki, $sectiontext ); |
| 176 | + |
172 | 177 | $ret = $this->sectionise( $sections, $sectiontext ); |
173 | 178 | |
174 | 179 | $tagPlaceHolders[$ph] = |
— | — | @@ -188,6 +193,8 @@ |
189 | 194 | $text = str_replace( $ph, $value, $text ); |
190 | 195 | } |
191 | 196 | |
| 197 | + $text = self::unArmourNowiki( $nowiki, $text ); |
| 198 | + |
192 | 199 | $parse = new TPParse( $this->getTitle() ); |
193 | 200 | $parse->template = $text; |
194 | 201 | $parse->sections = $sections; |
— | — | @@ -200,10 +207,27 @@ |
201 | 208 | |
202 | 209 | // Inner functionality // |
203 | 210 | |
| 211 | + public static function armourNowiki( &$holders, $text ) { |
| 212 | + $re = '~(<nowiki>)(.*?)(</nowiki>)~'; |
| 213 | + while ( preg_match( $re, $text, $matches ) ) { |
| 214 | + $ph = self::getUniq(); |
| 215 | + $text = str_replace( $matches[0], $ph, $text ); |
| 216 | + $holders[$ph] = $matches[0]; |
| 217 | + } |
| 218 | + return $text; |
| 219 | + } |
| 220 | + |
| 221 | + public static function unArmourNowiki( $holders, $text ) { |
| 222 | + foreach ( $holders as $ph => $value ) { |
| 223 | + $text = str_replace( $ph, $value, $text ); |
| 224 | + } |
| 225 | + return $text; |
| 226 | + } |
| 227 | + |
204 | 228 | /** |
205 | 229 | * Returns a random string that can be used as placeholder. |
206 | 230 | */ |
207 | | - protected function getUniq() { |
| 231 | + protected static function getUniq() { |
208 | 232 | static $i = 0; |
209 | 233 | return "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ) . '|' . $i++; |
210 | 234 | } |
— | — | @@ -229,7 +253,7 @@ |
230 | 254 | if ( trim( $_ ) === '' ) { |
231 | 255 | $template .= $_; |
232 | 256 | } else { |
233 | | - $ph = $this->getUniq(); |
| 257 | + $ph = self::getUniq(); |
234 | 258 | $sections[$ph] = $this->shakeSection( $_ ); |
235 | 259 | $template .= $ph; |
236 | 260 | } |
Index: trunk/extensions/Translate/tag/TPParse.php |
— | — | @@ -141,9 +141,13 @@ |
142 | 142 | $text = str_replace( $ph, $sectiontext, $text ); |
143 | 143 | } |
144 | 144 | |
| 145 | + $nph = array(); |
| 146 | + $text = TranslatablePage::armourNowiki( $nph, $text ); |
| 147 | + |
145 | 148 | // Remove translation markup |
146 | 149 | $cb = array( __CLASS__, 'replaceTagCb' ); |
147 | 150 | $text = preg_replace_callback( '~(<translate>\n?)(.*?)(\n?</translate>)~s', $cb, $text ); |
| 151 | + $text = TranslatablePage::unArmourNowiki( $nph, $text ); |
148 | 152 | |
149 | 153 | return $text; |
150 | 154 | } |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -7,12 +7,15 @@ |
8 | 8 | |
9 | 9 | public static function renderTagPage( $parser, &$text, $state ) { |
10 | 10 | $title = $parser->getTitle(); |
11 | | - if ( strpos( $text, '</translate>' ) !== false ) { |
| 11 | + if ( strpos( $text, '<translate>' ) !== false ) { |
| 12 | + $nowiki = array(); |
| 13 | + $text = TranslatablePage::armourNowiki( $nowiki, $text ); |
12 | 14 | $cb = array( __CLASS__, 'replaceTagCb' ); |
13 | 15 | # Remove the tags nicely, trying to not leave excess whitespace lying around |
14 | | - $text = preg_replace_callback( '~(\n?<translate>\s*?)(.*?)(\s*?</translate>)~s', $cb, $text ); |
| 16 | + $text = preg_replace_callback( '~(<translate>)\s*(.*?)(</translate>)~s', $cb, $text ); |
15 | 17 | # Replace variable markers |
16 | 18 | $text = preg_replace_callback( '~(<tvar[^<>]+>)(.*)(</>)~s', $cb, $text ); |
| 19 | + $text = TranslatablePage::unArmourNowiki( $nowiki, $text ); |
17 | 20 | } |
18 | 21 | |
19 | 22 | // For translation pages, parse plural, grammar etc with correct language |
— | — | @@ -279,7 +282,9 @@ |
280 | 283 | |
281 | 284 | // Add the ready tag |
282 | 285 | $page = TranslatablePage::newFromTitle( $article->getTitle() ); |
283 | | - $page->addReadyTag( $revision->getId() ); |
| 286 | + if ( $page->getParse()->countSections() > 0 ) { |
| 287 | + $page->addReadyTag( $revision->getId() ); |
| 288 | + } |
284 | 289 | |
285 | 290 | return true; |
286 | 291 | } |