MediaWiki r49397 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r49396‎ | r49397 (on ViewVC)‎ | 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:

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
===================================================================
--- trunk/phase3/languages/LanguageConverter.php	(revision 49396)
+++ trunk/phase3/languages/LanguageConverter.php	(revision 49397)
@@ -487,10 +487,11 @@
 	 *
 	 * @param string $text text to be converted
 	 * @param bool $isTitle whether this conversion is for the article title
+	 * @param string $variant the variant we convert to
 	 * @return string converted text
 	 * @public
 	 */
-	function convert( $text, $isTitle = false ) {
+	function convert( $text, $isTitle = false, $variant = none ) {
 
 		$mw =& MagicWord::get( 'notitleconvert' );
 		if( $mw->matchAndRemove( $text ) )
@@ -505,7 +506,10 @@
 		if( $mw->matchStart( $text ) )
 			return $text;
 
-		$plang = $this->getPreferredVariant();
+		if( $variant && in_array( $variant, $this->mVariants ) )
+			$plang = $variant;
+		else
+			$plang = $this->getPreferredVariant();
 
 		// for title convertion
 		if ( $isTitle ) return $this->convertTitle( $text, $plang );
Index: trunk/phase3/languages/Language.php
===================================================================
--- trunk/phase3/languages/Language.php	(revision 49396)
+++ trunk/phase3/languages/Language.php	(revision 49397)
@@ -35,7 +35,7 @@
 class FakeConverter {
 	var $mLang;
 	function FakeConverter($langobj) {$this->mLang = $langobj;}
-	function convert($t, $i) {return $t;}
+	function convert($t, $i, $v) {return $t;}
 	function parserConvert($t, $p) {return $t;}
 	function getVariants() { return array( $this->mLang->getCode() ); }
 	function getPreferredVariant() {return $this->mLang->getCode(); }
@@ -2183,8 +2183,8 @@
 	}
 
 	# convert text to different variants of a language.
-	function convert( $text, $isTitle = false) {
-		return $this->mConverter->convert($text, $isTitle);
+	function convert( $text, $isTitle = false, $variant = none) {
+		return $this->mConverter->convert($text, $isTitle, $variant);
 	}
 
 	# Convert text from within Parser

Follow-up revisions

Rev.Commit 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

Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox