Minor tweaks to cleanSig(inSig)
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 6 Dec 2011 23:07:13 +0000 (23:07 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 6 Dec 2011 23:07:13 +0000 (23:07 +0000)
* Make cleanSig public, since it's a declared entry point per class docs
* Make cleanSigInSig public static, added 2 more test cases for it

includes/Preferences.php
includes/parser/Parser.php
tests/phpunit/includes/ExtraParserTest.php

index 7126b2b..27603cb 100644 (file)
@@ -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;
index a3748e1..33a728b 100644 (file)
@@ -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;
        }
index a38f1c3..dc29439 100644 (file)
@@ -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() {