From: Chad Horohoe Date: Tue, 6 Dec 2011 23:07:13 +0000 (+0000) Subject: Minor tweaks to cleanSig(inSig) X-Git-Tag: 1.31.0-rc.0~26148 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=a1f5c6ce732e08a99e05736f1290af242b3604ba;p=lhc%2Fweb%2Fwiklou.git Minor tweaks to cleanSig(inSig) * Make cleanSig public, since it's a declared entry point per class docs * Make cleanSigInSig public static, added 2 more test cases for it --- diff --git a/includes/Preferences.php b/includes/Preferences.php index 7126b2bf59..27603cb34f 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1186,12 +1186,12 @@ class Preferences { * @return string */ static function cleanSignature( $signature, $alldata, $form ) { - global $wgParser; if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) { + global $wgParser; $signature = $wgParser->cleanSig( $signature ); } else { // When no fancy sig used, make sure ~{3,5} get removed. - $signature = $wgParser->cleanSigInSig( $signature ); + $signature = Parser::cleanSigInSig( $signature ); } return $signature; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index a3748e1ca0..33a728bca3 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4417,7 +4417,7 @@ class Parser { } # Make sure nickname doesnt get a sig in a sig - $nickname = $this->cleanSigInSig( $nickname ); + $nickname = self::cleanSigInSig( $nickname ); # If we're still here, make it a link to the user page $userText = wfEscapeWikiText( $username ); @@ -4447,7 +4447,7 @@ class Parser { * @param $parsing bool Whether we're cleaning (preferences save) or parsing * @return String: signature text */ - function cleanSig( $text, $parsing = false ) { + public function cleanSig( $text, $parsing = false ) { if ( !$parsing ) { global $wgTitle; $this->startParse( $wgTitle, new ParserOptions, self::OT_PREPROCESS, true ); @@ -4465,7 +4465,7 @@ class Parser { $substText = '{{' . $substWord->getSynonym( 0 ); $text = preg_replace( $substRegex, $substText, $text ); - $text = $this->cleanSigInSig( $text ); + $text = self::cleanSigInSig( $text ); $dom = $this->preprocessToDom( $text ); $frame = $this->getPreprocessor()->newFrame(); $text = $frame->expand( $dom ); @@ -4483,7 +4483,7 @@ class Parser { * @param $text String * @return String: signature text with /~{3,5}/ removed */ - function cleanSigInSig( $text ) { + public static function cleanSigInSig( $text ) { $text = preg_replace( '/~{3,5}/', '', $text ); return $text; } diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index a38f1c32f5..dc29439804 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -93,12 +93,18 @@ class ExtraParserTest extends MediaWikiTestCase { /** * cleanSigInSig() just removes tildes + * @dataProvider provideStringsForCleanSigInSig */ - function testCleanSigInSig() { - $title = Title::newFromText( __FUNCTION__ ); - $outputText = $this->parser->cleanSigInSig( "{{Foo}} ~~~~" ); - - $this->assertEquals( "{{Foo}} ", $outputText ); + function testCleanSigInSig( $in, $out ) { + $this->assertEquals( Parser::cleanSigInSig( $in), $out ); + } + + function provideStringsForCleanSigInSig() { + return array( + array( "{{Foo}} ~~~~", "{{Foo}} " ), + array( "~~~", "" ), + array( "~~~~~", "" ), + ); } function testGetSection() {