}
/**
- * Returns a generic ParserOutput object, wrapping the HTML returned by
- * getHtml().
+ * Fills the provided ParserOutput object with information derived from the content.
+ * Unless $generateHtml was false, this includes an HTML representation of the content
+ * provided by getHtml().
+ *
+ * For content models listed in $wgTextModelsToParse, this method will call the MediaWiki
+ * wikitext parser on the text to extract any (wikitext) links, magic words, etc.
+ *
+ * Subclasses may override this to provide custom content processing.
+ * For custom HTML generation alone, it is sufficient to override getHtml().
*
* @param Title $title Context title for parsing
* @param int $revId Revision ID (for {{REVISIONID}})
* @param ParserOptions $options Parser options
* @param bool $generateHtml Whether or not to generate HTML
- *
- * @return ParserOutput Representing the HTML form of the text.
+ * @param ParserOutput $output The output object to fill (reference).
*/
- public function getParserOutput( Title $title, $revId = null,
- ParserOptions $options = null, $generateHtml = true ) {
+ protected function fillParserOutput( Title $title, $revId,
+ ParserOptions $options, $generateHtml, ParserOutput &$output
+ ) {
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();
+ // parse just to get links etc into the database, HTML is replaced below.
+ $output = $wgParser->parse( $this->getNativeData(), $title, $options, true, true, $revId );
}
if ( $generateHtml ) {
$html = '';
}
- $po->setText( $html );
-
- return $po;
+ $output->setText( $html );
}
/**
* Generates an HTML version of the content, for display. Used by
- * getParserOutput() to construct a ParserOutput object.
+ * fillParserOutput() to provide HTML for the ParserOutput object.
*
* Subclasses may override this to provide a custom HTML rendering.
* If further information is to be derived from the content (such as
- * categories), the getParserOutput() method can be overridden instead.
+ * categories), the fillParserOutput() method can be overridden instead.
*
* For backwards-compatibility, this default implementation just calls
* getHighlightHtml().