X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=blobdiff_plain;f=includes%2Fcontent%2FTextContent.php;h=e5a9f90d16a555933ef5dac65ff483c7cdfeefbc;hb=c9231ac8c43f3a0c4675c0e7637881b89c84142f;hp=de650b9194b7acf731696e9023ad8dd91d5722c8;hpb=120e275384a65e9e255b1aebdf5c9d4bddd15d8e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index de650b9194..e5a9f90d16 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -34,6 +34,11 @@ */ class TextContent extends AbstractContent { + /** + * @var string + */ + protected $mText; + /** * @param string $text * @param string $model_id @@ -147,9 +152,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 string $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 and normalizes newlines. + * + * 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,8 +183,7 @@ class TextContent extends AbstractContent { */ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { $text = $this->getNativeData(); - $pst = rtrim( $text ); - $pst = str_replace( [ "\r\n", "\r" ], "\n", $pst ); + $pst = self::normalizeLineEndings( $text ); return ( $text === $pst ) ? $this : new static( $pst, $this->getModel() ); } @@ -215,7 +238,7 @@ class TextContent extends AbstractContent { * @param int $revId Revision ID (for {{REVISIONID}}) * @param ParserOptions $options Parser options * @param bool $generateHtml Whether or not to generate HTML - * @param ParserOutput $output The output object to fill (reference). + * @param ParserOutput &$output The output object to fill (reference). */ protected function fillParserOutput( Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output