r49397 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49396‎ | r49397 | r49398 >
Date:10:56, 11 April 2009
Author:philip
Status:reverted (Comments)
Tags:
Comment:
A new optional param for LanguageConverter::convert(), to enable a new function named 'convert()' which added to AbuseFilter.
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -487,10 +487,11 @@
488488 *
489489 * @param string $text text to be converted
490490 * @param bool $isTitle whether this conversion is for the article title
 491+ * @param string $variant the variant we convert to
491492 * @return string converted text
492493 * @public
493494 */
494 - function convert( $text, $isTitle = false ) {
 495+ function convert( $text, $isTitle = false, $variant = none ) {
495496
496497 $mw =& MagicWord::get( 'notitleconvert' );
497498 if( $mw->matchAndRemove( $text ) )
@@ -505,7 +506,10 @@
506507 if( $mw->matchStart( $text ) )
507508 return $text;
508509
509 - $plang = $this->getPreferredVariant();
 510+ if( $variant && in_array( $variant, $this->mVariants ) )
 511+ $plang = $variant;
 512+ else
 513+ $plang = $this->getPreferredVariant();
510514
511515 // for title convertion
512516 if ( $isTitle ) return $this->convertTitle( $text, $plang );
Index: trunk/phase3/languages/Language.php
@@ -35,7 +35,7 @@
3636 class FakeConverter {
3737 var $mLang;
3838 function FakeConverter($langobj) {$this->mLang = $langobj;}
39 - function convert($t, $i) {return $t;}
 39+ function convert($t, $i, $v) {return $t;}
4040 function parserConvert($t, $p) {return $t;}
4141 function getVariants() { return array( $this->mLang->getCode() ); }
4242 function getPreferredVariant() {return $this->mLang->getCode(); }
@@ -2183,8 +2183,8 @@
21842184 }
21852185
21862186 # convert text to different variants of a language.
2187 - function convert( $text, $isTitle = false) {
2188 - return $this->mConverter->convert($text, $isTitle);
 2187+ function convert( $text, $isTitle = false, $variant = none) {
 2188+ return $this->mConverter->convert($text, $isTitle, $variant);
21892189 }
21902190
21912191 # Convert text from within Parser

Follow-up revisions

RevisionCommit summaryAuthorDate
r49399Add a new function named 'convert()', allow user to convert a string to speci...philip10:59, 11 April 2009
r51002Reverted r49855, r49656, r49401, r49399, r49397. The language converter canno...tstarling07:46, 26 May 2009

Comments

#Comment by Tim Starling (talk | contribs)   08:39, 19 May 2009

+ function convert( $text, $isTitle = false, $variant = none ) {

Syntax error, maybe you mean 'none'.

The entry point here seems to be wrong, convert() is mostly full of code that is parser-specific, and will screw up in unexpected ways when called from AbuseFilter. autoConvert() is apparently more appropriate, and it already has a $variant parameter. But the $wgParser reference is certainly incorrect and will fail unexpectedly. You really have to commit to a bit of refactoring if you want this feature.

#Comment by PhiLiP (talk | contribs)   17:56, 22 May 2009

btw: ialex has fixed my typo errors on r49401 (change none to null).

Status & tagging log