ContentHandler removed wikitext parsing for CSS and JS pages.
However, people seem to rely on links and categories embedded
in script comments.
Change-Id: I0736f15878fbd3292e75854bf16f04df656ce363
*/
$wgContentHandlerUseDB = false;
+/**
+ * Determines which types of text are parsed as wikitext. This does not imply that these kinds
+ * of texts are also rendered as wikitext, it only means that links, magic words, etc will have
+ * the effect on the database they would have on a wikitext page.
+ *
+ * @todo: On the long run, it would be nice to put categories etc into a separate structure,
+ * or at least parse only the contents of comments in the scripts.
+ *
+ * @since 1.21
+ */
+$wgTextModelsToParse = array(
+ CONTENT_MODEL_WIKITEXT, // Just for completeness, wikitext will always be parsed.
+ CONTENT_MODEL_JAVASCRIPT, // Make categories etc work, people put them into comments.
+ CONTENT_MODEL_CSS, // Make categories etc work, people put them into comments.
+);
+
/**
* Whether the user must enter their password to change their e-mail address
*
$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.css", null, "hello <world>\n",
- "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>"),
+ array(
+ "MediaWiki:Test.css",
+ null,
+ "hello <world>\n",
+ "<pre class=\"mw-code mw-css\" dir=\"ltr\">\nhello <world>\n\n</pre>" ),
+
+ array(
+ "MediaWiki:Test.css",
+ null,
+ "/* hello [[world]] */\n",
+ "<pre class=\"mw-code mw-css\" dir=\"ltr\">\n/* hello [[world]] */\n\n</pre>",
+ array( 'Links' => array( // NOTE: assumes default settings for $wgTextModelsToParse
+ array( 'World' => 0 ) ) ) ),
+
// @todo: more...?
);
}
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...?
);
}
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
}