From 03a2cb6999bcd6ebef3137f9b8053976e19014ee Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 7 Jun 2012 17:23:05 +0200 Subject: [PATCH] some cleanup and checks in the Revision class --- includes/Revision.php | 35 +++++++++++++------ ...evisionStorageTest_ContentHandlerUseDB.php | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index 48c34e9088..1ffbc5c615 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -497,7 +497,7 @@ class Revision { # if we have a content object, use it to set the model and type if ( !empty( $row['content'] ) ) { - if ( !empty( $row['text_id'] ) ) { #FIXME: when is that set? test with external store setup! check out insertOn() + if ( !empty( $row['text_id'] ) ) { //@todo: when is that set? test with external store setup! check out insertOn() [dk] throw new MWException( "Text already stored in external store (id {$row['text_id']}), can't serialize content object" ); } @@ -542,7 +542,7 @@ class Revision { } $this->mTitle = null; # Load on demand if needed - $this->mCurrent = false; #XXX: really? we are about to create a revision. it will usually then be the current one. + $this->mCurrent = false; # XXX: really? we are about to create a revision. it will usually then be the current one. # If we still have no length, see it we have the text to figure it out if ( !$this->mSize ) { @@ -566,9 +566,6 @@ class Revision { throw new MWException( 'Revision constructor passed invalid row format.' ); } $this->mUnpatrolled = null; - - // @TODO: add support for ar_content_format, ar_content_model, rev_content_format, rev_content_model to API - // @TODO: get rid of $mText } /** @@ -881,11 +878,26 @@ class Revision { * Fetch revision text without regard for view restrictions * * @return String + * + * @deprecated since 1.WD. Instead, use Revision::getContent( Revision::RAW ) or Revision::getSerializedData() as appropriate. */ public function getRawText() { #FIXME: deprecated, replace usage! + wfDeprecated( __METHOD__, "1.WD" ); + return $this->getText( self::RAW ); } + /** + * Fetch original serialized data without regard for view restrictions + * + * @return String + * + * @since 1.WD + */ + public function getSerializedData() { + return $this->mText; + } + protected function getContentInternal() { if( is_null( $this->mContent ) ) { // Revision is immutable. Load on demand: @@ -954,7 +966,14 @@ class Revision { $model = $this->getContentModel(); $this->mContentHandler = ContentHandler::getForModelID( $model ); - assert( $this->mContentHandler->isSupportedFormat( $this->getContentFormat() ) ); #FIXME: use exception, not assert + $format = $this->getContentFormat(); + + if ( !$this->mContentHandler->isSupportedFormat( $format ) ) { + $formatName = ContentHandler::getContentFormatMimeType( $format ); + $modelName = ContentHandler::getContentModelName( $model ); + + throw new MWException( "Oops, the content format #$format ($formatName) is not supported for this content model, #$model ($modelName)" ); + } } return $this->mContentHandler; @@ -1204,10 +1223,6 @@ class Revision { if ( $wgContentHandlerUseDB ) { $row[ 'rev_content_model' ] = $this->getContentModel(); $row[ 'rev_content_format' ] = $this->getContentFormat(); - } else { - // @todo: Make sure the revision is using the default model and format. - // Since we don't store the actual model and format, we won't have any way to determine it later - // if it's not the default. } $dbw->insert( 'revision', $row, __METHOD__ ); diff --git a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php index d4bf4e83fd..3dfaa8de3f 100644 --- a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php +++ b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php @@ -78,7 +78,7 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest { $orig = $this->makeRevision( array( 'text' => 'hello hello.', 'content_model' => CONTENT_MODEL_JAVASCRIPT, 'content_format' => 'text/javascript' ) ); $rev = Revision::newFromId( $orig->getId() ); - $this->assertEquals( 'text/x-wiki', $rev->getContentFormat() ); + $this->assertEquals( CONTENT_FORMAT_WIKITEXT, $rev->getContentFormat() ); } } -- 2.20.1