public function build() { $article = $this->Agent->getArticle(); $text = $article->getContent(true); # Strip comments and <nowiki> $text = preg_replace("/<!--.*?-->/s", "", $text); $text = preg_replace("@<nowiki>.*?</nowiki>@s", "", $text); # change template usage to substitution; note that this is WRONG #$tchars = Title::legalChars(); #$text = preg_replace("/(?<!{){{([$tchars]+)(\|.*?)?}}(?!})/", "{{subst:$1$2}}", $text); $parser = new Parser(); # so the magic variables work out right $parser->mOptions = new ParserOptions(); $parser->mTitle = $this->Agent->getTitle(); $parser->mOutputType = OT_WIKI; $parser->initialiseVariables(); $parser->clearState(); $text = $parser->replaceVariables($text); preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER); $content = $matches[1]; $rdf = implode(' ', array_values($content)); $model = MwRdf::Model(); if (strlen($rdf) > 0) { $parser->mOutputType = OT_HTML; $rdf = $parser->replaceVariables($rdf); $turtle_parser = MwRdf::Parser('turtle'); $base_uri = $this->Agent->getTitle()->getFullUrl(); $prelude = MwRdf::getNamespacePrelude(); $model->loadStatementsFromString($turtle_parser, $prelude . $rdf); } return $model; }
public function testSpecialPageProducesCorrectHistoryModel() { $this->format = 'turtle'; $parser = MwRdf::Parser('turtle'); $this->prepareRequest(null, array('history')); $text = wfRdfSpecialPage(null); $model = MwRdf::Model(); $model->loadStatementsFromString($parser, $text); $expect = MwRdfTest::createExpectedHistoryModel(); $this->assertModelEqualsModel($expect, $model); }
public function testParser() { $o = MwRdf::Parser(); $this->assertTrue($o instanceof LibRDF_Parser); }