X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fcontent%2FTextContent.php;h=7bb4def2a6c555742b1563802de6b12d292851bd;hb=ce079cf6ad79ca8d3360817f809b219d166f9153;hp=225522e92d1dee40d447a21e455e9f22fa5f56b2;hpb=9fd930f74592234f95f83c0c831339e5b49553e7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index 225522e92d..7bb4def2a6 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -147,9 +147,28 @@ class TextContent extends AbstractContent { } } + /** + * Do a "\r\n" -> "\n" and "\r" -> "\n" transformation + * as well as trim trailing whitespace + * + * This was formerly part of Parser::preSaveTransform, but + * for non-wikitext content models they probably still want + * to normalize line endings without all of the other PST + * changes. + * + * @since 1.28 + * @param $text + * @return string + */ + public static function normalizeLineEndings( $text ) { + return str_replace( [ "\r\n", "\r" ], "\n", rtrim( $text ) ); + } + /** * Returns a Content object with pre-save transformations applied. - * This implementation just trims trailing whitespace. + * + * At a minimum, subclasses should make sure to call TextContent::normalizeLineEndings() + * either directly or part of Parser::preSaveTransform(). * * @param Title $title * @param User $user @@ -159,7 +178,7 @@ class TextContent extends AbstractContent { */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { $text = $this->getNativeData(); - $pst = rtrim( $text ); + $pst = self::normalizeLineEndings( $text ); return ( $text === $pst ) ? $this : new static( $pst, $this->getModel() ); }