if ( !$this->mContentModel ) {
$title = $this->getTitle();
if ( $title ) {
- $this->mContentModel = ContentHandler::getDefaultModelFor( $title );
+ $this->mContentModel = $title->getContentModel();
} else {
$this->mContentModel = CONTENT_MODEL_WIKITEXT;
}
. "revision's page!" );
}
- $defaultModel = ContentHandler::getDefaultModelFor( $title );
+ $defaultModel = $title->getContentModel();
$defaultFormat = ContentHandler::getForModelID( $defaultModel )->getDefaultFormat();
$row['rev_content_model'] = ( $model === $defaultModel ) ? null : $model;
/**
* @covers Revision::getContentModel
*/
- public function testGetContentModel() {
+ public function testGetContentModel_default_model() {
+ global $wgContentHandlerUseDB;
+
+ if ( !$wgContentHandlerUseDB ) {
+ $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
+ }
+
+ $orig = $this->makeRevision( [ 'text' => 'hello hello.', ] );
+
+ // Change namespace default content model, to make sure getContentModel() uses the
+ // page content model, not the namespace default.
+ $ns = $this->getDefaultWikitextNS();
+ $this->mergeMwGlobalArrayValue( 'wgNamespaceContentModels', [ $ns => CONTENT_MODEL_JSON ] );
+
+ $rev = Revision::newFromId( $orig->getId() );
+
+ // we should still get the correct content model from the page table
+ $this->assertEquals( CONTENT_MODEL_WIKITEXT, $rev->getContentModel() );
+
+ // check that we don't null the revision model if it's equal to the default, but not to
+ // the current page model.
+ $second = $this->makeRevision( [
+ 'text' => '{ "say":"hello" }',
+ 'content_model' => CONTENT_MODEL_JAVASCRIPT
+ ] );
+
+ $rev = Revision::newFromId( $second->getId() );
+
+ // we should now get the content model from the revision table
+ $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
+ }
+
+ /**
+ * @covers Revision::getContentModel
+ */
+ public function testGetContentModel_other_model() {
global $wgContentHandlerUseDB;
if ( !$wgContentHandlerUseDB ) {
}
$orig = $this->makeRevision( [ 'text' => 'hello hello.',
- 'content_model' => CONTENT_MODEL_JAVASCRIPT ] );
+ 'content_model' => CONTENT_MODEL_JAVASCRIPT ] );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );