Exemple #1
0
 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 testGetNamespacePrelude()
 {
     $this->assertType('string', MwRdf::getNamespacePrelude());
     $parser = new LibRDF_Parser('turtle');
     $i = $parser->parseString(MwRdf::getNamespacePrelude());
     $this->assertTrue($i instanceof LibRDF_StreamIterator, get_class($i));
     // this should be a completely empty result, we're just proving it
     // can be parsed
     $this->assertNull($i->current());
     $this->assertNull($i->next());
 }