/** * Transform wiki markup when saving a page by doing "\r\n" -> "\n" * conversion, substituting signatures, {{subst:}} templates, etc. * * @param string $text The text to transform * @param Title $title The Title object for the current article * @param User $user The User object describing the current user * @param ParserOptions $options Parsing options * @param bool $clearState Whether to clear the parser state first * @return string The altered wiki markup */ public function preSaveTransform($text, Title $title, User $user, ParserOptions $options, $clearState = true) { if ($clearState) { $magicScopeVariable = $this->lock(); } $this->startParse($title, $options, self::OT_WIKI, $clearState); $this->setUser($user); // We still normalize line endings for backwards-compatibility // with other code that just calls PST, but this should already // be handled in TextContent subclasses $text = TextContent::normalizeLineEndings($text); if ($options->getPreSaveTransform()) { $text = $this->pstPass2($text, $user); } $text = $this->mStripState->unstripBoth($text); $this->setUser(null); # Reset return $text; }
/** * @covers TextContent::normalizeLineEndings * @dataProvider provideNormalizeLineEndings */ public function testNormalizeLineEndings($input, $expected) { $this->assertEquals($expected, TextContent::normalizeLineEndings($input)); }