Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -3304,6 +3304,7 @@ |
3305 | 3305 | throw new MWException( '<html> extension tag encountered unexpectedly' ); |
3306 | 3306 | } |
3307 | 3307 | case 'nowiki': |
| 3308 | + $content = strtr($content, array('-{' => '-{', '}-' => '}-')); |
3308 | 3309 | $output = Xml::escapeTagsOnly( $content ); |
3309 | 3310 | break; |
3310 | 3311 | case 'math': |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @ingroup Language |
15 | 15 | * |
16 | 16 | * @author Zhengzhu Feng <zhengzhu@gmail.com> |
17 | | - * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com> |
| 17 | + * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com>, PhiLiP <philip.npc@gmail.com> |
18 | 18 | */ |
19 | 19 | class LanguageConverter { |
20 | 20 | var $mPreferredVariant=''; |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | var $mVariants, $mVariantFallbacks, $mVariantNames; |
23 | 23 | var $mTablesLoaded = false; |
24 | 24 | var $mTables; |
| 25 | + var $mManualAddTables; |
| 26 | + var $mManualRemoveTables; |
25 | 27 | var $mTitleDisplay=''; |
26 | 28 | var $mDoTitleConvert=true, $mDoContentConvert=true; |
27 | 29 | var $mManualLevel; // 'bidirectional' 'unidirectional' 'disable' for each variants |
— | — | @@ -81,10 +83,13 @@ |
82 | 84 | 'N'=>'N' // current variant name |
83 | 85 | ); |
84 | 86 | $this->mFlags = array_merge($f, $flags); |
85 | | - foreach( $this->mVariants as $v) |
| 87 | + foreach( $this->mVariants as $v) { |
86 | 88 | $this->mManualLevel[$v]=array_key_exists($v,$manualLevel) |
87 | 89 | ?$manualLevel[$v] |
88 | 90 | :'bidirectional'; |
| 91 | + $this->mManualAddTables[$v] = array(); |
| 92 | + $this->mManualRemoveTables[$v] = array(); |
| 93 | + } |
89 | 94 | } |
90 | 95 | |
91 | 96 | /** |
— | — | @@ -323,13 +328,12 @@ |
324 | 329 | |
325 | 330 | return $ret; |
326 | 331 | } |
327 | | - |
328 | | - |
| 332 | + |
329 | 333 | /** |
330 | | - * apply manual conversion |
| 334 | + * prepare manual conversion table |
331 | 335 | * @private |
332 | 336 | */ |
333 | | - function applyManualConv($convRule){ |
| 337 | + function prepareManualConv($convRule){ |
334 | 338 | // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title |
335 | 339 | $title = $convRule->getTitle(); |
336 | 340 | if($title){ |
— | — | @@ -342,14 +346,33 @@ |
343 | 347 | $action = $convRule->getRulesAction(); |
344 | 348 | foreach($convTable as $v=>$t) { |
345 | 349 | if( !in_array($v,$this->mVariants) )continue; |
346 | | - if( $action=="add" ) |
347 | | - $this->mTables[$v]->mergeArray($t); |
| 350 | + if( $action=="add" ) { |
| 351 | + foreach($t as $from=>$to) { |
| 352 | + // more efficient than array_merge(), about 2.5 times. |
| 353 | + $this->mManualAddTables[$v][$from] = $to; |
| 354 | + } |
| 355 | + } |
348 | 356 | elseif ( $action=="remove" ) |
349 | | - $this->mTables[$v]->removeArray($t); |
| 357 | + $this->mManualRemoveTables[$v] = array_merge($this->mManualRemoveTables[$v], $t); |
350 | 358 | } |
351 | 359 | } |
352 | 360 | |
353 | 361 | /** |
| 362 | + * apply manual conversion from $this->mManualAddTables and $this->mManualRemoveTables |
| 363 | + * @private |
| 364 | + */ |
| 365 | + function applyManualConv(){ |
| 366 | + //apply manual conversion table to global table |
| 367 | + foreach($this->mVariants as $v) { |
| 368 | + if (count($this->mManualAddTables[$v]) > 0) { |
| 369 | + $this->mTables[$v]->mergeArray($this->mManualAddTables[$v]); |
| 370 | + } |
| 371 | + if (count($this->mManualRemoveTables[$v]) > 0) |
| 372 | + $this->mTables[$v]->removeArray($this->mManualRemoveTables[$v]); |
| 373 | + } |
| 374 | + } |
| 375 | + |
| 376 | + /** |
354 | 377 | * Convert text using a parser object for context |
355 | 378 | * @public |
356 | 379 | */ |
— | — | @@ -438,33 +461,31 @@ |
439 | 462 | $plang = $this->getPreferredVariant(); |
440 | 463 | $tarray = StringUtils::explode($this->mMarkup['end'], $text); |
441 | 464 | $text = ''; |
442 | | - $lastDelim = false; |
| 465 | + |
| 466 | + $marks = array(); |
443 | 467 | foreach($tarray as $txt) { |
444 | 468 | $marked = explode($this->mMarkup['begin'], $txt, 2); |
445 | | - |
| 469 | + if (array_key_exists(1, $marked)) { |
| 470 | + $crule = new ConverterRule($marked[1], $this); |
| 471 | + $crule->parse($plang); |
| 472 | + $marked[1] = $crule->getDisplay(); |
| 473 | + $this->prepareManualConv($crule); |
| 474 | + } |
| 475 | + else |
| 476 | + $marked[0] .= $this->mMarkup['end']; |
| 477 | + array_push($marks, $marked); |
| 478 | + } |
| 479 | + $this->applyManualConv(); |
| 480 | + foreach ($marks as $marked) { |
446 | 481 | if( $this->mDoContentConvert ) |
447 | 482 | $text .= $this->autoConvert($marked[0],$plang); |
448 | 483 | else |
449 | 484 | $text .= $marked[0]; |
450 | | - |
451 | | - if(array_key_exists(1, $marked)){ |
452 | | - // strip the flags from syntax like -{T| ... }- |
453 | | - $crule = new ConverterRule($marked[1], $this); |
454 | | - $crule->parse($plang); |
455 | | - |
456 | | - $text .= $crule->getDisplay(); |
457 | | - $this->applyManualConv($crule); |
458 | | - $lastDelim = false; |
459 | | - } else { |
460 | | - // Reinsert the }- which wasn't part of anything |
461 | | - $text .= $this->mMarkup['end']; |
462 | | - $lastDelim = true; |
463 | | - } |
| 485 | + if( array_key_exists(1, $marked) ) |
| 486 | + $text .= $marked[1]; |
464 | 487 | } |
465 | | - if ( $lastDelim ) { |
466 | | - // Remove the last delimiter (wasn't real) |
467 | | - $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) ); |
468 | | - } |
| 488 | + // Remove the last delimiter (wasn't real) |
| 489 | + $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) ); |
469 | 490 | |
470 | 491 | return $text; |
471 | 492 | } |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -50,6 +50,8 @@ |
51 | 51 | * Page moves should not be minor edits |
52 | 52 | * (bug 17035) Special:Upload now fails gracefully if PHP's file_uploads has been |
53 | 53 | disabled |
| 54 | +* Fixing the caching issue by using -{T|xxx}- syntax (only applies on wiki with LanguageConverter class) |
| 55 | +* Improving the efficiency by using -{A|xxx}- syntax (only applies on wiki with LanguageConverter class) |
54 | 56 | |
55 | 57 | == API changes in 1.15 == |
56 | 58 | * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions |