From: daniel Date: Mon, 30 Apr 2012 10:50:31 +0000 (+0200) Subject: backporting changes made during review of core patch X-Git-Tag: 1.31.0-rc.0~22097^2^2~184 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=fc91010111580858788ca315371d20a1d654adca;p=lhc%2Fweb%2Fwiklou.git backporting changes made during review of core patch --- diff --git a/includes/Content.php b/includes/Content.php index 28a1717468..aee53b623f 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -476,24 +476,12 @@ class WikitextContent extends TextContent { public function __construct( $text ) { parent::__construct($text, CONTENT_MODEL_WIKITEXT); - - $this->mDefaultParserOptions = null; #TODO: use per-class static member?! } protected function getHtml( ) { throw new MWException( "getHtml() not implemented for wikitext. Use getParserOutput()->getText()." ); } - public function getDefaultParserOptions() { - global $wgUser, $wgContLang; - - if ( !$this->mDefaultParserOptions ) { #TODO: use per-class static member?! - $this->mDefaultParserOptions = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); - } - - return $this->mDefaultParserOptions; - } - /** * Returns a ParserOutput object resulting from parsing the content's text using $wgParser. * @@ -510,7 +498,7 @@ class WikitextContent extends TextContent { global $wgParser; if ( !$options ) { - $options = $this->getDefaultParserOptions(); + $options = ParserOptions::newFromUserAndLang( $context->getUser(), $context->getLanguage() ); } $po = $wgParser->parse( $this->mText, $context->getTitle(), $options, true, true, $revId ); @@ -594,13 +582,11 @@ class WikitextContent extends TextContent { * * @param Title $title * @param User $user - * @param null|ParserOptions $popts + * @param ParserOptions $popts * @return Content */ - public function preSaveTransform( Title $title, User $user, ParserOptions $popts = null ) { - global $wgParser; - - if ( $popts == null ) $popts = $this->getDefaultParserOptions(); + public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { + global $wgParser, $wgConteLang; $text = $this->getNativeData(); $pst = $wgParser->preSaveTransform( $text, $title, $user, $popts ); @@ -612,13 +598,11 @@ class WikitextContent extends TextContent { * Returns a Content object with preload transformations applied (or this object if no transformations apply). * * @param Title $title - * @param null|ParserOptions $popts + * @param ParserOptions $popts * @return Content */ - public function preloadTransform( Title $title, ParserOptions $popts = null ) { - global $wgParser; - - if ( $popts == null ) $popts = $this->getDefaultParserOptions(); + public function preloadTransform( Title $title, ParserOptions $popts ) { + global $wgParser, $wgConteLang; $text = $this->getNativeData(); $plt = $wgParser->getPreloadText( $text, $title, $popts ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index 0411089344..6ecda15f3f 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -563,7 +563,8 @@ more stuff $admin->setName("Admin"); $text = "one"; - $page = $this->createPage( "WikiPageTest_testDoRollback", $text ); + $page = $this->newPage( "WikiPageTest_testDoRollback" ); + $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "section one", EDIT_NEW, false, $admin ); $user1 = new User(); $user1->setName( "127.0.1.11" ); diff --git a/tests/phpunit/includes/WikitextContentTest.php b/tests/phpunit/includes/WikitextContentTest.php index 96eea7ac0f..35e2e778cd 100644 --- a/tests/phpunit/includes/WikitextContentTest.php +++ b/tests/phpunit/includes/WikitextContentTest.php @@ -140,8 +140,11 @@ just a test" * @dataProvider dataPreSaveTransform */ public function testPreSaveTransform( $text, $expected ) { + global $wgUser, $wgContLang; + $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); + $content = $this->newContent( $text ); - $content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser() ); + $content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options ); $this->assertEquals( $expected, $content->getNativeData() ); } @@ -161,8 +164,11 @@ just a test" * @dataProvider dataPreloadTransform */ public function testPreloadTransform( $text, $expected ) { + global $wgUser, $wgContLang; + $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang ); + $content = $this->newContent( $text ); - $content = $content->preloadTransform( $this->context->getTitle() ); + $content = $content->preloadTransform( $this->context->getTitle(), $options ); $this->assertEquals( $expected, $content->getNativeData() ); }