2012-04-18 13:02:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
2012-10-20 01:51:15 +00:00
|
|
|
* @group Database
|
2012-06-14 06:39:15 +00:00
|
|
|
*
|
2012-10-20 01:51:15 +00:00
|
|
|
* @note Declare that we are using the database, because otherwise we'll fail in the "databaseless" test run.
|
2012-06-14 06:39:15 +00:00
|
|
|
* This is because the LinkHolderArray used by the parser needs database access.
|
|
|
|
|
*
|
2012-05-13 22:02:29 +00:00
|
|
|
*/
|
2012-04-18 13:02:21 +00:00
|
|
|
class ContentHandlerTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-09-12 11:43:52 +00:00
|
|
|
public function setup() {
|
2012-10-20 01:51:15 +00:00
|
|
|
global $wgContLang;
|
2012-09-12 11:43:52 +00:00
|
|
|
parent::setup();
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgExtraNamespaces' => array(
|
|
|
|
|
12312 => 'Dummy',
|
|
|
|
|
12313 => 'Dummy_talk',
|
|
|
|
|
),
|
|
|
|
|
// The below tests assume that namespaces not mentioned here (Help, User, MediaWiki, ..)
|
|
|
|
|
// default to CONTENT_MODEL_WIKITEXT.
|
|
|
|
|
'wgNamespaceContentModels' => array(
|
|
|
|
|
12312 => 'testing',
|
|
|
|
|
),
|
|
|
|
|
'wgContentHandlers' => array(
|
|
|
|
|
CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler',
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler',
|
|
|
|
|
CONTENT_MODEL_CSS => 'CssContentHandler',
|
|
|
|
|
CONTENT_MODEL_TEXT => 'TextContentHandler',
|
|
|
|
|
'testing' => 'DummyContentHandlerForTesting',
|
|
|
|
|
),
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
// Reset namespace cache
|
|
|
|
|
MWNamespace::getCanonicalNamespaces( true );
|
|
|
|
|
$wgContLang->resetNamespaces();
|
2012-04-26 10:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public function tearDown() {
|
|
|
|
|
global $wgContLang;
|
2012-04-26 10:11:01 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// Reset namespace cache
|
|
|
|
|
MWNamespace::getCanonicalNamespaces( true );
|
|
|
|
|
$wgContLang->resetNamespaces();
|
2012-04-26 10:11:01 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
parent::tearDown();
|
2012-04-26 10:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetDefaultModelFor() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return array(
|
2012-09-19 18:07:56 +00:00
|
|
|
array( 'Help:Foo', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ),
|
2012-04-25 16:35:36 +00:00
|
|
|
array( 'User:Foo', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
|
|
|
|
|
array( 'User:Foo/bar.css', CONTENT_MODEL_CSS ),
|
|
|
|
|
array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
|
|
|
|
|
array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ),
|
|
|
|
|
array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDefaultModelFor
|
|
|
|
|
*/
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testGetDefaultModelFor( $title, $expectedModelId ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-10-20 01:51:15 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDefaultModelFor
|
|
|
|
|
*/
|
|
|
|
|
public function testGetForTitle( $title, $expectedContentModel ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$handler = ContentHandler::getForTitle( $title );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedContentModel, $handler->getModelID() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetLocalizedName() {
|
2012-05-13 22:02:29 +00:00
|
|
|
return array(
|
|
|
|
|
array( null, null ),
|
2012-06-25 21:30:51 +00:00
|
|
|
array( "xyzzy", null ),
|
2012-05-13 22:02:29 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// XXX: depends on content language
|
|
|
|
|
array( CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ),
|
2012-05-13 22:02:29 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-19 12:45:25 +00:00
|
|
|
/**
|
2012-06-25 21:30:51 +00:00
|
|
|
* @dataProvider dataGetLocalizedName
|
2012-06-19 12:45:25 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetLocalizedName( $id, $expected ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
$name = ContentHandler::getLocalizedName( $id );
|
2012-06-19 12:45:25 +00:00
|
|
|
|
2012-06-25 21:30:51 +00:00
|
|
|
if ( $expected ) {
|
|
|
|
|
$this->assertNotNull( $name, "no name found for content model $id" );
|
2013-01-28 10:27:15 +00:00
|
|
|
$this->assertTrue( preg_match( $expected, $name ) > 0,
|
2012-10-20 01:51:15 +00:00
|
|
|
"content model name for #$id did not match pattern $expected"
|
|
|
|
|
);
|
2012-06-25 21:30:51 +00:00
|
|
|
} else {
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertEquals( $id, $name, "localization of unknown model $id should have "
|
2012-10-20 01:51:15 +00:00
|
|
|
. "fallen back to use the model id directly."
|
|
|
|
|
);
|
2012-06-19 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetPageLanguage() {
|
2012-06-26 14:37:42 +00:00
|
|
|
global $wgLanguageCode;
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
array( "Main", $wgLanguageCode ),
|
|
|
|
|
array( "Dummy:Foo", $wgLanguageCode ),
|
|
|
|
|
array( "MediaWiki:common.js", 'en' ),
|
|
|
|
|
array( "User:Foo/common.js", 'en' ),
|
|
|
|
|
array( "MediaWiki:common.css", 'en' ),
|
|
|
|
|
array( "User:Foo/common.css", 'en' ),
|
|
|
|
|
array( "User:Foo", $wgLanguageCode ),
|
|
|
|
|
|
|
|
|
|
array( CONTENT_MODEL_JAVASCRIPT, 'javascript' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetPageLanguage
|
|
|
|
|
*/
|
|
|
|
|
public function testGetPageLanguage( $title, $expected ) {
|
|
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expected = wfGetLangObj( $expected );
|
|
|
|
|
|
|
|
|
|
$handler = ContentHandler::getForTitle( $title );
|
|
|
|
|
$lang = $handler->getPageLanguage( $title );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected->getCode(), $lang->getCode() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetContentText_Null() {
|
2012-04-25 16:35:36 +00:00
|
|
|
global $wgContentHandlerTextFallback;
|
|
|
|
|
|
|
|
|
|
$content = null;
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'fail';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( '', $text );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'serialize';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( '', $text );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'ignore';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( '', $text );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetContentText_TextContent() {
|
2012-04-25 16:35:36 +00:00
|
|
|
global $wgContentHandlerTextFallback;
|
|
|
|
|
|
|
|
|
|
$content = new WikitextContent( "hello world" );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'fail';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( $content->getNativeData(), $text );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'serialize';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( $content->serialize(), $text );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'ignore';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( $content->getNativeData(), $text );
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 13:10:38 +00:00
|
|
|
public function testGetContentText_NonTextContent() {
|
2012-04-25 16:35:36 +00:00
|
|
|
global $wgContentHandlerTextFallback;
|
|
|
|
|
|
|
|
|
|
$content = new DummyContentForTesting( "hello world" );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'fail';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
|
|
|
|
|
$this->fail( "ContentHandler::getContentText should have thrown an exception for non-text Content object" );
|
2012-10-20 01:51:15 +00:00
|
|
|
} catch ( MWException $ex ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
// as expected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'serialize';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( $content->serialize(), $text );
|
|
|
|
|
|
|
|
|
|
$wgContentHandlerTextFallback = 'ignore';
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertNull( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
/*
|
|
|
|
|
public static function makeContent( $text, Title $title, $modelId = null, $format = null ) {}
|
|
|
|
|
*/
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataMakeContent() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return array(
|
2012-09-19 18:07:56 +00:00
|
|
|
array( 'hallo', 'Help:Test', null, null, CONTENT_MODEL_WIKITEXT, 'hallo', false ),
|
2012-04-25 16:35:36 +00:00
|
|
|
array( 'hallo', 'MediaWiki:Test.js', null, null, CONTENT_MODEL_JAVASCRIPT, 'hallo', false ),
|
2013-02-14 13:10:38 +00:00
|
|
|
array( serialize( 'hallo' ), 'Dummy:Test', null, null, "testing", 'hallo', false ),
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
array( 'hallo', 'Help:Test', null, CONTENT_FORMAT_WIKITEXT, CONTENT_MODEL_WIKITEXT, 'hallo', false ),
|
2012-05-13 22:02:29 +00:00
|
|
|
array( 'hallo', 'MediaWiki:Test.js', null, CONTENT_FORMAT_JAVASCRIPT, CONTENT_MODEL_JAVASCRIPT, 'hallo', false ),
|
2013-02-14 13:10:38 +00:00
|
|
|
array( serialize( 'hallo' ), 'Dummy:Test', null, "testing", "testing", 'hallo', false ),
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
array( 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, 'hallo', false ),
|
2012-04-25 16:35:36 +00:00
|
|
|
array( 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, 'hallo', false ),
|
2013-02-14 13:10:38 +00:00
|
|
|
array( serialize( 'hallo' ), 'Dummy:Test', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, serialize( 'hallo' ), false ),
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
array( 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT, "testing", null, null, true ),
|
2012-06-25 21:30:51 +00:00
|
|
|
array( 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS, "testing", null, null, true ),
|
|
|
|
|
array( 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT, "testing", null, null, true ),
|
2012-04-25 16:35:36 +00:00
|
|
|
);
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataMakeContent
|
|
|
|
|
*/
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testMakeContent( $data, $title, $modelId, $format, $expectedModelId, $expectedNativeData, $shouldFail ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
try {
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = ContentHandler::makeContent( $data, $title, $modelId, $format );
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
if ( $shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent should have failed!" );
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, $content->getModel(), 'bad model id' );
|
2012-04-25 16:35:36 +00:00
|
|
|
$this->assertEquals( $expectedNativeData, $content->getNativeData(), 'bads native data' );
|
|
|
|
|
} catch ( MWException $ex ) {
|
2013-02-14 13:10:38 +00:00
|
|
|
if ( !$shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// dummy, so we don't get the "test did not perform any assertions" message.
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
/*
|
2012-06-19 12:45:25 +00:00
|
|
|
public function testSupportsSections() {
|
|
|
|
|
$this->markTestIncomplete( "not yet implemented" );
|
|
|
|
|
}
|
2012-10-20 01:51:15 +00:00
|
|
|
*/
|
2012-08-20 17:28:20 +00:00
|
|
|
|
|
|
|
|
public function testRunLegacyHooks() {
|
|
|
|
|
Hooks::register( 'testRunLegacyHooks', __CLASS__ . '::dummyHookHandler' );
|
|
|
|
|
|
|
|
|
|
$content = new WikitextContent( 'test text' );
|
2012-08-28 13:58:36 +00:00
|
|
|
$ok = ContentHandler::runLegacyHooks( 'testRunLegacyHooks', array( 'foo', &$content, 'bar' ), false );
|
2012-08-20 17:28:20 +00:00
|
|
|
|
|
|
|
|
$this->assertTrue( $ok, "runLegacyHooks should have returned true" );
|
|
|
|
|
$this->assertEquals( "TEST TEXT", $content->getNativeData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function dummyHookHandler( $foo, &$text, $bar ) {
|
|
|
|
|
if ( $text === null || $text === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$text = strtoupper( $text );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DummyContentHandlerForTesting extends ContentHandler {
|
|
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
public function __construct( $dataModel ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
parent::__construct( $dataModel, array( "testing" ) );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serializes Content object of the type supported by this ContentHandler.
|
|
|
|
|
*
|
|
|
|
|
* @param Content $content the Content object to serialize
|
|
|
|
|
* @param null $format the desired serialization format
|
|
|
|
|
* @return String serialized form of the content
|
|
|
|
|
*/
|
2012-10-20 01:51:15 +00:00
|
|
|
public function serializeContent( Content $content, $format = null ) {
|
2013-02-14 13:10:38 +00:00
|
|
|
return $content->serialize();
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unserializes a Content object of the type supported by this ContentHandler.
|
|
|
|
|
*
|
|
|
|
|
* @param $blob String serialized form of the content
|
|
|
|
|
* @param null $format the format used for serialization
|
|
|
|
|
* @return Content the Content object created by deserializing $blob
|
|
|
|
|
*/
|
2012-10-20 01:51:15 +00:00
|
|
|
public function unserializeContent( $blob, $format = null ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$d = unserialize( $blob );
|
|
|
|
|
return new DummyContentForTesting( $d );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an empty Content object of the type supported by this ContentHandler.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-10-20 01:51:15 +00:00
|
|
|
public function makeEmptyContent() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return new DummyContentForTesting( '' );
|
|
|
|
|
}
|
2012-04-19 12:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-09 11:19:52 +00:00
|
|
|
class DummyContentForTesting extends AbstractContent {
|
2012-04-19 12:57:10 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
public function __construct( $data ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
parent::__construct( "testing" );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$this->data = $data;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 15:52:13 +00:00
|
|
|
public function serialize( $format = null ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
return serialize( $this->data );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return String a string representing the content in a way useful for building a full text search index.
|
|
|
|
|
* If no useful representation exists, this method returns an empty string.
|
|
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function getTextForSearchIndex() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return String the wikitext to include when another page includes this content, or false if the content is not
|
2012-10-20 01:51:15 +00:00
|
|
|
* includable in a wikitext page.
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function getWikitextForTransclusion() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a textual representation of the content suitable for use in edit summaries and log messages.
|
|
|
|
|
*
|
2012-10-20 01:51:15 +00:00
|
|
|
* @param int $maxlength Maximum length of the summary text.
|
|
|
|
|
* @return string The summary text.
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function getTextForSummary( $maxlength = 250 ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns native represenation of the data. Interpretation depends on the data model used,
|
|
|
|
|
* as given by getDataModel().
|
|
|
|
|
*
|
|
|
|
|
* @return mixed the native representation of the content. Could be a string, a nested array
|
2012-10-20 01:51:15 +00:00
|
|
|
* structure, an object, a binary blob... anything, really.
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function getNativeData() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return $this->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* returns the content's nominal size in bogo-bytes.
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function getSize() {
|
2012-05-02 10:54:27 +00:00
|
|
|
return strlen( $this->data );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a copy of this Content object. The following must be true for the object returned
|
|
|
|
|
* if $copy = $original->copy()
|
|
|
|
|
*
|
|
|
|
|
* * get_class($original) === get_class($copy)
|
2012-05-13 22:02:29 +00:00
|
|
|
* * $original->getModel() === $copy->getModel()
|
2012-04-25 16:35:36 +00:00
|
|
|
* * $original->equals( $copy )
|
|
|
|
|
*
|
|
|
|
|
* If and only if the Content object is imutable, the copy() method can and should
|
|
|
|
|
* return $this. That is, $copy === $original may be true, but only for imutable content
|
|
|
|
|
* objects.
|
|
|
|
|
*
|
2012-10-20 01:51:15 +00:00
|
|
|
* @return Content. A copy of this object.
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function copy() {
|
2012-04-25 16:35:36 +00:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if this content is countable as a "real" wiki page, provided
|
|
|
|
|
* that it's also in a countable location (e.g. a current revision in the main namespace).
|
|
|
|
|
*
|
2012-10-20 01:51:15 +00:00
|
|
|
* @param boolean $hasLinks if it is known whether this content contains links, provide this information here,
|
|
|
|
|
* to avoid redundant parsing to find out.
|
2012-04-25 16:35:36 +00:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2012-10-08 15:26:11 +00:00
|
|
|
public function isCountable( $hasLinks = null ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2012-07-23 21:52:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param null $revId
|
|
|
|
|
* @param null|ParserOptions $options
|
2012-10-20 01:51:15 +00:00
|
|
|
* @param boolean $generateHtml whether to generate Html (default: true). If false,
|
|
|
|
|
* the result of calling getText() on the ParserOutput object returned by
|
|
|
|
|
* this method is undefined.
|
2012-07-23 21:52:34 +00:00
|
|
|
*
|
|
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function getParserOutput( Title $title, $revId = null, ParserOptions $options = null, $generateHtml = true ) {
|
2012-07-23 21:52:34 +00:00
|
|
|
return new ParserOutput( $this->getNativeData() );
|
|
|
|
|
}
|
2012-04-18 13:02:21 +00:00
|
|
|
}
|