backporting changes made during review of core patch
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 30 Apr 2012 10:50:31 +0000 (12:50 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 30 Apr 2012 10:50:31 +0000 (12:50 +0200)
includes/Content.php
tests/phpunit/includes/WikiPageTest.php
tests/phpunit/includes/WikitextContentTest.php

index 28a1717..aee53b6 100644 (file)
@@ -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 );
index 0411089..6ecda15 100644 (file)
@@ -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" );
index 96eea7a..35e2e77 100644 (file)
@@ -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() );
        }