Index: trunk/extensions/Transliterator/Transliterator.php |
— | — | @@ -24,6 +24,8 @@ |
25 | 25 | * added cache support |
26 | 26 | * @version 1.2.2 |
27 | 27 | * use new magic word i18n system |
| 28 | + * @version 1.3.1 |
| 29 | + * made ^ act more like $ (i.e. ^μπ => doesn't prevent μ => from matching), fix bug with cache refresh |
28 | 30 | */ |
29 | 31 | |
30 | 32 | /** |
— | — | @@ -44,8 +46,7 @@ |
45 | 47 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
46 | 48 | */ |
47 | 49 | |
48 | | -if ( !defined( 'MEDIAWIKI' ) ) |
49 | | -{ |
| 50 | +if ( !defined( 'MEDIAWIKI' ) ) { |
50 | 51 | die( 'This file is a MediaWiki extension, not a valid entry point.' ); |
51 | 52 | } |
52 | 53 | |
— | — | @@ -68,9 +69,11 @@ |
69 | 70 | $wgExtensionFunctions[] = 'ExtTransliterator::setup'; |
70 | 71 | } |
71 | 72 | $wgExtensionMessagesFiles['Transliterator'] = dirname(__FILE__).'/Transliterator.i18n.php'; |
72 | | -$wgHooks['ArticleDeleteComplete'][] = 'ExtTransliterator::purgeMap'; |
73 | | -$wgHooks['NewRevisionFromEditComplete'][] = 'ExtTransliterator::purgeMap'; |
74 | | -$wgHooks['ArticlePurge'][] = 'ExtTransliterator::purgeMap'; |
| 73 | +$wgHooks['ArticleDeleteComplete'][] = 'ExtTransliterator::purgeArticle'; |
| 74 | +$wgHooks['NewRevisionFromEditComplete'][] = 'ExtTransliterator::purgeArticle'; |
| 75 | +$wgHooks['ArticlePurge'][] = 'ExtTransliterator::purgeArticle'; |
| 76 | +$wgHooks['ArticleUndelete'][] = 'ExtTransliterator::purgeTitle'; |
| 77 | +$wgHooks['TitleMoveComplete'][] = 'ExtTransliterator::purgeNewtitle'; |
75 | 78 | |
76 | 79 | class ExtTransliterator { |
77 | 80 | |
— | — | @@ -265,10 +268,10 @@ |
266 | 269 | $fromlast = strlen( $from ) - 1; |
267 | 270 | if ( $fromlast > 0 ) { |
268 | 271 | if ( $from[0] == "^" && $fromlast > 0) |
269 | | - $from[0] = ExtTransliterator::DELIMITER; |
| 272 | + $from[0] = self::DELIMITER; |
270 | 273 | |
271 | 274 | if ( $from[$fromlast] == "$") |
272 | | - $from[$fromlast] = ExtTransliterator::DELIMITER; |
| 275 | + $from[$fromlast] = self::DELIMITER; |
273 | 276 | } |
274 | 277 | |
275 | 278 | // Now we've looked at our syntax we can remove html escaping to reveal the true form |
— | — | @@ -324,7 +327,6 @@ |
325 | 328 | $sensitive = isset( $map["__sensitive__"] ); // Are we in case-sensitive mode, or not |
326 | 329 | $ucfirst = false; // We are in case-sensitive mode and the first character of the current match was upper-case originally |
327 | 330 | $last_upper = null; // We have lower-cased the current letter, but we need to keep track of the original (dotted I for example) |
328 | | - $withstart = false; // Have we inserted a start character into the current $current |
329 | 331 | |
330 | 332 | $output = ""; // The output |
331 | 333 | $last_match = 0; // The position of the last character matched, or the first character of the current run |
— | — | @@ -337,14 +339,6 @@ |
338 | 340 | |
339 | 341 | if ( $i < $count ) { |
340 | 342 | |
341 | | - // if this is the start of a word, first try the form with the start indicator |
342 | | - if ( $withstart ) { |
343 | | - $withstart = false; |
344 | | - } else if ( $alphamap[$i] && ($last_trans == null) && ( $i == 0 || !$alphamap[$i - 1] ) ) { |
345 | | - $current = ExtTransliterator::DELIMITER; |
346 | | - $withstart = true; |
347 | | - } |
348 | | - |
349 | 343 | $next = $current.$letters[$i]; |
350 | 344 | |
351 | 345 | // There may be a match longer than $current |
— | — | @@ -365,55 +359,54 @@ |
366 | 360 | // We had no match at all, pass through one character |
367 | 361 | if ( is_null( $last_trans ) ) { |
368 | 362 | |
369 | | - // This was a fake character that we inserted |
370 | | - if ( $withstart ) { |
371 | | - $current = ""; |
372 | | - continue; |
| 363 | + $last_letter = $letters[$last_match]; |
| 364 | + $last_lower = $sensitive ? $last_letter : mb_strtolower( $last_letter ); |
373 | 365 | |
374 | | - // It was a real character that we were supposed to transliterate |
375 | | - } else { |
| 366 | + // If we are not being sensitive, we can try down-casing the previous letter |
| 367 | + if ( $last_letter != $last_lower ) { |
| 368 | + $ucfirst = true; |
| 369 | + $letters[$last_match] = $last_lower; |
| 370 | + $last_upper = $last_letter; |
376 | 371 | |
377 | | - $last_letter = $letters[$last_match]; |
378 | | - $last_lower = $sensitive ? $last_letter : mb_strtolower( $last_letter ); |
| 372 | + // Might be nice to output a ? if we don't understand |
| 373 | + } else if ( isset( $map[''] ) ) { |
379 | 374 | |
380 | | - // If we are not being sensitive, we can try down-casing the previous letter |
381 | | - if ( $last_letter != $last_lower ) { |
382 | | - $ucfirst = true; |
383 | | - $letters[$last_match] = $last_lower; |
384 | | - $last_upper = $last_letter; |
| 375 | + if ( $ucfirst ) { |
| 376 | + $output .= str_replace( '$1', $last_upper , $map[''] ); |
| 377 | + $ucfirst = false; |
| 378 | + } else { |
| 379 | + $output .= str_replace( '$1', $last_letter, $map[''] ); |
| 380 | + } |
| 381 | + $i = ++$last_match; |
| 382 | + $current = ""; |
385 | 383 | |
386 | | - // Might be nice to output a ? if we don't understand |
387 | | - } else if ( isset( $map[''] ) ) { |
| 384 | + // Or the input if it's likely to be correct enough |
| 385 | + } else { |
388 | 386 | |
389 | | - if ( $ucfirst ) { |
390 | | - $output .= str_replace( '$1', $last_upper , $map[''] ); |
391 | | - $ucfirst = false; |
392 | | - } else { |
393 | | - $output .= str_replace( '$1', $last_letter, $map[''] ); |
394 | | - } |
395 | | - $i = ++$last_match; |
396 | | - $current = ""; |
397 | | - |
398 | | - // Or the input if it's likely to be correct enough |
| 387 | + if ( $ucfirst ) { |
| 388 | + $output .= $last_upper; |
| 389 | + $ucfirst = false; |
399 | 390 | } else { |
400 | | - |
401 | | - if ( $ucfirst ) { |
402 | | - $output .= $last_upper; |
403 | | - $ucfirst = false; |
404 | | - } else { |
405 | | - $output .= $last_letter; |
406 | | - } |
407 | | - $i = ++$last_match; |
408 | | - $current = ""; |
| 391 | + $output .= $last_letter; |
409 | 392 | } |
| 393 | + $i = ++$last_match; |
| 394 | + $current = ""; |
410 | 395 | } |
411 | 396 | |
412 | 397 | // Output the previous match |
413 | 398 | } else { |
414 | 399 | |
| 400 | + // If this match is at the start of a word, see whether we have a more specific rule |
| 401 | + if ( ( $last_match == 0 || !$alphamap[$last_match-1]) && $alphamap[$last_match] ) { |
| 402 | + $try = self::DELIMITER . $current; |
| 403 | + if ( isset( $map[$try] ) && is_string( $map[$try] ) ) { |
| 404 | + $last_trans = $map[$try]; |
| 405 | + $current = $try; |
| 406 | + } |
| 407 | + } |
415 | 408 | // If this match is at the end of a word, see whether we have a more specific rule |
416 | 409 | if ( $alphamap[$i-1] && ( $i == $count || !$alphamap[$i] ) ) { |
417 | | - $try = $current . ExtTransliterator::DELIMITER; |
| 410 | + $try = $current . self::DELIMITER; |
418 | 411 | if ( isset( $map[$try] ) && is_string( $map[$try] ) ) { |
419 | 412 | $last_trans = $map[$try]; |
420 | 413 | } |
— | — | @@ -487,17 +480,30 @@ |
488 | 481 | /** |
489 | 482 | * Called on ArticlePurge, ArticleDeleteComplete and NewRevisionFromEditComplete in order to purge cache |
490 | 483 | */ |
491 | | - static function purgeMap( &$article, $a=false, $b=false, $c=false, $d=false ) { |
| 484 | + static function purgeArticle( &$article, $a=false, $b=false, $c=false, $d=false ) { |
| 485 | + return self::purgeTitle( $article->getTitle() ); |
| 486 | + } |
| 487 | + |
| 488 | + /** |
| 489 | + * Called on TitleMoveComplete |
| 490 | + */ |
| 491 | + static function purgeNewTitle ( &$title, &$newtitle, $a=false, $b=false, $c=false ) { |
| 492 | + return self::purgeTitle( $newtitle ); |
| 493 | + } |
| 494 | + /** |
| 495 | + * Called on ArticleUndelete (and by other purge hook handlers) |
| 496 | + */ |
| 497 | + static function purgeTitle( &$title, $a=false ) { |
492 | 498 | global $wgMemc; |
493 | | - $title = $article->getTitle(); |
494 | 499 | if ( $title->getNamespace() == NS_MEDIAWIKI ) { |
495 | 500 | $text = $title->getText(); |
496 | 501 | $prefix = wfMsg( 'transliterator-prefix' ); |
497 | 502 | if ( strpos( $text, $prefix ) === 0 ) { |
498 | | - $wgMemc->delete( str_replace( $prefix, '', $text ) ); |
| 503 | + $wgMemc->delete( 'extTransliterator:'.str_replace( $prefix, '', $text ) ); |
499 | 504 | } |
500 | 505 | } |
501 | 506 | return true; |
| 507 | + |
502 | 508 | } |
503 | 509 | |
504 | 510 | /** |