r55662 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55661‎ | r55662 | r55663 >
Date:23:07, 28 August 2009
Author:conrad
Status:deferred
Tags:
Comment:
change precedence of ^, fix wgMemc->delete call, uncache on move and undelete
Modified paths:
  • /trunk/extensions/Transliterator/Transliterator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Transliterator/Transliterator.php
@@ -24,6 +24,8 @@
2525 * added cache support
2626 * @version 1.2.2
2727 * 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
2830 */
2931
3032 /**
@@ -44,8 +46,7 @@
4547 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
4648 */
4749
48 -if ( !defined( 'MEDIAWIKI' ) )
49 -{
 50+if ( !defined( 'MEDIAWIKI' ) ) {
5051 die( 'This file is a MediaWiki extension, not a valid entry point.' );
5152 }
5253
@@ -68,9 +69,11 @@
6970 $wgExtensionFunctions[] = 'ExtTransliterator::setup';
7071 }
7172 $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';
7578
7679 class ExtTransliterator {
7780
@@ -265,10 +268,10 @@
266269 $fromlast = strlen( $from ) - 1;
267270 if ( $fromlast > 0 ) {
268271 if ( $from[0] == "^" && $fromlast > 0)
269 - $from[0] = ExtTransliterator::DELIMITER;
 272+ $from[0] = self::DELIMITER;
270273
271274 if ( $from[$fromlast] == "$")
272 - $from[$fromlast] = ExtTransliterator::DELIMITER;
 275+ $from[$fromlast] = self::DELIMITER;
273276 }
274277
275278 // Now we've looked at our syntax we can remove html escaping to reveal the true form
@@ -324,7 +327,6 @@
325328 $sensitive = isset( $map["__sensitive__"] ); // Are we in case-sensitive mode, or not
326329 $ucfirst = false; // We are in case-sensitive mode and the first character of the current match was upper-case originally
327330 $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
329331
330332 $output = ""; // The output
331333 $last_match = 0; // The position of the last character matched, or the first character of the current run
@@ -337,14 +339,6 @@
338340
339341 if ( $i < $count ) {
340342
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 -
349343 $next = $current.$letters[$i];
350344
351345 // There may be a match longer than $current
@@ -365,55 +359,54 @@
366360 // We had no match at all, pass through one character
367361 if ( is_null( $last_trans ) ) {
368362
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 );
373365
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;
376371
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[''] ) ) {
379374
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 = "";
385383
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 {
388386
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;
399390 } 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;
409392 }
 393+ $i = ++$last_match;
 394+ $current = "";
410395 }
411396
412397 // Output the previous match
413398 } else {
414399
 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+ }
415408 // If this match is at the end of a word, see whether we have a more specific rule
416409 if ( $alphamap[$i-1] && ( $i == $count || !$alphamap[$i] ) ) {
417 - $try = $current . ExtTransliterator::DELIMITER;
 410+ $try = $current . self::DELIMITER;
418411 if ( isset( $map[$try] ) && is_string( $map[$try] ) ) {
419412 $last_trans = $map[$try];
420413 }
@@ -487,17 +480,30 @@
488481 /**
489482 * Called on ArticlePurge, ArticleDeleteComplete and NewRevisionFromEditComplete in order to purge cache
490483 */
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 ) {
492498 global $wgMemc;
493 - $title = $article->getTitle();
494499 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
495500 $text = $title->getText();
496501 $prefix = wfMsg( 'transliterator-prefix' );
497502 if ( strpos( $text, $prefix ) === 0 ) {
498 - $wgMemc->delete( str_replace( $prefix, '', $text ) );
 503+ $wgMemc->delete( 'extTransliterator:'.str_replace( $prefix, '', $text ) );
499504 }
500505 }
501506 return true;
 507+
502508 }
503509
504510 /**

Status & tagging log