Manual talk:Globals are evil

From mediawiki.org
Latest comment: 9 years ago by 2nd in topic How to get article html?

How to get article html?[edit]

# Generate the article HTML as if viewed by a web request
$article = new Article( Title::newFromText( $t ) );
$article->view();

Manual:Article.php says "Warning: Article is a front end UI class not an api for interacting with page contents. Please use WikiPage for that." but WikiPage dont have view() method. I'm using now:

  global $wgOut;

  $title = Title::makeTitle(NS_MEDIAWIKI, "Sidebar");

  if (!$title->exists())
    continue;

  $text = WikiPage::factory($title)->getContent()->mText;
  $html = $wgOut->parse($text);

Is this common way? --2nd 19:00, 17 May 2014 (UTC)Reply