(Bug 41169) Apply rtrim on on preSaveTransfrom.
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 18 Oct 2012 18:14:46 +0000 (20:14 +0200)
committerReedy <reedy@wikimedia.org>
Thu, 18 Oct 2012 18:40:29 +0000 (19:40 +0100)
Wikitext should not have trailing whitespace.

Change-Id: I75eb1c4bef7217ec2b7440594e3fc4b68dc3c022

includes/content/TextContent.php
includes/content/WikitextContent.php
tests/phpunit/includes/JavascriptContentTest.php
tests/phpunit/includes/TextContentTest.php
tests/phpunit/includes/WikitextContentTest.php

index b561b90..18dcebd 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 b45caa2..74652e6 100644 (file)
@@ -89,6 +89,9 @@ class JavascriptContentTest extends TextContentTest {
                        array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                                'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
                        ),
+                       array( " Foo \n ",
+                               " Foo",
+                       ),
                );
        }
 
index ee17a75..6cd436e 100644 (file)
@@ -50,8 +50,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",
+                       ),
                );
        }