Merge "(Bug 41169) Apply rtrim on on preSaveTransfrom."
authorDemon <chadh@wikimedia.org>
Thu, 18 Oct 2012 18:45:36 +0000 (18:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 18 Oct 2012 18:45:36 +0000 (18:45 +0000)
includes/content/TextContent.php
includes/content/WikitextContent.php
tests/phpunit/includes/JavascriptContentTest.php
tests/phpunit/includes/TextContentTest.php
tests/phpunit/includes/WikitextContentTest.php

index 5e60b3c..8e832ec 100644 (file)
@@ -116,6 +116,22 @@ class TextContent extends AbstractContent {
                return $this->getNativeData();
        }
 
+       /**
+        * Returns a Content object with pre-save transformations applied.
+        * This implementation just trims trailing whitespace.
+        *
+        * @param $title Title
+        * @param $user User
+        * @param $popts ParserOptions
+        * @return Content
+        */
+       public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
+               $text = $this->getNativeData();
+               $pst = rtrim( $text );
+
+               return ( $text === $pst ) ? $this : new WikitextContent( $pst );
+       }
+
        /**
         * Diff this content object with another content object..
         *
index 89a9fe9..8f1381f 100644 (file)
@@ -116,8 +116,9 @@ class WikitextContent extends TextContent {
 
                $text = $this->getNativeData();
                $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+               rtrim( $pst );
 
-               return new WikitextContent( $pst );
+               return ( $text === $pst ) ? $this : new WikitextContent( $pst );
        }
 
        /**
index e10d706..d3810af 100644 (file)
@@ -101,6 +101,9 @@ class JavascriptContentTest extends TextContentTest {
                        array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                                'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                        ),
+                       array( " Foo \n ",
+                               " Foo",
+                       ),
                );
        }
 
index ebadfb5..10934b4 100644 (file)
@@ -68,8 +68,13 @@ class TextContentTest extends MediaWikiTestCase {
 
        public function dataPreSaveTransform() {
                return array(
-                       array( 'hello this is ~~~',
-                              "hello this is ~~~",
+                       array( #0: no signature resolution
+                               "hello this is ~~~",
+                               "hello this is ~~~",
+                       ),
+                       array( #1: rtrim
+                               " Foo \n ",
+                               " Foo",
                        ),
                );
        }
index b2d3bdf..c1332a6 100644 (file)
@@ -21,12 +21,12 @@ class WikitextContentTest extends TextContentTest {
 
        public function dataGetSecondaryDataUpdates() {
                return array(
-                       array("WikitextContentTest_testGetSecondaryDataUpdates_1",
+                       array( "WikitextContentTest_testGetSecondaryDataUpdates_1",
                                CONTENT_MODEL_WIKITEXT, "hello ''world''\n",
                                array( 'LinksUpdate' => array(  'mRecursive' => true,
                                                                'mLinks' => array() ) )
                        ),
-                       array("WikitextContentTest_testGetSecondaryDataUpdates_2",
+                       array( "WikitextContentTest_testGetSecondaryDataUpdates_2",
                                CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n",
                                array( 'LinksUpdate' => array(  'mRecursive' => true,
                                                                'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) )
@@ -174,6 +174,10 @@ just a test"
                        array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                               'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                        ),
+                       array( // rtrim
+                               " Foo \n ",
+                               " Foo",
+                       ),
                );
        }