Hi,
Having a $wgArticle object how can I get the *rendered* article text ? Can't find any method/function that will return that... getContent just returns the article as wiki markup.
On 06/07/07, Carlos Jorge Andrade carlos.andrade@gmail.com wrote:
Having a $wgArticle object how can I get the *rendered* article text ? Can't find any method/function that will return that... getContent just returns the article as wiki markup.
Assuming no use of the parser cache...
global $wgParser, $wgUser; $output = $wgParser->parse( $wgArticle->getContent(), $wgArticle->getTitle(), ParserOptions::newFromUser() ); $html = $output->getText();
Rob Church
I later found that piece of code. :-) I just have two questions....
I set $wgParser->setOutputType('html'). Is this necessary ?
Regarding the parsing, you said "assuming no use of the parser cache". I'm doing this for every article shown, so I nead it to use the parser cache. It would be a bad ideia parsing over and over again the same article. In this way, is the cache used internally ou is this a fresh parsing every time it's run ? How do I make it use the parser cache ?
Thanks for the feedback.
On Jul 6, 2007, at 5:31 PM, Rob Church wrote:
On 06/07/07, Carlos Jorge Andrade carlos.andrade@gmail.com wrote:
Having a $wgArticle object how can I get the *rendered* article text ? Can't find any method/function that will return that... getContent just returns the article as wiki markup.
Assuming no use of the parser cache...
global $wgParser, $wgUser; $output = $wgParser->parse( $wgArticle->getContent(), $wgArticle->getTitle(), ParserOptions::newFromUser() ); $html = $output->getText();
Rob Church
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
On 07/07/07, Carlos Jorge Andrade carlos.andrade@gmail.com wrote:
I set $wgParser->setOutputType('html'). Is this necessary ?
Probably not, a bog standard call to Parser::parse() will *hopefully* return HTML.
In this way, is the cache used internally ou is this a fresh parsing every time it's run ? How do I make it use the parser cache ?
It's quite straightforward; here's a quick snippet...
global $wgArticle, $wgUser, $wgParser; $cache = ParserCache::singleton(); if( ( $output = $cache->get( $wgArticle, $wgUser ) ) === false ) { $output = $wgParser->parse( $wgArticle->getContent(), $wgArticle->getTitle(), ParserOptions::newFromUser( $wgUser ) ); $cache->save( $output, $wgArticle, $wgUser ); } $text = $output->getText();
Rob Church
mediawiki-l@lists.wikimedia.org