return $this->getNativeData();
}
+ /**
+ * Returns a Content object with pre-save transformations applied.
+ * This implementation just trims trailing whitespace.
+ *
+ * @param $title Title
+ * @param $user User
+ * @param $popts ParserOptions
+ * @return Content
+ */
+ public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
+ $text = $this->getNativeData();
+ $pst = rtrim( $text );
+
+ return ( $text === $pst ) ? $this : new WikitextContent( $pst );
+ }
+
/**
* Diff this content object with another content object..
*
$revId = null,
ParserOptions $options = null, $generateHtml = true
) {
- # Generic implementation, relying on $this->getHtml()
+ global $wgParser, $wgTextModelsToParse;
+
+ if ( !$options ) {
+ //NOTE: use canonical options per default to produce cacheable output
+ $options = $this->getContentHandler()->makeParserOptions( 'canonical' );
+ }
+
+ if ( in_array( $this->getModel(), $wgTextModelsToParse ) ) {
+ // parse just to get links etc into the database
+ $po = $wgParser->parse( $this->getNativeData(), $title, $options, true, true, $revId );
+ } else {
+ $po = new ParserOutput();
+ }
if ( $generateHtml ) {
$html = $this->getHtml();
$html = '';
}
- $po = new ParserOutput( $html );
+ $po->setText( $html );
return $po;
}
public function dataGetParserOutput() {
return array(
- array("MediaWiki:Test.js", null, "hello <world>\n",
- "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>"),
+ array(
+ "MediaWiki:Test.js",
+ null,
+ "hello <world>\n",
+ "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello <world>\n\n</pre>" ),
+
+ array(
+ "MediaWiki:Test.js",
+ null,
+ "hello(); // [[world]]\n",
+ "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
+ array( 'Links' => array( // NOTE: assumes default settings for $wgTextModelsToParse
+ array( 'World' => 0 ) ) ) ),
+
// @todo: more...?
);
}
array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
),
+ array( " Foo \n ",
+ " Foo",
+ ),
);
}
public function dataGetParserOutput() {
return array(
- array("TextContentTest_testGetParserOutput", CONTENT_MODEL_TEXT, "hello ''world'' & stuff\n", "hello ''world'' & stuff"),
+ array(
+ "TextContentTest_testGetParserOutput",
+ CONTENT_MODEL_TEXT,
+ "hello ''world'' & [[stuff]]\n", "hello ''world'' & [[stuff]]",
+ array( 'Links' => array() ) ),
// @todo: more...?
);
}
/**
* @dataProvider dataGetParserOutput
*/
- public function testGetParserOutput( $title, $model, $text, $expectedHtml ) {
+ public function testGetParserOutput( $title, $model, $text, $expectedHtml, $expectedFields = null ) {
$title = Title::newFromText( $title );
$content = ContentHandler::makeContent( $text, $title, $model );
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
$this->assertEquals( $expectedHtml, trim( $html ) );
+
+ if ( $expectedFields ) {
+ foreach ( $expectedFields as $field => $exp ) {
+ $f = 'get' . ucfirst( $field );
+ $v = call_user_func( array( $po, $f ) );
+
+ if ( is_array( $exp ) ) {
+ $this->assertArrayEquals( $exp, $v );
+ } else {
+ $this->assertEquals( $exp, $v );
+ }
+ }
+ }
+
// @todo: assert more properties
}
public function dataPreSaveTransform() {
return array(
- array( 'hello this is ~~~',
- "hello this is ~~~",
+ array( #0: no signature resolution
+ "hello this is ~~~",
+ "hello this is ~~~",
+ ),
+ array( #1: rtrim
+ " Foo \n ",
+ " Foo",
),
);
}