Merge "make MessageContent use a Message object" into Wikidata
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 31 Aug 2012 09:53:08 +0000 (09:53 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 31 Aug 2012 09:53:08 +0000 (09:53 +0000)
includes/specials/SpecialBooksources.php
tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/WikitextContentTest.php

index d271a62..fb65326 100644 (file)
@@ -144,9 +144,17 @@ class SpecialBookSources extends SpecialPage {
                $title = Title::makeTitleSafe( NS_PROJECT, $page ); # Show list in content language
                if( is_object( $title ) && $title->exists() ) {
                        $rev = Revision::newFromTitle( $title, false, Revision::READ_NORMAL );
-                       #FIXME: need a way to do this via ContentHandler (or enforce flat text-based content)
-                       $this->getOutput()->addWikiText( str_replace( 'MAGICNUMBER', $this->isbn, $rev->getText() ) );
-                       return true;
+                       $content = $rev->getContent();
+
+                       if ( $content instanceof TextContent ) {
+                               //XXX: in the future, this could be stored as structured data, defining a list of book sources
+
+                               $text = $content->getNativeData();
+                               $this->getOutput()->addWikiText( str_replace( 'MAGICNUMBER', $this->isbn, $text ) );
+                               return true;
+                       } else {
+                               throw new MWException( "Unexpected content type for book sources: " . $content->getModel() );
+                       }
                }
 
                # Fall back to the defaults given in the language file
index cae320f..3778914 100644 (file)
@@ -327,6 +327,8 @@ class RevisionTest extends MediaWikiTestCase {
        }
 
        public function testConstructWithText() {
+               $this->hideDeprecated( "Revision::getText" );
+
                $rev = new Revision( array(
                                          'text' => 'hello world.',
                                          'content_model' => CONTENT_MODEL_JAVASCRIPT
@@ -339,6 +341,8 @@ class RevisionTest extends MediaWikiTestCase {
        }
 
        public function testConstructWithContent() {
+               $this->hideDeprecated( "Revision::getText" );
+
                $title = Title::newFromText( 'RevisionTest_testConstructWithContent' );
 
                $rev = new Revision( array(
index 449423b..fd1f886 100644 (file)
@@ -6,8 +6,15 @@
 class WikitextContentTest extends MediaWikiTestCase {
 
        public function setup() {
+               global $wgUser;
+
+               // anon user
+               $wgUser = new User();
+               $wgUser->setName( '127.0.0.1' );
+
                $this->context = new RequestContext( new FauxRequest() );
                $this->context->setTitle( Title::newFromText( "Test" ) );
+               $this->context->setUser( $wgUser );
        }
 
        public function newContent( $text ) {
@@ -191,8 +198,9 @@ just a test"
         * @dataProvider dataPreSaveTransform
         */
        public function testPreSaveTransform( $text, $expected ) {
-               global $wgUser, $wgContLang;
-               $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+               global $wgContLang;
+
+               $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
 
                $content = $this->newContent( $text );
                $content = $content->preSaveTransform( $this->context->getTitle(), $this->context->getUser(), $options );
@@ -215,8 +223,8 @@ just a test"
         * @dataProvider dataPreloadTransform
         */
        public function testPreloadTransform( $text, $expected ) {
-               global $wgUser, $wgContLang;
-               $options = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+               global $wgContLang;
+               $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
 
                $content = $this->newContent( $text );
                $content = $content->preloadTransform( $this->context->getTitle(), $options );